// QSortFilterProxyModel *proxyModel;// QSqlQueryModel* model//QTableView* viewvoid QDbfReader::sort(int index){ proxyModel->setSourceModel(model); view->setModel(proxyModel); proxyModel->setFilterKeyColumn(index);}
void QSortFilterProxyModel::sort ( int column, Qt::SortOrder order = Qt::AscendingOrder )
bool QSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const
QVariant QAbstractItemModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
QVariant SqlQueryModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const{ QVariant v = QSqlQueryModel::data ( index, role ); switch(role) { case Qt::DisplayRole: case Qt::EditRole: { if( v.canConvert( QVariant::Double ) ) return v.toDouble(); } } return v;}
bool MySortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{ QVariant leftData = sourceModel()->data(left); QVariant rightData = sourceModel()->data(right); if (leftData.canConvert(QVariant::Double)) { bool ok1 = false; double a = leftData.toDouble(&ok1); double b = rightData.toDouble(); if (ok1) return a < b; } if (leftData.canConvert(QVariant::String)) return QString::localeAwareCompare(leftData.toString(), rightData.toString()) < 0;}
canConvert(QVariant::Double)