Un-constify Entry* and Group* in various related signals and models/views.

This commit is contained in:
Felix Geyer 2010-08-23 21:30:20 +02:00
parent d2e677c7f4
commit e96c3bb011
11 changed files with 66 additions and 65 deletions

View File

@ -43,10 +43,10 @@ public:
Group* resolveGroup(const Uuid& uuid);
Q_SIGNALS:
void groupDataChanged(const Group* group);
void groupAboutToAdd(const Group* group, int index);
void groupDataChanged(Group* group);
void groupAboutToAdd(Group* group, int index);
void groupAdded();
void groupAboutToRemove(const Group* group);
void groupAboutToRemove(Group* group);
void groupRemoved();
private:

View File

@ -84,7 +84,7 @@ public:
void setGroup(Group* group);
Q_SIGNALS:
void dataChanged(const Entry* entry);
void dataChanged(Entry* entry);
private:
Uuid m_uuid;

View File

@ -167,6 +167,11 @@ void Group::setLastTopVisibleEntry(Entry* entry)
m_lastTopVisibleEntry = entry;
}
Group* Group::parentGroup()
{
return m_parent;
}
const Group* Group::parentGroup() const
{
return m_parent;
@ -273,7 +278,7 @@ void Group::addEntry(Entry *entry)
Q_EMIT entryAboutToAdd(entry);
m_entries << entry;
connect(entry, SIGNAL(dataChanged(const Entry*)), SIGNAL(entryDataChanged(const Entry*)));
connect(entry, SIGNAL(dataChanged(Entry*)), SIGNAL(entryDataChanged(Entry*)));
Q_EMIT entryAdded();
}
@ -290,16 +295,16 @@ void Group::removeEntry(Entry* entry)
void Group::recSetDatabase(Database* db)
{
disconnect(SIGNAL(dataChanged(const Group*)), m_db);
disconnect(SIGNAL(aboutToRemove(const Group*)), m_db);
disconnect(SIGNAL(dataChanged(Group*)), m_db);
disconnect(SIGNAL(aboutToRemove(Group*)), m_db);
disconnect(SIGNAL(removed()), m_db);
disconnect(SIGNAL(aboutToAdd(const Group*,int)), m_db);
disconnect(SIGNAL(aboutToAdd(Group*,int)), m_db);
disconnect(SIGNAL(added()), m_db);
connect(this, SIGNAL(dataChanged(const Group*)), db, SIGNAL(groupDataChanged(const Group*)));
connect(this, SIGNAL(aboutToRemove(const Group*)), db, SIGNAL(groupAboutToRemove(const Group*)));
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(const Group*,int)), db, SIGNAL(groupAboutToAdd(const Group*,int)));
connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int)));
connect(this, SIGNAL(added()), db, SIGNAL(groupAdded()));
m_db = db;

View File

@ -58,6 +58,7 @@ public:
void setSearchingEnabled(int enable);
void setLastTopVisibleEntry(Entry* entry);
Group* parentGroup();
const Group* parentGroup() const;
void setParent(Group* parent, int index = -1);
void setParent(Database* db);
@ -71,19 +72,19 @@ public:
void removeEntry(Entry* entry);
Q_SIGNALS:
void dataChanged(const Group* group);
void dataChanged(Group* group);
void aboutToAdd(const Group* group, int index);
void aboutToAdd(Group* group, int index);
void added();
void aboutToRemove(const Group* group);
void aboutToRemove(Group* group);
void removed();
void entryAboutToAdd(const Entry* entry);
void entryAboutToAdd(Entry* entry);
void entryAdded();
void entryAboutToRemove(const Entry* entry);
void entryAboutToRemove(Entry* entry);
void entryRemoved();
void entryDataChanged(const Entry* entry);
void entryDataChanged(Entry* entry);
private:
void recSetDatabase(Database* db);

View File

