Mercurial > retraceit
diff 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 |
line wrap: on
line diff
--- a/src/metadataview.cpp Mon Mar 23 16:34:42 2015 +0100 +++ b/src/metadataview.cpp Mon Mar 23 19:10:01 2015 +0100 @@ -57,10 +57,53 @@ /* One row selected */ Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount()); const QModelIndex idx = selected.indexes()[0]; - emit selectionChanged(idx.data().toString(), QString()); + const QString dateString = selected.indexes()[1].data().toString(); + bool ok; + qint64 secondsSinceEpoch = dateString.toLongLong(&ok); + if (!ok) { + // TODO emit error + qDebug() << "Unparsable date."; + } + QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000); + emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1, + timestamp); qDebug() << "Selection changed: " << idx.data(); } +void MetaDataView::selectRow(int row) { + QItemSelectionModel *selection = mView->selectionModel(); + if (!mSortModel->hasIndex(row, 0)) { + qDebug() << "Invalid row: " << row; + return; + } + QModelIndex newIdx = mSortModel->index(row, 0); + selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); +} + +void MetaDataView::selectPrevRow() { + QItemSelectionModel *selection = mView->selectionModel(); + QModelIndexList selected = selection->selectedIndexes(); + int row = 0, + col = 0; + if (selected.isEmpty()) { + qDebug() << "Selection empty. Start at row 0"; + if (!mSortModel->hasIndex(row, col)) { + qDebug() << "Empty model. Failed to advance."; + return; + } + } else { + QModelIndex old = selection->selectedIndexes().first(); + if (!mSortModel->hasIndex(old.row() - 1, old.column())) { + qDebug() << "No less rows."; + return; + } + row = old.row() - 1; + col = old.column(); + } + QModelIndex newIdx = mSortModel->index(row, col); + selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); +} + void MetaDataView::selectNextRow() { QItemSelectionModel *selection = mView->selectionModel(); QModelIndexList selected = selection->selectedIndexes();