very simple but effective up and down arrows
This commit is contained in:
parent
c10e42cc2c
commit
016756df72
3 changed files with 38 additions and 31 deletions
|
@ -280,6 +280,8 @@ ColumnLayout {
|
|||
return;
|
||||
if (newIndex === -1)
|
||||
newIndex = 0;
|
||||
if (newIndex >= serviceItemList.count)
|
||||
newIndex = serviceItemList.count;
|
||||
print("moveRequested: ", oldIndex, newIndex);
|
||||
serviceItemModel.move(oldIndex, newIndex);
|
||||
indexDragged = newIndex;
|
||||
|
@ -359,32 +361,23 @@ ColumnLayout {
|
|||
/* text: "Down" */
|
||||
icon.name: "arrow-down"
|
||||
onTriggered: {
|
||||
const oldid = serviceItemList.currentIndex;
|
||||
if (oldid + 1 >= serviceItemList.count)
|
||||
const id = serviceItemList.currentIndex;
|
||||
if (id + 1 >= serviceItemList.count)
|
||||
{
|
||||
showPassiveNotification("wow you dummy you can't got further down");
|
||||
return;
|
||||
};
|
||||
const newid = findId(serviceItemList.currentIndex + 2);
|
||||
showPassiveNotification(oldid + " " + newid);
|
||||
showPassiveNotification("Down");
|
||||
const ans = serviceItemModel.move(oldid, newid);
|
||||
showPassiveNotification("moving ", id, " down");
|
||||
const ans = serviceItemModel.moveDown(id);
|
||||
if (ans)
|
||||
{
|
||||
serviceItemList.currentIndex = newid - 1;
|
||||
serviceItemList.currentIndex = id + 1;
|
||||
showPassiveNotification("move was successful, newid: "
|
||||
+ serviceItemList.currentIndex);
|
||||
}
|
||||
else
|
||||
showPassiveNotification("move was unsuccessful, newid: "
|
||||
+ newid);
|
||||
|
||||
function findId(id) {
|
||||
if (id >= serviceItemList.count)
|
||||
return serviceItemList.count;
|
||||
else
|
||||
return id;
|
||||
}
|
||||
showPassiveNotification("move was unsuccessful, id: "
|
||||
+ id);
|
||||
}
|
||||
},
|
||||
Kirigami.Action {
|
||||
|
|
|
@ -234,21 +234,34 @@ bool ServiceItemModel::move(int sourceIndex, int destIndex) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ServiceItemModel::move(int sourceIndex, int destIndex, bool simple) {
|
||||
qDebug() << index(sourceIndex).row();
|
||||
qDebug() << index(destIndex).row();
|
||||
QModelIndex parent = index(sourceIndex).parent();
|
||||
bool ServiceItemModel::moveDown(int id) {
|
||||
qDebug() << index(id).row();
|
||||
qDebug() << index(id + 1).row();
|
||||
QModelIndex parent = index(id).parent();
|
||||
|
||||
if (simple)
|
||||
bool begsuc = beginMoveRows(parent, id,
|
||||
id, parent, id + 2);
|
||||
if (begsuc) {
|
||||
int dest = id + 1;
|
||||
if (dest >= m_items.size())
|
||||
{
|
||||
if (moveRow(parent, sourceIndex, parent, destIndex))
|
||||
return true;
|
||||
qDebug() << "dest too big, moving to end";
|
||||
m_items.move(id, m_items.size() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "not sure...";
|
||||
m_items.move(id, dest);
|
||||
endMoveRows();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ServiceItemModel::moveUp(int id) {
|
||||
qDebug() << index(id).row();
|
||||
qDebug() << index(id - 1).row();
|
||||
QModelIndex parent = index(id).parent();
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ public:
|
|||
const QString &backgroundType, const QStringList &text);
|
||||
Q_INVOKABLE void removeItem(int index);
|
||||
Q_INVOKABLE bool move(int sourceIndex, int destIndex);
|
||||
Q_INVOKABLE bool move(int sourceIndex, int destIndex, bool simple);
|
||||
Q_INVOKABLE bool moveDown(int index);
|
||||
Q_INVOKABLE bool moveUp(int index);
|
||||
Q_INVOKABLE QVariantMap getItem(int index) const;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue