Notify entry/group parent on deletion.
Also make the root group pseudo static, i.e. it shouldn't be changed after the database has been fully constructed.
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
Database::Database()
|
||||
{
|
||||
m_metadata = new Metadata(this);
|
||||
m_rootGroup = 0;
|
||||
setRootGroup(new Group());
|
||||
|
||||
m_cipher = KeePass2::CIPHER_AES;
|
||||
m_compressionAlgo = CompressionGZip;
|
||||
@@ -47,11 +47,10 @@ const Group* Database::rootGroup() const
|
||||
|
||||
void Database::setRootGroup(Group* group)
|
||||
{
|
||||
if (group != 0) {
|
||||
group->setParent(this);
|
||||
}
|
||||
Q_ASSERT(group);
|
||||
|
||||
m_rootGroup = group;
|
||||
m_rootGroup->setParent(this);
|
||||
}
|
||||
|
||||
Metadata* Database::metadata()
|
||||
|
||||
@@ -53,6 +53,10 @@ public:
|
||||
|
||||
/**
|
||||
* Sets group as the root group and takes ownership of it.
|
||||
* Warning: Be careful when calling this method as it doesn't
|
||||
* emit any notifications so e.g. models aren't updated.
|
||||
* The caller is responsible for cleaning up the pervious
|
||||
root group.
|
||||
*/
|
||||
void setRootGroup(Group* group);
|
||||
|
||||
|
||||
@@ -40,7 +40,10 @@ Entry::Entry()
|
||||
|
||||
Entry::~Entry()
|
||||
{
|
||||
// TODO notify group
|
||||
if (m_group) {
|
||||
m_group->removeEntry(this);
|
||||
}
|
||||
|
||||
qDeleteAll(m_history);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define KEEPASSX_ENTRY_H
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtGui/QColor>
|
||||
@@ -122,7 +123,7 @@ private:
|
||||
QSet<QString> m_protectedAttachments;
|
||||
|
||||
QList<Entry*> m_history;
|
||||
Group* m_group;
|
||||
QPointer<Group> m_group;
|
||||
const Database* m_db;
|
||||
const static QStringList m_defaultAttibutes;
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ Group::Group()
|
||||
|
||||
Group::~Group()
|
||||
{
|
||||
// TODO notify parent
|
||||
cleanupParent();
|
||||
}
|
||||
|
||||
Uuid Group::uuid() const
|
||||
@@ -186,22 +186,14 @@ void Group::setParent(Group* parent, int index)
|
||||
{
|
||||
Q_ASSERT(parent);
|
||||
Q_ASSERT(index >= -1 && index <= parent->children().size());
|
||||
// setting a new parent for root groups is not allowed
|
||||
Q_ASSERT(!m_db || (m_db->rootGroup() != this));
|
||||
|
||||
if (index == -1) {
|
||||
index = parent->children().size();
|
||||
}
|
||||
|
||||
Q_EMIT aboutToRemove(this);
|
||||
|
||||
if (m_parent) {
|
||||
m_parent->m_children.removeAll(this);
|
||||
}
|
||||
else if (m_db) {
|
||||
// parent was a Database
|
||||
m_db->setRootGroup(0);
|
||||
}
|
||||
|
||||
Q_EMIT removed();
|
||||
cleanupParent();
|
||||
|
||||
m_parent = parent;
|
||||
|
||||
@@ -222,16 +214,7 @@ void Group::setParent(Database* db)
|
||||
{
|
||||
Q_ASSERT(db);
|
||||
|
||||
Q_EMIT aboutToRemove(this);
|
||||
|
||||
if (m_parent) {
|
||||
m_parent->m_children.removeAll(this);
|
||||
}
|
||||
else if (m_db) {
|
||||
m_db->setRootGroup(0);
|
||||
}
|
||||
|
||||
Q_EMIT removed();
|
||||
cleanupParent();
|
||||
|
||||
m_parent = 0;
|
||||
recSetDatabase(db);
|
||||
@@ -295,6 +278,7 @@ void Group::recSetDatabase(Database* db)
|
||||
disconnect(SIGNAL(added()), m_db);
|
||||
|
||||
connect(this, SIGNAL(dataChanged(Group*)), db, SIGNAL(groupDataChanged(Group*)));
|
||||
|
||||
connect(this, SIGNAL(aboutToRemove(Group*)), db, SIGNAL(groupAboutToRemove(Group*)));
|
||||
connect(this, SIGNAL(removed()), db, SIGNAL(groupRemoved()));
|
||||
connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int)));
|
||||
@@ -306,3 +290,12 @@ void Group::recSetDatabase(Database* db)
|
||||
group->recSetDatabase(db);
|
||||
}
|
||||
}
|
||||
|
||||
void Group::cleanupParent()
|
||||
{
|
||||
if (m_parent) {
|
||||
Q_EMIT aboutToRemove(this);
|
||||
m_parent->m_children.removeAll(this);
|
||||
Q_EMIT removed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#ifndef KEEPASSX_GROUP_H
|
||||
#define KEEPASSX_GROUP_H
|
||||
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
#include "core/Database.h"
|
||||
@@ -90,8 +91,9 @@ private:
|
||||
void setParent(Database* db);
|
||||
|
||||
void recSetDatabase(Database* db);
|
||||
void cleanupParent();
|
||||
|
||||
Database* m_db;
|
||||
QPointer<Database> m_db;
|
||||
Uuid m_uuid;
|
||||
QString m_name;
|
||||
QString m_notes;
|
||||
@@ -106,9 +108,10 @@ private:
|
||||
QList<Group*> m_children;
|
||||
QList<Entry*> m_entries;
|
||||
|
||||
Group* m_parent;
|
||||
QPointer<Group> m_parent;
|
||||
|
||||
friend void Database::setRootGroup(Group* group);
|
||||
friend Entry::~Entry();
|
||||
friend void Entry::setGroup(Group *group);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user