comparison src/metadataview.cpp @ 3:248d5d1cdb38

Add functionalty to control buttons and make picture resizable
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 23 Mar 2015 19:10:01 +0100
parents 97d2c8869c39
children e4748da7140b
comparison
equal deleted inserted replaced
2:97d2c8869c39 3:248d5d1cdb38
55 void MetaDataView::viewSelectionChanged(const QItemSelection& selected, 55 void MetaDataView::viewSelectionChanged(const QItemSelection& selected,
56 const QItemSelection& deselected) { 56 const QItemSelection& deselected) {
57 /* One row selected */ 57 /* One row selected */
58 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount()); 58 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount());
59 const QModelIndex idx = selected.indexes()[0]; 59 const QModelIndex idx = selected.indexes()[0];
60 emit selectionChanged(idx.data().toString(), QString()); 60 const QString dateString = selected.indexes()[1].data().toString();
61 bool ok;
62 qint64 secondsSinceEpoch = dateString.toLongLong(&ok);
63 if (!ok) {
64 // TODO emit error
65 qDebug() << "Unparsable date.";
66 }
67 QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000);
68 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1,
69 timestamp);
61 qDebug() << "Selection changed: " << idx.data(); 70 qDebug() << "Selection changed: " << idx.data();
71 }
72
73 void MetaDataView::selectRow(int row) {
74 QItemSelectionModel *selection = mView->selectionModel();
75 if (!mSortModel->hasIndex(row, 0)) {
76 qDebug() << "Invalid row: " << row;
77 return;
78 }
79 QModelIndex newIdx = mSortModel->index(row, 0);
80 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
81 }
82
83 void MetaDataView::selectPrevRow() {
84 QItemSelectionModel *selection = mView->selectionModel();
85 QModelIndexList selected = selection->selectedIndexes();
86 int row = 0,
87 col = 0;
88 if (selected.isEmpty()) {
89 qDebug() << "Selection empty. Start at row 0";
90 if (!mSortModel->hasIndex(row, col)) {
91 qDebug() << "Empty model. Failed to advance.";
92 return;
93 }
94 } else {
95 QModelIndex old = selection->selectedIndexes().first();
96 if (!mSortModel->hasIndex(old.row() - 1, old.column())) {
97 qDebug() << "No less rows.";
98 return;
99 }
100 row = old.row() - 1;
101 col = old.column();
102 }
103 QModelIndex newIdx = mSortModel->index(row, col);
104 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
62 } 105 }
63 106
64 void MetaDataView::selectNextRow() { 107 void MetaDataView::selectNextRow() {
65 QItemSelectionModel *selection = mView->selectionModel(); 108 QItemSelectionModel *selection = mView->selectionModel();
66 QModelIndexList selected = selection->selectedIndexes(); 109 QModelIndexList selected = selection->selectedIndexes();
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)