@ -26,7 +26,7 @@ EntryModel::EntryModel(QObject* parent)
{
}
void EntryModel::setGroup(const Group* group)
void EntryModel::setGroup(Group* group)
{
beginResetModel();
@ -34,11 +34,11 @@ void EntryModel::setGroup(const Group* group)
disconnect(m_group, 0, this, 0);
}
m_group = group;
connect(group, SIGNAL(entryAboutToAdd(const Entry*)), SLOT(entryAboutToAdd(const Entry*)));
connect(group, SIGNAL(entryAboutToAdd(Entry*)), SLOT(entryAboutToAdd(Entry*)));
connect(group, SIGNAL(entryAdded()), SLOT(entryAdded()));
connect(group, SIGNAL(entryAboutToRemove(const Entry*)), SLOT(entryAboutToRemove(const Entry*)));
connect(group, SIGNAL(entryAboutToRemove(Entry*)), SLOT(entryAboutToRemove(Entry*)));
connect(group, SIGNAL(entryRemoved()), SLOT(entryRemoved()));
connect(group, SIGNAL(entryDataChanged(const Entry*)), SLOT(entryDataChanged(const Entry*)));
connect(group, SIGNAL(entryDataChanged(Entry*)), SLOT(entryDataChanged(Entry*)));
endResetModel();
}
@ -66,7 +66,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
return QVariant();
}
const Entry* entry = m_group->entries().at(index.row());
Entry* entry = m_group->entries().at(index.row());
// TODO implement other columns
if (role == Qt::DisplayRole) {
@ -90,7 +90,7 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
return QVariant();
}
void EntryModel::entryAboutToAdd(const Entry* entry)
void EntryModel::entryAboutToAdd(Entry* entry)
{
Q_UNUSED(entry);
@ -102,7 +102,7 @@ void EntryModel::entryAdded()
endInsertRows();
}
void EntryModel::entryAboutToRemove(const Entry* entry)
void EntryModel::entryAboutToRemove(Entry* entry)
{
beginRemoveRows(QModelIndex(), m_group->entries().indexOf(entry), m_group->entries().indexOf(entry));
}
@ -112,7 +112,7 @@ void EntryModel::entryRemoved()
endRemoveRows();
}
void EntryModel::entryDataChanged(const Entry* entry)
void EntryModel::entryDataChanged(Entry* entry)
{
int row = m_group->entries().indexOf(entry);
qDebug("%d", index(row, 0).row());

View File

@ -35,17 +35,17 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
public Q_SLOTS:
void setGroup(const Group* group);
void setGroup(Group* group);
private Q_SLOTS:
void entryAboutToAdd(const Entry* entry);
void entryAboutToAdd(Entry* entry);
void entryAdded();
void entryAboutToRemove(const Entry* entry);
void entryAboutToRemove(Entry* entry);
void entryRemoved();
void entryDataChanged(const Entry* entry);
void entryDataChanged(Entry* entry);
private:
const Group* m_group;
Group* m_group;
};
#endif // KEEPASSX_ENTRYMODEL_H

View File

