comparison src/metadataview.cpp @ 4:e4748da7140b

Add filter functionalty to metadataview
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 25 Mar 2015 14:23:46 +0100
parents 248d5d1cdb38
children 73efe717b944
comparison
equal deleted inserted replaced
3:248d5d1cdb38 4:e4748da7140b
1 #include "metadataview.h" 1 #include "metadataview.h"
2 #include "qxtcsvmodel.h" 2 #include "qxtcsvmodel.h"
3 #include "filterwidget.h"
3 4
4 #include <QTextCodec> 5 #include <QTextCodec>
5 #include <QTableView> 6 #include <QTableView>
6 #include <QSortFilterProxyModel> 7 #include <QSortFilterProxyModel>
7 #include <QVBoxLayout> 8 #include <QVBoxLayout>
18 mCSVModel = new QxtCsvModel; 19 mCSVModel = new QxtCsvModel;
19 setupGUI(); 20 setupGUI();
20 21
21 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged, 22 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged,
22 this, &MetaDataView::viewSelectionChanged); 23 this, &MetaDataView::viewSelectionChanged);
24 connect(mSortModel, &QSortFilterProxyModel::dataChanged,
25 this, &MetaDataView::dataChanged);
23 return; 26 return;
24 } 27 }
25 28
26 void MetaDataView::setupGUI() { 29 void MetaDataView::setupGUI() {
27 QVBoxLayout *baseLayout = new QVBoxLayout; 30 QVBoxLayout *baseLayout = new QVBoxLayout;
31
32 FilterWidget *filterWidget = new FilterWidget(mSortModel);
33 baseLayout->addWidget(filterWidget);
34
28 mView = new QTableView; 35 mView = new QTableView;
29 mView->setModel(mSortModel); 36 mView->setModel(mSortModel);
30 37
31 mView->horizontalHeader()->setStretchLastSection(true); 38 mView->horizontalHeader()->setStretchLastSection(true);
32 mView->resizeColumnsToContents(); 39 mView->resizeColumnsToContents();
50 mSortModel->setSourceModel(mCSVModel); 57 mSortModel->setSourceModel(mCSVModel);
51 qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows."; 58 qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows.";
52 return QString(); 59 return QString();
53 } 60 }
54 61
62 void MetaDataView::dataChanged()
63 {
64 QItemSelectionModel *selection = mView->selectionModel();
65 QModelIndexList selected = selection->selectedIndexes();
66
67 qDebug() << "Data Changed.";
68 if (selected.isEmpty()) {
69 /* Nothing selected still we need to emit this signal to update
70 * the viewer otherwise selection changed handles it. */
71 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1,
72 QDateTime());
73 }
74 }
75
55 void MetaDataView::viewSelectionChanged(const QItemSelection& selected, 76 void MetaDataView::viewSelectionChanged(const QItemSelection& selected,
56 const QItemSelection& deselected) { 77 const QItemSelection& deselected) {
78 if (selected.indexes().isEmpty()) {
79 /* Nothing selected */
80 return;
81 }
57 /* One row selected */ 82 /* One row selected */
58 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount()); 83 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount());
59 const QModelIndex idx = selected.indexes()[0]; 84 const QModelIndex idx = selected.indexes()[0];
60 const QString dateString = selected.indexes()[1].data().toString(); 85 const QString dateString = selected.indexes()[1].data().toString();
61 bool ok; 86 bool ok;
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)