Esempio n. 1
0
void KItemModelBase::setSortRole(const QByteArray& role)
{
    if (role != m_sortRole) {
        const QByteArray previous = m_sortRole;
        m_sortRole = role;
        onSortRoleChanged(role, previous);
        emit sortRoleChanged(role, previous);
    }
}
Esempio n. 2
0
SortFilterModel::SortFilterModel(QObject *parent)
    : QSortFilterProxyModel(parent),
      m_maximumCount(0),
      m_hide(false)
{
    connect(this, SIGNAL(sourceModelChanged()), SIGNAL(modelChanged()));
    connect(this, SIGNAL(sortRoleChanged()), SLOT(manualSort()));
    setDynamicSortFilter(false);
}
void KItemListHeaderWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
    QGraphicsWidget::mouseReleaseEvent(event);

    if (m_pressedRoleIndex == -1) {
        return;
    }

    switch (m_roleOperation) {
    case NoRoleOperation: {
        // Only a click has been done and no moving or resizing has been started
        const QByteArray sortRole = m_model->sortRole();
        const int sortRoleIndex = m_columns.indexOf(sortRole);
        if (m_pressedRoleIndex == sortRoleIndex) {
            // Toggle the sort order
            const Qt::SortOrder previous = m_model->sortOrder();
            const Qt::SortOrder current = (m_model->sortOrder() == Qt::AscendingOrder) ?
                                          Qt::DescendingOrder : Qt::AscendingOrder;
            m_model->setSortOrder(current);
            emit sortOrderChanged(current, previous);
        } else {
            // Change the sort role and reset to the ascending order
            const QByteArray previous = m_model->sortRole();
            const QByteArray current = m_columns[m_pressedRoleIndex];
            m_model->setSortRole(current);
            emit sortRoleChanged(current, previous);

            if (m_model->sortOrder() == Qt::DescendingOrder) {
                m_model->setSortOrder(Qt::AscendingOrder);
                emit sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder);
            }
        }
        break;
    }

    case MoveRoleOperation:
        m_movingRole.pixmap = QPixmap();
        m_movingRole.x = 0;
        m_movingRole.xDec = 0;
        m_movingRole.index = -1;
        break;

    default:
        break;
    }

    m_pressedRoleIndex = -1;
    m_roleOperation = NoRoleOperation;
    update();

    QApplication::restoreOverrideCursor();
}
void KItemListHeaderWidget::setModel(KItemModelBase* model)
{
    if (m_model == model) {
        return;
    }

    if (m_model) {
        disconnect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
                   this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
        disconnect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
                   this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
    }

    m_model = model;

    if (m_model) {
        connect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
                this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
        connect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
                this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
    }
}
Esempio n. 5
0
void KateFileTree::slotSortOpeningOrder()
{
  emit sortRoleChanged(KateFileTreeModel::OpeningOrderRole);
}
Esempio n. 6
0
void KateFileTree::slotSortPath()
{
  emit sortRoleChanged(KateFileTreeModel::PathRole);
}
Esempio n. 7
0
void KateFileTree::slotSortName()
{
  emit sortRoleChanged(Qt::DisplayRole);
}
Esempio n. 8
0
void SortFilterModel::setSortRole(const QString &role)
{
    m_sortRole = role;
    QSortFilterProxyModel::setSortRole(roleNames().key(role.toLatin1()));
    Q_EMIT sortRoleChanged();
}