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>
This commit is contained in:
Tomaz Canabrava 2017-06-04 14:40:25 +02:00 committed by Dirk Hohndel
parent 78ee3f40a5
commit 03e771066b
4 changed files with 18 additions and 7 deletions

View file

@ -116,6 +116,7 @@ Kirigami.Page {
datetime: model.datetime datetime: model.datetime
duration: model.duration duration: model.duration
depth: model.depth depth: model.depth
selected: model.selected
backgroundColor: selectAll ? Kirigami.Theme.highlightColor : Kirigami.Theme.viewBackgroundColor backgroundColor: selectAll ? Kirigami.Theme.highlightColor : Kirigami.Theme.viewBackgroundColor

View file

@ -12,6 +12,7 @@ Kirigami.AbstractListItem {
property string depth property string depth
property string datetime property string datetime
property string duration property string duration
property bool selected
enabled: true enabled: true
supportsMouseEvents: true supportsMouseEvents: true
@ -30,9 +31,15 @@ Kirigami.AbstractListItem {
NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 400 } NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 400 }
NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 400 } NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 400 }
} }
CheckBox {
id: diveIsSelected
checked: innerListItem.selected;
width: childrenRect.heigh - Kirigami.Units.smallSpacing;
height: childrenRect.heigh - Kirigami.Units.smallSpacing;
}
Item { Item {
id: diveListEntry id: diveListEntry
width: parent.width - Kirigami.Units.gridUnit * (innerListItem.deleteButtonVisible ? 3 : 1) width: parent.width - diveIsSelected.width - Kirigami.Units.gridUnit * (innerListItem.deleteButtonVisible ? 3 : 1)
height: childrenRect.height - Kirigami.Units.smallSpacing height: childrenRect.height - Kirigami.Units.smallSpacing
Kirigami.Label { Kirigami.Label {

View file

@ -67,7 +67,7 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
// widgets access the model via index.column(), qml via role. // widgets access the model via index.column(), qml via role.
int column = index.column(); int column = index.column();
if (role == DateTime || role == Duration || role == Depth) { if (role >= DateTime) {
column = role - DateTime; column = role - DateTime;
role = Qt::DisplayRole; 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"))); return QVariant(get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min")));
case 2: case 2:
return QVariant(get_depth_string(d->maxdepth.mm, true, false)); return QVariant(get_depth_string(d->maxdepth.mm, true, false));
case 3:
return checkStates[index.row()];
} }
} }
if (role == Qt::CheckStateRole) { if (role == Qt::CheckStateRole) {
@ -92,25 +94,25 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
void DiveImportedModel::changeSelected(QModelIndex clickedIndex) void DiveImportedModel::changeSelected(QModelIndex clickedIndex)
{ {
checkStates[clickedIndex.row()] = !checkStates[clickedIndex.row()]; 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() void DiveImportedModel::selectAll()
{ {
memset(checkStates, true, lastIndex - firstIndex + 1); 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) void DiveImportedModel::selectRow(int row)
{ {
checkStates[row] = !checkStates[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() void DiveImportedModel::selectNone()
{ {
memset(checkStates, false, lastIndex - firstIndex + 1); 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 Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const
@ -176,6 +178,7 @@ QHash<int, QByteArray> DiveImportedModel::roleNames() const {
{ DateTime, "datetime"}, { DateTime, "datetime"},
{ Depth, "depth"}, { Depth, "depth"},
{ Duration, "duration"}, { Duration, "duration"},
{ Selected, "selected"}
}; };
return roles; return roles;
} }

View file

@ -8,7 +8,7 @@ class DiveImportedModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
enum roleTypes { DateTime = Qt::UserRole + 1, Duration, Depth}; enum roleTypes { DateTime = Qt::UserRole + 1, Duration, Depth, Selected};
DiveImportedModel(QObject *parent = 0); DiveImportedModel(QObject *parent = 0);
void setDiveTable(struct dive_table *table); void setDiveTable(struct dive_table *table);