mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-11 16:00:52 -04:00
Convert DatabaseOpenDialog into a widget on DatabaseWidget.
This commit is contained in:
parent
900beae046
commit
92af92ccbe
15 changed files with 250 additions and 135 deletions
|
@ -27,15 +27,30 @@
|
|||
|
||||
GroupModel::GroupModel(Database* db, QObject* parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, m_db(0)
|
||||
{
|
||||
m_root = db->rootGroup();
|
||||
connect(db, SIGNAL(groupDataChanged(Group*)), SLOT(groupDataChanged(Group*)));
|
||||
connect(db, SIGNAL(groupAboutToAdd(Group*,int)), SLOT(groupAboutToAdd(Group*,int)));
|
||||
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()));
|
||||
changeDatabase(db);
|
||||
}
|
||||
|
||||
void GroupModel::changeDatabase(Database* newDb)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
if (m_db) {
|
||||
m_db->disconnect(this);
|
||||
}
|
||||
|
||||
m_db = newDb;
|
||||
|
||||
connect(m_db, SIGNAL(groupDataChanged(Group*)), SLOT(groupDataChanged(Group*)));
|
||||
connect(m_db, SIGNAL(groupAboutToAdd(Group*,int)), SLOT(groupAboutToAdd(Group*,int)));
|
||||
connect(m_db, SIGNAL(groupAdded()), SLOT(groupAdded()));
|
||||
connect(m_db, SIGNAL(groupAboutToRemove(Group*)), SLOT(groupAboutToRemove(Group*)));
|
||||
connect(m_db, SIGNAL(groupRemoved()), SLOT(groupRemoved()));
|
||||
connect(m_db, SIGNAL(groupAboutToMove(Group*,Group*,int)), SLOT(groupAboutToMove(Group*,Group*,int)));
|
||||
connect(m_db, SIGNAL(groupMoved()), SLOT(groupMoved()));
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int GroupModel::rowCount(const QModelIndex& parent) const
|
||||
|
@ -66,7 +81,7 @@ QModelIndex GroupModel::index(int row, int column, const QModelIndex& parent) co
|
|||
Group* group;
|
||||
|
||||
if (!parent.isValid()) {
|
||||
group = m_root;
|
||||
group = m_db->rootGroup();
|
||||
}
|
||||
else {
|
||||
group = groupFromIndex(parent)->children().at(row);
|
||||
|
@ -269,7 +284,7 @@ QMimeData* GroupModel::mimeData(const QModelIndexList& indexes) const
|
|||
if (!indexes[i].isValid()) {
|
||||
continue;
|
||||
}
|
||||
stream << m_root->database()->uuid() << groupFromIndex(indexes[i])->uuid();
|
||||
stream << m_db->uuid() << groupFromIndex(indexes[i])->uuid();
|
||||
}
|
||||
|
||||
data->setData(mimeTypes().first(), encoded);
|
||||
|
|
|
@ -29,6 +29,7 @@ class GroupModel : public QAbstractItemModel
|
|||
|
||||
public:
|
||||
explicit GroupModel(Database* db, QObject* parent = 0);
|
||||
void changeDatabase(Database* newDb);
|
||||
QModelIndex index(Group* group) const;
|
||||
Group* groupFromIndex(const QModelIndex& index) const;
|
||||
|
||||
|
@ -58,7 +59,7 @@ private Q_SLOTS:
|
|||
void groupMoved();
|
||||
|
||||
private:
|
||||
Group* m_root;
|
||||
Database* m_db;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_GROUPMODEL_H
|
||||
|
|
|
@ -27,28 +27,31 @@
|
|||
GroupView::GroupView(Database* db, QWidget* parent)
|
||||
: QTreeView(parent)
|
||||
, m_model(new GroupModel(db, this))
|
||||
, m_updatingExpanded(false)
|
||||
{
|
||||
QTreeView::setModel(m_model);
|
||||
setHeaderHidden(true);
|
||||
setUniformRowHeights(true);
|
||||
|
||||
recInitExpanded(db->rootGroup());
|
||||
connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(expandedChanged(QModelIndex)));
|
||||
connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(expandedChanged(QModelIndex)));
|
||||
connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(syncExpandedState(QModelIndex,int,int)));
|
||||
connect(m_model, SIGNAL(modelReset()), SLOT(modelReset()));
|
||||
|
||||
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(emitGroupChanged()));
|
||||
|
||||
setCurrentIndex(m_model->index(0, 0));
|
||||
// invoke later so the EntryView is connected
|
||||
QMetaObject::invokeMethod(this, "emitGroupChanged", Qt::QueuedConnection,
|
||||
Q_ARG(QModelIndex, m_model->index(0, 0)));
|
||||
modelReset();
|
||||
|
||||
setDragEnabled(true);
|
||||
viewport()->setAcceptDrops(true);
|
||||
setDropIndicatorShown(true);
|
||||
}
|
||||
|
||||
void GroupView::changeDatabase(Database* newDb)
|
||||
{
|
||||
m_model->changeDatabase(newDb);
|
||||
}
|
||||
|
||||
void GroupView::dragMoveEvent(QDragMoveEvent* event)
|
||||
{
|
||||
QTreeView::dragMoveEvent(event);
|
||||
|
@ -72,13 +75,19 @@ Group* GroupView::currentGroup()
|
|||
|
||||
void GroupView::expandedChanged(const QModelIndex& index)
|
||||
{
|
||||
if (m_updatingExpanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
Group* group = m_model->groupFromIndex(index);
|
||||
group->setExpanded(isExpanded(index));
|
||||
}
|
||||
|
||||
void GroupView::recInitExpanded(Group* group)
|
||||
{
|
||||
m_updatingExpanded = true;
|
||||
expandGroup(group, group->isExpanded());
|
||||
m_updatingExpanded = false;
|
||||
|
||||
Q_FOREACH (Group* child, group->children()) {
|
||||
recInitExpanded(child);
|
||||
|
@ -119,3 +128,9 @@ void GroupView::setCurrentGroup(Group* group)
|
|||
{
|
||||
setCurrentIndex(m_model->index(group));
|
||||
}
|
||||
|
||||
void GroupView::modelReset()
|
||||
{
|
||||
recInitExpanded(m_model->groupFromIndex(m_model->index(0, 0)));
|
||||
setCurrentIndex(m_model->index(0, 0));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ class GroupView : public QTreeView
|
|||
|
||||
public:
|
||||
explicit GroupView(Database* db, QWidget* parent = 0);
|
||||
void changeDatabase(Database* newDb);
|
||||
void setModel(QAbstractItemModel* model);
|
||||
Group* currentGroup();
|
||||
void setCurrentGroup(Group* group);
|
||||
|
@ -43,6 +44,7 @@ private Q_SLOTS:
|
|||
void emitGroupChanged(const QModelIndex& index);
|
||||
void emitGroupChanged();
|
||||
void syncExpandedState(const QModelIndex& parent, int start, int end);
|
||||
void modelReset();
|
||||
|
||||
protected:
|
||||
void dragMoveEvent(QDragMoveEvent* event);
|
||||
|
@ -51,6 +53,7 @@ private:
|
|||
void recInitExpanded(Group* group);
|
||||
|
||||
GroupModel* const m_model;
|
||||
bool m_updatingExpanded;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_GROUPVIEW_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue