comparison src/metadataview.cpp @ 37:0c05958d254c

(issue 13, 6) Add constant index number column to data and view
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 06 May 2015 17:17:13 +0200
parents f10d4e035eec
children 73e6b6b12412
comparison
equal deleted inserted replaced
36:92bb9687d716 37:0c05958d254c
54 mView->setSelectionMode(QAbstractItemView::SingleSelection); 54 mView->setSelectionMode(QAbstractItemView::SingleSelection);
55 mView->setSortingEnabled(true); 55 mView->setSortingEnabled(true);
56 mView->setEditTriggers(QAbstractItemView::NoEditTriggers); 56 mView->setEditTriggers(QAbstractItemView::NoEditTriggers);
57 57
58 baseLayout->addWidget(mView); 58 baseLayout->addWidget(mView);
59 mView->verticalHeader()->setVisible(false);
59 60
60 setLayout(baseLayout); 61 setLayout(baseLayout);
61 } 62 }
62 63
63 QString MetaDataView::parseMetaData(const QString& filePath) { 64 QString MetaDataView::parseMetaData(const QString& filePath) {
81 qDebug() << "Data Changed."; 82 qDebug() << "Data Changed.";
82 if (selected.isEmpty()) { 83 if (selected.isEmpty()) {
83 /* Nothing selected still we need to emit this signal to update 84 /* Nothing selected still we need to emit this signal to update
84 * the viewer otherwise selection changed handles it. */ 85 * the viewer otherwise selection changed handles it. */
85 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1, 86 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1,
86 QDateTime()); 87 QDateTime(), 0);
87 } 88 }
88 } 89 }
89 90
90 void MetaDataView::viewSelectionChanged(const QItemSelection& selected, 91 void MetaDataView::viewSelectionChanged(const QItemSelection& selected,
91 const QItemSelection& deselected) { 92 const QItemSelection& deselected) {
93 /* Nothing selected */ 94 /* Nothing selected */
94 return; 95 return;
95 } 96 }
96 /* One row selected */ 97 /* One row selected */
97 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount()); 98 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount());
98 const QModelIndex idx = selected.indexes()[0]; 99 const QModelIndex idx = selected.indexes()[FILENAME_COLUMN];
99 const QString dateString = selected.indexes()[1].data().toString(); 100 const QString dateString = selected.indexes()[DATE_COLUMN].data().toString();
100 bool ok; 101 bool ok;
101 qint64 secondsSinceEpoch = dateString.toLongLong(&ok); 102 qint64 secondsSinceEpoch = dateString.toLongLong(&ok);
102 if (!ok) { 103 if (!ok) {
103 // TODO emit error 104 // TODO emit error
104 qDebug() << "Unparsable date."; 105 qDebug() << "Unparsable date.";
105 } 106 }
106 QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000); 107 QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000);
107 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1, 108 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1,
108 timestamp); 109 timestamp, selected.indexes()[0].data().toInt());
109 qDebug() << "Selection changed: " << idx.data(); 110 qDebug() << "Selection changed: " << idx.data();
110 } 111 }
111 112
112 void MetaDataView::selectRow(int row) { 113 void MetaDataView::selectRow(int row) {
113 QItemSelectionModel *selection = mView->selectionModel(); 114 QItemSelectionModel *selection = mView->selectionModel();
173 bool sortAsc = settings.value(SORT_ORDER_KEY, SORT_ORDER_VALUE).toBool(); 174 bool sortAsc = settings.value(SORT_ORDER_KEY, SORT_ORDER_VALUE).toBool();
174 175
175 int idx = -1; 176 int idx = -1;
176 for (int i=0; i < mSortModel->columnCount(); i++) { 177 for (int i=0; i < mSortModel->columnCount(); i++) {
177 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString(); 178 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString();
179 qDebug() << "Looking at entry: " << entry;
178 if (entry.toLower() == sortField.toLower()) { 180 if (entry.toLower() == sortField.toLower()) {
179 idx = 1; 181 idx = i;
180 break; 182 break;
181 } 183 }
182 } 184 }
183 if (idx == -1) { 185 if (idx == -1) {
184 return; 186 return;
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)