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