Add modified signals for groups.

This commit is contained in:
Florian Geyer 2012-04-11 18:00:28 +02:00 committed by Felix Geyer
parent 875c01dc52
commit 8b62365f8e
3 changed files with 60 additions and 19 deletions

View file

@ -33,6 +33,8 @@ Group::Group()
m_isExpanded = true; m_isExpanded = true;
m_autoTypeEnabled = Inherit; m_autoTypeEnabled = Inherit;
m_searchingEnabled = Inherit; m_searchingEnabled = Inherit;
m_updateTimeinfo = true;
} }
Group::~Group() Group::~Group()
@ -40,6 +42,25 @@ Group::~Group()
cleanupParent(); cleanupParent();
} }
template <class T> bool Group::set(T& property, const T& value) {
if (property != value) {
property = value;
if (m_updateTimeinfo) {
m_timeInfo.setLastModificationTime(QDateTime::currentDateTime());
m_timeInfo.setLastAccessTime(QDateTime::currentDateTime());
}
Q_EMIT modified();
return true;
}
else {
return false;
}
}
void Group::setUpdateTimeinfo(bool value) {
m_updateTimeinfo = value;
}
Uuid Group::uuid() const Uuid Group::uuid() const
{ {
return m_uuid; return m_uuid;
@ -125,43 +146,47 @@ Entry* Group::lastTopVisibleEntry() const
void Group::setUuid(const Uuid& uuid) void Group::setUuid(const Uuid& uuid)
{ {
m_uuid = uuid; set(m_uuid, uuid);
} }
void Group::setName(const QString& name) void Group::setName(const QString& name)
{ {
m_name = name; if (set(m_name, name)) {
Q_EMIT dataChanged(this);
Q_EMIT dataChanged(this); }
} }
void Group::setNotes(const QString& notes) void Group::setNotes(const QString& notes)
{ {
m_notes = notes; set(m_notes, notes);
} }
void Group::setIcon(int iconNumber) void Group::setIcon(int iconNumber)
{ {
Q_ASSERT(iconNumber >= 0); Q_ASSERT(iconNumber >= 0);
m_iconNumber = iconNumber; if (m_iconNumber != iconNumber || !m_customIcon.isNull()) {
m_customIcon = Uuid(); m_iconNumber = iconNumber;
m_customIcon = Uuid();
m_pixmapCacheKey = QPixmapCache::Key(); m_pixmapCacheKey = QPixmapCache::Key();
Q_EMIT dataChanged(this); Q_EMIT modified();
Q_EMIT dataChanged(this);
}
} }
void Group::setIcon(const Uuid& uuid) void Group::setIcon(const Uuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
m_iconNumber = 0; if (set(m_customIcon, uuid)) {
m_customIcon = uuid; m_iconNumber = 0;
m_pixmapCacheKey = QPixmapCache::Key(); m_pixmapCacheKey = QPixmapCache::Key();
Q_EMIT dataChanged(this); Q_EMIT dataChanged(this);
}
} }
void Group::setTimeInfo(const TimeInfo& timeInfo) void Group::setTimeInfo(const TimeInfo& timeInfo)
@ -171,27 +196,27 @@ void Group::setTimeInfo(const TimeInfo& timeInfo)
void Group::setExpanded(bool expanded) void Group::setExpanded(bool expanded)
{ {
m_isExpanded = expanded; set(m_isExpanded, expanded);
} }
void Group::setDefaultAutoTypeSequence(const QString& sequence) void Group::setDefaultAutoTypeSequence(const QString& sequence)
{ {
m_defaultAutoTypeSequence = sequence; set(m_defaultAutoTypeSequence, sequence);
} }
void Group::setAutoTypeEnabled(TriState enable) void Group::setAutoTypeEnabled(TriState enable)
{ {
m_autoTypeEnabled = enable; set(m_autoTypeEnabled, enable);
} }
void Group::setSearchingEnabled(TriState enable) void Group::setSearchingEnabled(TriState enable)
{ {
m_searchingEnabled = enable; set(m_searchingEnabled, enable);
} }
void Group::setLastTopVisibleEntry(Entry* entry) void Group::setLastTopVisibleEntry(Entry* entry)
{ {
m_lastTopVisibleEntry = entry; set(m_lastTopVisibleEntry, entry);
} }
Group* Group::parentGroup() Group* Group::parentGroup()
@ -215,6 +240,7 @@ void Group::setParent(Group* parent, int index)
index = parent->children().size(); index = parent->children().size();
} }
cleanupParent(); cleanupParent();
m_parent = parent; m_parent = parent;
@ -229,6 +255,7 @@ void Group::setParent(Group* parent, int index)
parent->m_children.insert(index, this); parent->m_children.insert(index, this);
Q_EMIT modified();
Q_EMIT added(); Q_EMIT added();
} }
@ -298,13 +325,14 @@ void Group::recSetDatabase(Database* db)
disconnect(SIGNAL(removed()), m_db); disconnect(SIGNAL(removed()), m_db);
disconnect(SIGNAL(aboutToAdd(Group*,int)), m_db); disconnect(SIGNAL(aboutToAdd(Group*,int)), m_db);
disconnect(SIGNAL(added()), m_db); disconnect(SIGNAL(added()), m_db);
disconnect(SIGNAL(modified()), m_db);
connect(this, SIGNAL(dataChanged(Group*)), db, SIGNAL(groupDataChanged(Group*))); connect(this, SIGNAL(dataChanged(Group*)), db, SIGNAL(groupDataChanged(Group*)));
connect(this, SIGNAL(aboutToRemove(Group*)), db, SIGNAL(groupAboutToRemove(Group*))); connect(this, SIGNAL(aboutToRemove(Group*)), db, SIGNAL(groupAboutToRemove(Group*)));
connect(this, SIGNAL(removed()), db, SIGNAL(groupRemoved())); connect(this, SIGNAL(removed()), db, SIGNAL(groupRemoved()));
connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int))); connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int)));
connect(this, SIGNAL(added()), db, SIGNAL(groupAdded())); connect(this, SIGNAL(added()), db, SIGNAL(groupAdded()));
connect(this, SIGNAL(modified()), db, SIGNAL(modified()));
m_db = db; m_db = db;
@ -318,6 +346,7 @@ void Group::cleanupParent()
if (m_parent) { if (m_parent) {
Q_EMIT aboutToRemove(this); Q_EMIT aboutToRemove(this);
m_parent->m_children.removeAll(this); m_parent->m_children.removeAll(this);
Q_EMIT modified();
Q_EMIT removed(); Q_EMIT removed();
} }
} }

