Select newly created entries.

This commit is contained in:
Florian Geyer 2012-05-02 19:33:37 +02:00
parent 8122ab2b2c
commit 09248fdb14
5 changed files with 16 additions and 0 deletions

View File

@ -223,6 +223,8 @@ void DatabaseWidget::switchToView(bool accepted)
else if (m_newEntry) {
if (accepted) {
m_newEntry->setGroup(m_newParent);
m_entryView->setFocus();
m_entryView->setCurrentEntry(m_newEntry);
}
else {
delete m_newEntry;

View File

@ -35,6 +35,13 @@ Entry* EntryModel::entryFromIndex(const QModelIndex& index) const
return m_group->entries().at(index.row());
}
QModelIndex EntryModel::indexFromEntry(Entry* entry) const
{
int row = m_group->entries().indexOf(entry);
Q_ASSERT(row != -1);
return index(row, 0);
}
void EntryModel::setGroup(Group* group)
{
beginResetModel();

View File

@ -30,6 +30,7 @@ class EntryModel : public QAbstractTableModel
public:
explicit EntryModel(QObject* parent = 0);
Entry* entryFromIndex(const QModelIndex& index) const;
QModelIndex indexFromEntry(Entry* entry) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;

View File

@ -60,3 +60,8 @@ bool EntryView::isSingleEntrySelected()
{
return (selectionModel()->selectedRows().size() == 1);
}
void EntryView::setCurrentEntry(Entry* entry)
{
setCurrentIndex(m_model->indexFromEntry(entry));
}

View File

@ -33,6 +33,7 @@ public:
void setModel(QAbstractItemModel* model);
Entry* currentEntry();
bool isSingleEntrySelected();
void setCurrentEntry(Entry* entry);
public Q_SLOTS:
void setGroup(Group* group);