mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-26 03:46:49 -08:00
Introduce Group::aboutToMove() and moved() signals.
Emit them instead of remove/add when groups are moved within a database.
This commit is contained in:
1 parent
6340ed8993
commit
bddc29101c
10 files changed
+239
-37
No files matched your search
@@ -29,6 +29,8 @@ GroupModel::GroupModel(Database* db, QObject* parent)
|
||||
connect(db, SIGNAL(groupAdded()), SLOT(groupAdded()));
|
||||
connect(db, SIGNAL(groupAboutToRemove(Group*)), SLOT(groupAboutToRemove(Group*)));
|
||||
connect(db, SIGNAL(groupRemoved()), SLOT(groupRemoved()));
|
||||
connect(db, SIGNAL(groupAboutToMove(Group*,Group*,int)), SLOT(groupAboutToMove(Group*,Group*,int)));
|
||||
connect(db, SIGNAL(groupMoved()), SLOT(groupMoved()));
|
||||
}
|
||||
|
||||
int GroupModel::rowCount(const QModelIndex& parent) const
|
||||
@@ -180,3 +182,24 @@ void GroupModel::groupAdded()
|
||||
{
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void GroupModel::groupAboutToMove(Group* group, Group* toGroup, int pos)
|
||||
{
|
||||
Q_ASSERT(group->parentGroup());
|
||||
|
||||
QModelIndex oldParentIndex = parent(group);
|
||||
QModelIndex newParentIndex = index(toGroup);
|
||||
int oldPos = group->parentGroup()->children().indexOf(group);
|
||||
if (group->parentGroup() == toGroup && pos > oldPos) {
|
||||
// beginMoveRows() has a bit different semantics than Group::setParent() and
|
||||
// QList::move() when the new position is greater than the old
|
||||
pos++;
|
||||
}
|
||||
|
||||
beginMoveRows(oldParentIndex, oldPos, oldPos, newParentIndex, pos);
|
||||
}
|
||||
|
||||
void GroupModel::groupMoved()
|
||||
{
|
||||
endMoveRows();
|
||||
}
|
||||
Reference in new issue
Block a user