diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2017-06-04 14:40:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-06-04 07:11:01 -0700 |
commit | 03e771066bf79c2f719b58948a55547f105f2dc2 (patch) | |
tree | 3ec16e166a6c0be31d6cf6d43fd74fe516118e16 /qt-models/diveimportedmodel.cpp | |
parent | 78ee3f40a5f3b55b9d98842f7e309b7bba9882c0 (diff) | |
download | subsurface-03e771066bf79c2f719b58948a55547f105f2dc2.tar.gz |
QML UI: show selection box on the Download from DC list
QML and C++ model don't interact too much, a new Rule
should be created and used on the QML
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models/diveimportedmodel.cpp')
-rw-r--r-- | qt-models/diveimportedmodel.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index eeb564fc8..cd54da92b 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -67,7 +67,7 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const // widgets access the model via index.column(), qml via role. int column = index.column(); - if (role == DateTime || role == Duration || role == Depth) { + if (role >= DateTime) { column = role - DateTime; role = Qt::DisplayRole; } @@ -80,6 +80,8 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const return QVariant(get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min"))); case 2: return QVariant(get_depth_string(d->maxdepth.mm, true, false)); + case 3: + return checkStates[index.row()]; } } if (role == Qt::CheckStateRole) { @@ -92,25 +94,25 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const void DiveImportedModel::changeSelected(QModelIndex clickedIndex) { checkStates[clickedIndex.row()] = !checkStates[clickedIndex.row()]; - dataChanged(index(clickedIndex.row(), 0), index(clickedIndex.row(), 0), QVector<int>() << Qt::CheckStateRole); + dataChanged(index(clickedIndex.row(), 0), index(clickedIndex.row(), 0), QVector<int>() << Qt::CheckStateRole << Selected); } void DiveImportedModel::selectAll() { memset(checkStates, true, lastIndex - firstIndex + 1); - dataChanged(index(0, 0), index(lastIndex - firstIndex, 0), QVector<int>() << Qt::CheckStateRole); + dataChanged(index(0, 0), index(lastIndex - firstIndex, 0), QVector<int>() << Qt::CheckStateRole << Selected); } void DiveImportedModel::selectRow(int row) { checkStates[row] = !checkStates[row]; - dataChanged(index(row, 0), index(row, 0)); + dataChanged(index(row, 0), index(row, 0), QVector<int>() << Qt::CheckStateRole << Selected); } void DiveImportedModel::selectNone() { memset(checkStates, false, lastIndex - firstIndex + 1); - dataChanged(index(0, 0), index(lastIndex - firstIndex,0 ), QVector<int>() << Qt::CheckStateRole); + dataChanged(index(0, 0), index(lastIndex - firstIndex,0 ), QVector<int>() << Qt::CheckStateRole << Selected); } Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const @@ -176,6 +178,7 @@ QHash<int, QByteArray> DiveImportedModel::roleNames() const { { DateTime, "datetime"}, { Depth, "depth"}, { Duration, "duration"}, + { Selected, "selected"} }; return roles; } |