diff --git a/src/Kdb3Database.cpp b/src/Kdb3Database.cpp index 91917ba..e614268 100644 --- a/src/Kdb3Database.cpp +++ b/src/Kdb3Database.cpp @@ -52,7 +52,7 @@ bool Kdb3Database::StdEntryLessThan(const Kdb3Database::StdEntry& This,const Kdb } -Kdb3Database::Kdb3Database() : RawMasterKey(32), RawMasterKey_CP1252(32), +Kdb3Database::Kdb3Database() : File(NULL), RawMasterKey(32), RawMasterKey_CP1252(32), RawMasterKey_Latin1(32), RawMasterKey_UTF8(32), MasterKey(32){ } @@ -448,14 +448,28 @@ bool Kdb3Database::createGroupTree(QList& Levels){ for(int i=0;iId){ + groupIndex = g; + break; + } } } + + Groups[groupIndex].Entries.append(&Entries[e]); + Entries[e].Group=&Groups[groupIndex]; + Entries[e].Index=EntryIndexCounter[groupIndex]; + EntryIndexCounter[groupIndex]++; } return true; @@ -1105,13 +1119,16 @@ IGroupHandle* Kdb3Database::addGroup(const CGroup* group,IGroupHandle* ParentHan Groups.back().Parent->Children.append(&Groups.back()); } else{ + // Insert to root group. Try to keep Backup group at the end. Groups.back().Parent=&RootGroup; Groups.back().Index=RootGroup.Children.size(); - if (group->Title!="Backup" && RootGroup.Children.size() && RootGroup.Children.last()->Title=="Backup"){ + int position = RootGroup.Children.size(); + if (group->Title!="Backup" && !RootGroup.Children.isEmpty() && RootGroup.Children.last()->Title=="Backup"){ RootGroup.Children.last()->Index = Groups.back().Index; Groups.back().Index--; + position--; } - Groups.back().Parent->Children.append(&Groups.back()); + RootGroup.Children.insert(position, &Groups.back()); } return &GroupHandles.back(); } @@ -1136,11 +1153,25 @@ IGroupHandle* Kdb3Database::backupGroup(bool create){ return group; } +Kdb3Database::StdEntry::StdEntry(){ + Handle = NULL; + Group = NULL; +} + +Kdb3Database::StdGroup::StdGroup(){ + Index=0; + Id=0; + Parent=NULL; + Handle=NULL; +} + Kdb3Database::StdGroup::StdGroup(const CGroup& other){ Index=0; Id=other.Id; Image=other.Image; Title=other.Title; + Parent=NULL; + Handle=NULL; } void Kdb3Database::EntryHandle::setTitle(const QString& Title){Entry->Title=Title; } @@ -1226,6 +1257,7 @@ void Kdb3Database::EntryHandle::setVisualIndex(int index){ Kdb3Database::EntryHandle::EntryHandle(Kdb3Database* db){ pDB=db; valid=true; + Entry=NULL; } diff --git a/src/Kdb3Database.h b/src/Kdb3Database.h index 765bbf9..ca96db9 100644 --- a/src/Kdb3Database.h +++ b/src/Kdb3Database.h @@ -117,6 +117,7 @@ public: class StdEntry:public CEntry{ public: + StdEntry(); quint16 Index; EntryHandle* Handle; StdGroup* Group; @@ -124,7 +125,7 @@ public: class StdGroup:public CGroup{ public: - StdGroup():CGroup(){}; + StdGroup(); StdGroup(const CGroup&); quint16 Index; StdGroup* Parent;