View file

@ -63,6 +63,8 @@ public:
void setSearchingEnabled(TriState enable); void setSearchingEnabled(TriState enable);
void setLastTopVisibleEntry(Entry* entry); void setLastTopVisibleEntry(Entry* entry);
void setUpdateTimeinfo(bool value);
Group* parentGroup(); Group* parentGroup();
const Group* parentGroup() const; const Group* parentGroup() const;
void setParent(Group* parent, int index = -1); void setParent(Group* parent, int index = -1);
@ -88,7 +90,11 @@ Q_SIGNALS:
void entryDataChanged(Entry* entry); void entryDataChanged(Entry* entry);
void modified();
private: private:
template <class T> inline bool set(T& property, const T& value);
void addEntry(Entry* entry); void addEntry(Entry* entry);
void removeEntry(Entry* entry); void removeEntry(Entry* entry);
void setParent(Database* db); void setParent(Database* db);
@ -114,6 +120,8 @@ private:
QPointer<Group> m_parent; QPointer<Group> m_parent;
QPixmapCache::Key m_pixmapCacheKey; QPixmapCache::Key m_pixmapCacheKey;
bool m_updateTimeinfo;
friend void Database::setRootGroup(Group* group); friend void Database::setRootGroup(Group* group);
friend Entry::~Entry(); friend Entry::~Entry();
friend void Entry::setGroup(Group *group); friend void Entry::setGroup(Group *group);

View file

@ -64,6 +64,9 @@ void KeePass2XmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Ra
} }
m_meta->setUpdateDatetime(true); m_meta->setUpdateDatetime(true);
Q_FOREACH (Group* group, m_groups) {
group->setUpdateTimeinfo(true);
}
delete m_tmpParent; delete m_tmpParent;
} }
@ -785,6 +788,7 @@ Group* KeePass2XmlReader::getGroup(const Uuid& uuid)
} }
Group* group = new Group(); Group* group = new Group();
group->setUpdateTimeinfo(false);
group->setUuid(uuid); group->setUuid(uuid);
group->setParent(m_tmpParent); group->setParent(m_tmpParent);
m_groups << group; m_groups << group;