diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95d88c815..d65755068 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,9 @@ set(keepassx_SOURCES core/TimeInfo.cpp core/Uuid.cpp core/Writer.cpp + gui/DatabaseWidget.cpp gui/EntryModel.cpp + gui/EntryView.cpp gui/GroupModel.cpp gui/GroupView.cpp ) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp new file mode 100644 index 000000000..be432f105 --- /dev/null +++ b/src/gui/DatabaseWidget.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 Felix Geyer + * + * 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 . + */ + +#include "DatabaseWidget.h" + +#include + +#include "EntryView.h" +#include "GroupView.h" + +DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) + : QWidget(parent) +{ + m_groupView = new GroupView(db); + m_entryView = new EntryView(); + + connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*))); + + QHBoxLayout* layout = new QHBoxLayout(); + layout->addWidget(m_groupView); + layout->addWidget(m_entryView); + setLayout(layout); +} diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h new file mode 100644 index 000000000..2aa76a496 --- /dev/null +++ b/src/gui/DatabaseWidget.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2010 Felix Geyer + * + * 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 . + */ + +#ifndef KEEPASSX_DATABASEWIDGET_H +#define KEEPASSX_DATABASEWIDGET_H + +#include + +class Database; +class EntryView; +class GroupView; + +class DatabaseWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DatabaseWidget(Database* db, QWidget* parent = 0); + +private: + GroupView* m_groupView; + EntryView* m_entryView; +}; + +#endif // KEEPASSX_DATABASEWIDGET_H diff --git a/src/gui/EntryView.cpp b/src/gui/EntryView.cpp new file mode 100644 index 000000000..3cc1addea --- /dev/null +++ b/src/gui/EntryView.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010 Felix Geyer + * + * 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 . + */ + +#include "EntryView.h" + +#include "EntryModel.h" + +EntryView::EntryView(QWidget* parent) + : QTreeView(parent) +{ + m_model = new EntryModel(this); + QTreeView::setModel(m_model); +} + +void EntryView::setGroup(Group* group) +{ + m_model->setGroup(group); +} + +void EntryView::setModel(QAbstractItemModel* model) +{ + Q_UNUSED(model); + Q_ASSERT(false); +} diff --git a/src/gui/EntryView.h b/src/gui/EntryView.h new file mode 100644 index 000000000..28baae842 --- /dev/null +++ b/src/gui/EntryView.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2010 Felix Geyer + * + * 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 . + */ + +#ifndef KEEPASSX_ENTRYVIEW_H +#define KEEPASSX_ENTRYVIEW_H + +#include + +class EntryModel; +class Group; + +class EntryView : public QTreeView +{ + Q_OBJECT + +public: + explicit EntryView(QWidget* parent = 0); + void setModel(QAbstractItemModel* model); + +public Q_SLOTS: + void setGroup(Group* group); + +private: + EntryModel* m_model; +}; + +#endif // KEEPASSX_ENTRYVIEW_H diff --git a/src/gui/GroupView.cpp b/src/gui/GroupView.cpp index 01e26694d..d0f39877b 100644 --- a/src/gui/GroupView.cpp +++ b/src/gui/GroupView.cpp @@ -27,6 +27,8 @@ GroupView::GroupView(Database* db, QWidget* parent) : QTreeView(parent) QTreeView::setModel(m_model); recInitExpanded(db->rootGroup()); setHeaderHidden(true); + + connect(this, SIGNAL(clicked(const QModelIndex&)), SLOT(emitGroupChanged(const QModelIndex&))); } void GroupView::expandedChanged(const QModelIndex& index) @@ -45,6 +47,11 @@ void GroupView::recInitExpanded(Group* group) } } +void GroupView::emitGroupChanged(const QModelIndex& index) +{ + Q_EMIT groupChanged(m_model->groupFromIndex(index)); +} + void GroupView::setModel(QAbstractItemModel* model) { Q_UNUSED(model); diff --git a/src/gui/GroupView.h b/src/gui/GroupView.h index 80faab08e..dba703731 100644 --- a/src/gui/GroupView.h +++ b/src/gui/GroupView.h @@ -32,6 +32,9 @@ public: GroupView(Database* db, QWidget* parent = 0); void setModel(QAbstractItemModel* model); +Q_SIGNALS: + void groupChanged(Group* group); + private Q_SLOTS: void expandedChanged(const QModelIndex& index); void emitGroupChanged(const QModelIndex& index); diff --git a/src/main.cpp b/src/main.cpp index f5d7c9ff1..f00b28d14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ #include "core/Database.h" #include "core/Parser.h" -#include "gui/GroupModel.h" +#include "gui/DatabaseWidget.h" #include "../tests/config-keepassx-tests.h" @@ -32,12 +32,8 @@ int main(int argc, char **argv) Parser* parser = new Parser(db); parser->parse(QString(KEEPASSX_TEST_DIR).append("/NewDatabase.xml")); - GroupModel groupModel(db); + DatabaseWidget dbWidget(db); + dbWidget.show(); - QTreeView view; - view.setModel(&groupModel); - view.setHeaderHidden(true); - view.expandAll(); - view.show(); return app.exec(); }