Add button to remove all history entries.

Refs #23
This commit is contained in:
Florian Geyer 2012-05-18 20:15:02 +02:00
parent 4797926be6
commit 8904869350
5 changed files with 48 additions and 1 deletions

View File

@ -103,6 +103,7 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
SLOT(updateHistoryButtons(QModelIndex, QModelIndex))); SLOT(updateHistoryButtons(QModelIndex, QModelIndex)));
connect(m_historyUi->showButton, SIGNAL(clicked()), SLOT(showHistoryEntry())); connect(m_historyUi->showButton, SIGNAL(clicked()), SLOT(showHistoryEntry()));
connect(m_historyUi->deleteButton, SIGNAL(clicked()), SLOT(deleteHistoryEntry())); connect(m_historyUi->deleteButton, SIGNAL(clicked()), SLOT(deleteHistoryEntry()));
connect(m_historyUi->deleteAllButton, SIGNAL(clicked()), SLOT(deleteAllHistoryEntries()));
connect(this, SIGNAL(accepted()), SLOT(saveEntry())); connect(this, SIGNAL(accepted()), SLOT(saveEntry()));
connect(this, SIGNAL(rejected()), SLOT(cancel())); connect(this, SIGNAL(rejected()), SLOT(cancel()));
@ -200,7 +201,7 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const Q
m_historyUi->showButton->setEnabled(false); m_historyUi->showButton->setEnabled(false);
m_historyUi->restoreButton->setEnabled(false); m_historyUi->restoreButton->setEnabled(false);
m_historyUi->deleteButton->setEnabled(false); m_historyUi->deleteButton->setEnabled(false);
m_historyUi->deleteAllButton->setEnabled(false);
setForms(entry); setForms(entry);
@ -240,6 +241,10 @@ void EditEntryWidget::setForms(const Entry* entry)
m_iconsWidget->load(entry->uuid(), m_database, iconStruct); m_iconsWidget->load(entry->uuid(), m_database, iconStruct);
if (!m_history) { if (!m_history) {
m_historyModel->setEntries(entry->historyItems()); m_historyModel->setEntries(entry->historyItems());
if (m_historyModel->rowCount() > 0) {
m_historyUi->deleteAllButton->setEnabled(true);
}
} }
} }
@ -532,5 +537,22 @@ void EditEntryWidget::deleteHistoryEntry()
QModelIndex index = m_historyUi->historyView->currentIndex(); QModelIndex index = m_historyUi->historyView->currentIndex();
if (index.isValid()) { if (index.isValid()) {
m_historyModel->deleteIndex(index); m_historyModel->deleteIndex(index);
if (m_historyModel->rowCount() > 0) {
m_historyUi->deleteAllButton->setEnabled(true);
}
else {
m_historyUi->deleteAllButton->setEnabled(false);
}
}
}
void EditEntryWidget::deleteAllHistoryEntries()
{
m_historyModel->deleteAll();
if (m_historyModel->rowCount() > 0) {
m_historyUi->deleteAllButton->setEnabled(true);
}
else {
m_historyUi->deleteAllButton->setEnabled(false);
} }
} }

View File

@ -73,6 +73,7 @@ private Q_SLOTS:
void removeCurrentAttachment(); void removeCurrentAttachment();
void showHistoryEntry(); void showHistoryEntry();
void deleteHistoryEntry(); void deleteHistoryEntry();
void deleteAllHistoryEntries();
void emitHistoryEntryActivated(const QModelIndex &index); void emitHistoryEntryActivated(const QModelIndex &index);
void updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous); void updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous);

View File

@ -49,6 +49,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="deleteAllButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Delete all</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -125,3 +125,16 @@ void EntryHistoryModel::deleteIndex(QModelIndex index)
endRemoveRows(); endRemoveRows();
} }
} }
void EntryHistoryModel::deleteAll()
{
Q_ASSERT(m_historyEntries.count() > 0);
beginRemoveRows(QModelIndex(), 0, m_historyEntries.size() - 1);
Q_FOREACH (Entry* entry, m_historyEntries) {
m_deletedHistoryEntries << entry;
}
m_historyEntries.clear();
endRemoveRows();
}

View File

@ -39,6 +39,7 @@ public:
void clear(); void clear();
QList<Entry*> deletedEntries(); QList<Entry*> deletedEntries();
void deleteIndex(QModelIndex index); void deleteIndex(QModelIndex index);
void deleteAll();
private: private:
QList<Entry*> m_historyEntries; QList<Entry*> m_historyEntries;