@ -20,13 +20,13 @@
#include "core/Database.h"
#include "core/Group.h"
GroupModel::GroupModel(const Database* db, QObject* parent) : QAbstractItemModel(parent)
GroupModel::GroupModel(Database* db, QObject* parent) : QAbstractItemModel(parent)
{
m_root = db->rootGroup();
connect(db, SIGNAL(groupDataChanged(const Group*)), SLOT(groupDataChanged(const Group*)));
connect(db, SIGNAL(groupAboutToAdd(const Group*,int)), SLOT(groupAboutToAdd(const Group*,int)));
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(const Group*)), SLOT(groupAboutToRemove(const Group*)));
connect(db, SIGNAL(groupAboutToRemove(Group*)), SLOT(groupAboutToRemove(Group*)));
connect(db, SIGNAL(groupRemoved()), SLOT(groupRemoved()));
}
@ -55,7 +55,7 @@ QModelIndex GroupModel::index(int row, int column, const QModelIndex& parent) co
return QModelIndex();
}
const Group* group;
Group* group;
if (!parent.isValid()) {
group = m_root;
@ -76,9 +76,9 @@ QModelIndex GroupModel::parent(const QModelIndex& index) const
return parent(groupFromIndex(index));
}
QModelIndex GroupModel::parent(const Group* group) const
QModelIndex GroupModel::parent(Group* group) const
{
const Group* parentGroup = group->parentGroup();
Group* parentGroup = group->parentGroup();
if (!parentGroup) {
// index is already the root group
@ -102,7 +102,7 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const
return QVariant();
}
const Group* group = groupFromIndex(index);
Group* group = groupFromIndex(index);
if (role == Qt::DisplayRole) {
return group->name();
@ -124,7 +124,7 @@ QVariant GroupModel::headerData(int section, Qt::Orientation orientation, int ro
return QVariant();
}
QModelIndex GroupModel::index(const Group* group) const
QModelIndex GroupModel::index(Group* group) const
{
int row;
@ -138,25 +138,20 @@ QModelIndex GroupModel::index(const Group* group) const
return createIndex(row, 0, group);
}
QModelIndex GroupModel::createIndex(int row, int column, const Group* group) const
{
return QAbstractItemModel::createIndex(row, column, const_cast<Group*>(group));
}
const Group* GroupModel::groupFromIndex(const QModelIndex& index) const
Group* GroupModel::groupFromIndex(const QModelIndex& index) const
{
Q_ASSERT(index.internalPointer());
return static_cast<const Group*>(index.internalPointer());
return static_cast<Group*>(index.internalPointer());
}
void GroupModel::groupDataChanged(const Group* group)
void GroupModel::groupDataChanged(Group* group)
{
QModelIndex ix = index(group);
Q_EMIT dataChanged(ix, ix);
}
void GroupModel::groupAboutToRemove(const Group* group)
void GroupModel::groupAboutToRemove(Group* group)
{
Q_ASSERT(group->parentGroup());
@ -171,7 +166,7 @@ void GroupModel::groupRemoved()
endRemoveRows();
}
void GroupModel::groupAboutToAdd(const Group* group, int index)
void GroupModel::groupAboutToAdd(Group* group, int index)
{
Q_ASSERT(group->parentGroup());

View File

@ -28,9 +28,9 @@ class GroupModel : public QAbstractItemModel
Q_OBJECT
public:
explicit GroupModel(const Database* db, QObject* parent = 0);
QModelIndex index(const Group* group) const;
const Group* groupFromIndex(const QModelIndex& index) const;
explicit GroupModel(Database* db, QObject* parent = 0);
QModelIndex index(Group* group) const;
Group* groupFromIndex(const QModelIndex& index) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
@ -40,18 +40,17 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
private:
QModelIndex createIndex(int row, int column, const Group* group) const;
QModelIndex parent(const Group* group) const;
QModelIndex parent(Group* group) const;
private Q_SLOTS:
void groupDataChanged(const Group* group);
void groupAboutToRemove(const Group* group);
void groupDataChanged(Group* group);
void groupAboutToRemove(Group* group);
void groupRemoved();
void groupAboutToAdd(const Group* group, int index);
void groupAboutToAdd(Group* group, int index);
void groupAdded();
private:
const Group* m_root;
Group* m_root;
};
#endif // KEEPASSX_GROUPMODEL_H

View File

@ -31,16 +31,16 @@ GroupView::GroupView(Database* db, QWidget* parent) : QTreeView(parent)
void GroupView::expandedChanged(const QModelIndex& index)
{
Group* group = const_cast<Group*>(m_model->groupFromIndex(index));
Group* group = m_model->groupFromIndex(index);
group->setExpanded(isExpanded(index));
}
void GroupView::recInitExpanded(const Group* group)
void GroupView::recInitExpanded(Group* group)
{
QModelIndex index = m_model->index(group);
setExpanded(index, group->isExpanded());
Q_FOREACH (const Group* child, group->children()) {
Q_FOREACH (Group* child, group->children()) {
recInitExpanded(child);
}
}

View File

@ -34,9 +34,10 @@ public:
private Q_SLOTS:
void expandedChanged(const QModelIndex& index);
void emitGroupChanged(const QModelIndex& index);
private:
void recInitExpanded(const Group* group);
void recInitExpanded(Group* group);
GroupModel* m_model;
};

View File

@ -69,7 +69,7 @@ void TestGroup::testParenting()
QVERIFY(g1->children().at(1) == g3);
QVERIFY(g3->children().contains(g4));
QSignalSpy spy(db, SIGNAL(groupDataChanged(const Group*)));
QSignalSpy spy(db, SIGNAL(groupDataChanged(Group*)));
g2->setName("test");
g4->setName("test");
g3->setName("test");
@ -90,9 +90,9 @@ void TestGroup::testSignals()
g1->setParent(root);
g2->setParent(root);
QSignalSpy spyAboutToAdd(db, SIGNAL(groupAboutToAdd(const Group*,int)));
QSignalSpy spyAboutToAdd(db, SIGNAL(groupAboutToAdd(Group*,int)));
QSignalSpy spyAdded(db, SIGNAL(groupAdded()));
QSignalSpy spyAboutToRemove(db, SIGNAL(groupAboutToRemove(const Group*)));
QSignalSpy spyAboutToRemove(db, SIGNAL(groupAboutToRemove(Group*)));
QSignalSpy spyRemoved(db, SIGNAL(groupRemoved()));
g2->setParent(root, 0);