Support setting a new parent group with an empty db.

This commit is contained in:
Felix Geyer 2012-04-27 10:50:32 +02:00
parent fdf4ab9d76
commit c36481edae
2 changed files with 38 additions and 29 deletions

View File

@ -394,13 +394,15 @@ Group* Entry::group()
void Entry::setGroup(Group* group)
{
Q_ASSERT(group);
if (m_group == group) {
return;
}
if (m_group) {
m_group->removeEntry(this);
if (m_group->database() != group->database() && m_group->database()) {
if (m_group->database() && m_group->database() != group->database()) {
m_group->database()->addDeletedObject(m_uuid);
}
}

View File

@ -1,22 +1,19 @@
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Group.h"
@ -277,8 +274,10 @@ void Group::setParent(Group* parent, int index)
if (!moveWithinDatabase) {
cleanupParent();
m_parent = parent;
if (parent->m_db) {
if (m_db) {
recCreateDelObjects();
}
if (m_db != parent->m_db) {
recSetDatabase(parent->m_db);
}
QObject::setParent(parent);
@ -312,6 +311,7 @@ void Group::setParent(Group* parent, int index)
void Group::setParent(Database* db)
{
Q_ASSERT(db);
Q_ASSERT(db->rootGroup() == this);
cleanupParent();
@ -373,6 +373,7 @@ QList<Entry*> Group::entriesRecursive(bool includeHistoryItems)
void Group::addEntry(Entry *entry)
{
Q_ASSERT(entry);
Q_ASSERT(!m_entries.contains(entry));
Q_EMIT entryAboutToAdd(entry);
@ -388,6 +389,8 @@ void Group::addEntry(Entry *entry)
void Group::removeEntry(Entry* entry)
{
Q_ASSERT(m_entries.contains(entry));
Q_EMIT entryAboutToRemove(entry);
entry->disconnect(this);
@ -416,9 +419,12 @@ void Group::recSetDatabase(Database* db)
if (m_db) {
entry->disconnect(m_db);
}
if (db) {
connect(entry, SIGNAL(modified()), db, SIGNAL(modified()));
}
}
if (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()));
@ -427,6 +433,7 @@ void Group::recSetDatabase(Database* db)
connect(this, SIGNAL(aboutToMove(Group*,Group*,int)), db, SIGNAL(groupAboutToMove(Group*,Group*,int)));
connect(this, SIGNAL(moved()), db, SIGNAL(groupMoved()));
connect(this, SIGNAL(modified()), db, SIGNAL(modified()));
}
m_db = db;