QML UI: select / unselect dive by clicking on it

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2017-05-29 20:36:00 +02:00 committed by Dirk Hohndel
parent 1de1a85e32
commit 52e07a6306
3 changed files with 27 additions and 2 deletions

View file

@ -15,6 +15,8 @@ Kirigami.Page {
Layout.fillWidth: true; Layout.fillWidth: true;
title: qsTr("Dive Computer") title: qsTr("Dive Computer")
property bool selectAll : false
DCDownloadThread { DCDownloadThread {
id: downloadThread id: downloadThread
deviceData.vendor : comboVendor.currentText deviceData.vendor : comboVendor.currentText
@ -99,9 +101,17 @@ Kirigami.Page {
model : importModel model : importModel
delegate : DownloadedDiveDelegate { delegate : DownloadedDiveDelegate {
id: delegate
datetime: model.datetime datetime: model.datetime
duration: model.duration duration: model.duration
depth: model.depth depth: model.depth
backgroundColor: selectAll ? Kirigami.Theme.highlightColor : Kirigami.Theme.viewBackgroundColor
onClicked : {
console.log("Selecting index" + index);
importModel.selectRow(index)
}
} }
} }
@ -126,10 +136,17 @@ Kirigami.Page {
} }
Button { Button {
text: qsTr("Select All") text: qsTr("Select All")
onClicked : {
selectAll = true
importModel.selectAll()
}
} }
Button { Button {
id: unselectbutton
text: qsTr("Unselect All") text: qsTr("Unselect All")
onClicked : {
selectAll = false
importModel.selectNone()
}
} }
} }
} }

View file

@ -101,6 +101,12 @@ void DiveImportedModel::selectAll()
dataChanged(index(0, 0), index(lastIndex - firstIndex, 0), QVector<int>() << Qt::CheckStateRole); dataChanged(index(0, 0), index(lastIndex - firstIndex, 0), QVector<int>() << Qt::CheckStateRole);
} }
void DiveImportedModel::selectRow(int row)
{
checkStates[row] = !checkStates[row];
dataChanged(index(row, 0), index(row, 0));
}
void DiveImportedModel::selectNone() void DiveImportedModel::selectNone()
{ {
memset(checkStates, false, lastIndex - firstIndex + 1); memset(checkStates, false, lastIndex - firstIndex + 1);
@ -169,6 +175,7 @@ QHash<int, QByteArray> DiveImportedModel::roleNames() const {
static QHash<int, QByteArray> roles = { static QHash<int, QByteArray> roles = {
{ DateTime, "datetime"}, { DateTime, "datetime"},
{ Depth, "depth"}, { Depth, "depth"},
{ Duration, "duration"}}; { Duration, "duration"},
};
return roles; return roles;
} }

View file

@ -25,6 +25,7 @@ public:
public public
slots: slots:
void changeSelected(QModelIndex clickedIndex); void changeSelected(QModelIndex clickedIndex);
void selectRow(int row);
void selectAll(); void selectAll();
void selectNone(); void selectNone();