From 24158bb032df1ceda1c6cdd87e5d4d29cce4681a Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 19 Sep 2010 19:45:14 +0200 Subject: Add signal EntryView::entryActivated(). --- src/gui/EntryModel.cpp | 8 +++++++- src/gui/EntryModel.h | 2 ++ src/gui/EntryView.cpp | 5 +++++ src/gui/EntryView.h | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/EntryModel.cpp b/src/gui/EntryModel.cpp index c7009cc91..ae0f67bfc 100644 --- a/src/gui/EntryModel.cpp +++ b/src/gui/EntryModel.cpp @@ -26,6 +26,12 @@ EntryModel::EntryModel(QObject* parent) { } +Entry* EntryModel::entryFromIndex(const QModelIndex& index) const +{ + Q_ASSERT(index.isValid() && index.row() < m_group->entries().size()); + return m_group->entries().at(index.row()); +} + void EntryModel::setGroup(Group* group) { beginResetModel(); @@ -66,7 +72,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const return QVariant(); } - Entry* entry = m_group->entries().at(index.row()); + Entry* entry = entryFromIndex(index); // TODO implement other columns if (role == Qt::DisplayRole) { diff --git a/src/gui/EntryModel.h b/src/gui/EntryModel.h index 2905b987d..b65e533a1 100644 --- a/src/gui/EntryModel.h +++ b/src/gui/EntryModel.h @@ -29,6 +29,8 @@ class EntryModel : public QAbstractTableModel public: explicit EntryModel(QObject* parent = 0); + Entry* entryFromIndex(const QModelIndex& index) const; + int rowCount(const QModelIndex& parent = QModelIndex()) const; int columnCount(const QModelIndex& parent = QModelIndex()) const; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; diff --git a/src/gui/EntryView.cpp b/src/gui/EntryView.cpp index 141aca700..ac3130f27 100644 --- a/src/gui/EntryView.cpp +++ b/src/gui/EntryView.cpp @@ -34,6 +34,11 @@ void EntryView::setGroup(Group* group) m_model->setGroup(group); } +void EntryView::emitEntryActivated(const QModelIndex& index) +{ + Q_EMIT entryActivated(m_model->entryFromIndex(index)); +} + void EntryView::setModel(QAbstractItemModel* model) { Q_UNUSED(model); diff --git a/src/gui/EntryView.h b/src/gui/EntryView.h index 28baae842..a7d27495f 100644 --- a/src/gui/EntryView.h +++ b/src/gui/EntryView.h @@ -20,6 +20,7 @@ #include +class Entry; class EntryModel; class Group; @@ -34,6 +35,12 @@ public: public Q_SLOTS: void setGroup(Group* group); +private Q_SLOTS: + void emitEntryActivated(const QModelIndex& index); + +Q_SIGNALS: + void entryActivated(Entry* entry); + private: EntryModel* m_model; }; -- cgit v1.2.3