Make the edit entry button work.

This commit is contained in:
Felix Geyer 2011-12-29 19:01:58 +01:00
parent e11b0061d4
commit 73b84ff670
6 changed files with 46 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include "format/KeePass2XmlReader.h"
#include "gui/DatabaseWidget.h"
#include "gui/FileDialog.h"
#include "gui/EntryView.h"
#include "gui/GroupView.h"
#include "gui/KeyOpenDialog.h"
@ -41,6 +42,7 @@ DatabaseManager::DatabaseManager(QTabWidget* tabWidget)
, m_window(tabWidget->window())
{
connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int)));
connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged()));
}
void DatabaseManager::newDatabase()
@ -119,6 +121,18 @@ void DatabaseManager::openDatabaseCleanup()
m_curDbStruct = DatabaseManagerStruct();
}
void DatabaseManager::emitEntrySelectionChanged()
{
Database* db = indexDatabase(m_tabWidget->currentIndex());
bool isSingleEntrySelected = false;
if (db) {
isSingleEntrySelected = m_dbList[db].dbWidget->entryView()->isSingleEntrySelected();
}
Q_EMIT entrySelectionChanged(isSingleEntrySelected);
}
void DatabaseManager::closeDatabase(Database* db)
{
Q_ASSERT(db);
@ -216,6 +230,13 @@ void DatabaseManager::createEntry()
dbWidget->createEntry();
}
void DatabaseManager::editEntry()
{
Database* db = indexDatabase(m_tabWidget->currentIndex());
DatabaseWidget* dbWidget = m_dbList[db].dbWidget;
dbWidget->switchToEntryEdit();
}
void DatabaseManager::createGroup()
{
Database* db = indexDatabase(m_tabWidget->currentIndex());
@ -294,4 +315,5 @@ void DatabaseManager::insertDatabase(Database* db, const DatabaseManagerStruct&
m_tabWidget->setCurrentIndex(index);
connect(db->metadata(), SIGNAL(nameTextChanged(Database*)), SLOT(updateTabName(Database*)));
connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged()));
}

View File

@ -58,6 +58,7 @@ public Q_SLOTS:
void saveDatabaseAs(int index = -1);
void closeDatabase(int index = -1);
void createEntry();
void editEntry();
void createGroup();
void editGroup();
@ -66,6 +67,10 @@ private Q_SLOTS:
void openDatabaseDialog();
void openDatabaseRead();
void openDatabaseCleanup();
void emitEntrySelectionChanged();
Q_SIGNALS:
void entrySelectionChanged(bool singleEntrySelected);
private:
int databaseIndex(Database* db);

View File

@ -140,7 +140,7 @@ void DatabaseWidget::switchToGroupEdit(Group* group, bool create)
}
void DatabaseWidget::switchToEntryEdit()
{
// TODO switchToEntryEdit(m_entryView->currentEntry(), false);
switchToEntryEdit(m_entryView->currentEntry(), false);
}
void DatabaseWidget::switchToGroupEdit()

View File

@ -29,6 +29,7 @@ EntryView::EntryView(QWidget* parent)
setRootIsDecorated(false);
connect(this, SIGNAL(activated(const QModelIndex&)), SLOT(emitEntryActivated(const QModelIndex&)));
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged()));
}
void EntryView::setGroup(Group* group)
@ -46,3 +47,14 @@ void EntryView::setModel(QAbstractItemModel* model)
Q_UNUSED(model);
Q_ASSERT(false);
}
Entry* EntryView::currentEntry()
{
// TODO use selection instead of current?
return m_model->entryFromIndex(currentIndex());
}
bool EntryView::isSingleEntrySelected()
{
return (selectionModel()->selectedRows().size() == 1);
}

View File

@ -31,6 +31,8 @@ class EntryView : public QTreeView
public:
explicit EntryView(QWidget* parent = 0);
void setModel(QAbstractItemModel* model);
Entry* currentEntry();
bool isSingleEntrySelected();
public Q_SLOTS:
void setGroup(Group* group);
@ -40,6 +42,7 @@ private Q_SLOTS:
Q_SIGNALS:
void entryActivated(Entry* entry);
void entrySelectionChanged();
private:
EntryModel* m_model;

View File

@ -31,6 +31,8 @@ MainWindow::MainWindow()
m_dbManager = new DatabaseManager(m_ui->tabWidget);
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(currentTabChanged(int)));
connect(m_dbManager, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryEdit, SLOT(setEnabled(bool)));
connect(m_dbManager, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryDelete, SLOT(setEnabled(bool)));
connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_dbManager, SLOT(newDatabase()));
connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_dbManager, SLOT(openDatabase()));
@ -38,6 +40,7 @@ MainWindow::MainWindow()
connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabaseAs()));
connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_dbManager, SLOT(closeDatabase()));
connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_dbManager, SLOT(createEntry()));
connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_dbManager, SLOT(editEntry()));
connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_dbManager, SLOT(createGroup()));
connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_dbManager, SLOT(editGroup()));
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));