Mercurial > retraceit > retraceit
diff src/metadataview.cpp @ 56:016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 19 May 2015 11:12:22 +0200 |
parents | 23672cbc3e5f |
children | 5923d569167b |
line wrap: on
line diff
--- a/src/metadataview.cpp Tue May 19 10:13:04 2015 +0200 +++ b/src/metadataview.cpp Tue May 19 11:12:22 2015 +0200 @@ -23,12 +23,32 @@ #include <QFontMetrics> #include <QApplication> +/**@brief Small wrapper around csv model to enable numerical sorting. */ +class numericSortCSVModel : public QxtCsvModel +{ +public: + /**@brief returns the data as string, integer or double variant. */ + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const { + QVariant base = QxtCsvModel::data(index, role); + bool ok = false; + int intVal = base.toInt(&ok); + if (ok) { + return intVal; + } + double dblVal = base.toDouble(&ok); + if (ok) { + return dblVal; + } + return base; + } +}; + MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mDateColIdx(-1) { /* Create models */ mSortModel = new QSortFilterProxyModel; - mCSVModel = new QxtCsvModel; + mCSVModel = new numericSortCSVModel; setupGUI(); connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged,