bool QSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const { ... if (leftType != rightType) return (leftType == dir); // или return (leftType == file); вверх-вниз else return QString::localeAwareCompare(leftString, rightString) < 0;}
bool MySortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const { ... if (leftType != rightType) return (leftType == (MySortType == dirAbove)?dir:file); else return QSortFilterProxyModel::lessThan(left, right);}
QVariant UpData = sourceModel()->data(sourceModel()->index(qmiUp.row(),2));QVariant DownData = sourceModel()->data(sourceModel()->index(qmiDown.row(),2));if ((UpData.toString()=="-=DIR=-") && (DownData.toString()!="-=DIR=-")){ return true;}else if ((UpData.toString()!="-=DIR=-") && (DownData.toString()=="-=DIR=-")) { return false; }
QVariant UpData = sourceModel()->data(sourceModel()->index(qmiUp.row(),2));QVariant DownData = sourceModel()->data(sourceModel()->index(qmiDown.row(),2));if ((UpData.toString()=="-=DIR=-") && (DownData.toString()!="-=DIR=-")){ return true && order;}else if ((UpData.toString()!="-=DIR=-") && (DownData.toString()=="-=DIR=-")) { return false && order; }
class MySortModel : public QSortFilterProxyModel{public: MySortModel( QObject * parent = 0 ); bool lessThan( const QModelIndex &left, const QModelIndex &right ) const; void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );private: Qt::SortOrder m_order;};
void MySortModel::sort( int column, Qt::SortOrder order ){ m_order = order; QSortFilterProxyModel::sort( column, order );}
bool MySortModel::lessThan( const QModelIndex &l, const QModelIndex &r ) const{... if ( ltype == rtype ) return QString::localeAwareCompare( lname, rname ) < 0; else if ( ltype == "dir" ) return m_order == Qt::AscendingOrder; return m_order != Qt::AscendingOrder;}