diff options
Diffstat (limited to 'homescreen/src')
-rw-r--r-- | homescreen/src/applicationmodel.cpp | 28 | ||||
-rw-r--r-- | homescreen/src/applicationmodel.h | 2 |
2 files changed, 30 insertions, 0 deletions
diff --git a/homescreen/src/applicationmodel.cpp b/homescreen/src/applicationmodel.cpp index c43e1bc..417bc4c 100644 --- a/homescreen/src/applicationmodel.cpp +++ b/homescreen/src/applicationmodel.cpp @@ -114,3 +114,31 @@ QHash<int, QByteArray> ApplicationModel::roleNames() const roles[Qt::UserRole] = "id"; return roles; } + +QString ApplicationModel::id(int i) const +{ + return data(index(i), Qt::UserRole).toString(); +} + +void ApplicationModel::move(int from, int to) +{ + QModelIndex parent; + if (to < 0 || to > rowCount()) return; + if (from < to) { + if (!beginMoveRows(parent, from, from, parent, to + 1)) { + qDebug() << from << to << false; + return; + } + d->data.move(from, to); + endMoveRows(); + } else if (from > to) { + if (!beginMoveRows(parent, from, from, parent, to)) { + qDebug() << from << to << false; + return; + } + d->data.move(from, to); + endMoveRows(); + } else { + qDebug() << from << to << false; + } +} diff --git a/homescreen/src/applicationmodel.h b/homescreen/src/applicationmodel.h index bffc4c9..2414b7e 100644 --- a/homescreen/src/applicationmodel.h +++ b/homescreen/src/applicationmodel.h @@ -30,6 +30,8 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QHash<int, QByteArray> roleNames() const override; + Q_INVOKABLE QString id(int index) const; + Q_INVOKABLE void move(int from, int to); private: class Private; |