From b88a0d8de315aad6fc4c8e410988201ef989787a Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Mon, 14 May 2012 16:27:59 +0200 Subject: [PATCH] Coding style improvements. --- src/core/Entry.cpp | 68 +++++++++++++++--------------- src/core/EntryAttachments.h | 2 +- src/core/Tools.cpp | 2 +- src/gui/DatabaseSettingsWidget.cpp | 5 +-- src/gui/DatabaseSettingsWidget.h | 4 +- src/gui/DatabaseWidget.h | 4 +- src/gui/EntryModel.cpp | 2 +- src/gui/EntryModel.h | 8 ++-- src/gui/EntryView.cpp | 2 +- src/gui/EntryView.h | 2 +- src/gui/IconModels.cpp | 2 +- src/gui/IconModels.h | 2 +- 12 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 9c6352cdc..4dbdb3cc6 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -362,43 +362,45 @@ void Entry::addHistoryItem(Entry* entry) void Entry::truncateHistory() { const Database *db = database(); - if(db) { - int histMaxItems = db->metadata()->historyMaxItems(); - if (histMaxItems > -1) { - int historyCount = 0; - QMutableListIterator i(m_history); - i.toBack(); - while (i.hasPrevious()) { - historyCount++; - Entry* entry = i.previous(); - if (historyCount > histMaxItems) { - delete entry; - i.remove(); - } + + if (!db) { + return; + } + + int histMaxItems = db->metadata()->historyMaxItems(); + if (histMaxItems > -1) { + int historyCount = 0; + QMutableListIterator i(m_history); + i.toBack(); + while (i.hasPrevious()) { + historyCount++; + Entry* entry = i.previous(); + if (historyCount > histMaxItems) { + delete entry; + i.remove(); } } + } - int histMaxSize = db->metadata()->historyMaxSize(); - if (histMaxSize > -1) { - int size = 0; - QList* foundAttachements = new QList(); - attachments()->attachmentsSize(foundAttachements); + int histMaxSize = db->metadata()->historyMaxSize(); + if (histMaxSize > -1) { + int size = 0; + QList* foundAttachements = new QList(); + attachments()->attachmentsSize(foundAttachements); - QMutableListIterator i(m_history); - i.toBack(); - while (i.hasPrevious()) { - Entry* entry = i.previous(); - if (size > histMaxSize) { - delete entry; - i.remove(); - } - else { - size += entry->getSize(foundAttachements); - if (size > histMaxSize) { - delete entry; - i.remove(); - } - } + QMutableListIterator i(m_history); + i.toBack(); + while (i.hasPrevious()) { + Entry* entry = i.previous(); + + // don't calculate size if it's already above the maximum + if (size <= histMaxSize) { + size += entry->getSize(foundAttachements); + } + + if (size > histMaxSize) { + delete entry; + i.remove(); } } } diff --git a/src/core/EntryAttachments.h b/src/core/EntryAttachments.h index a4cfe3045..67e6a4231 100644 --- a/src/core/EntryAttachments.h +++ b/src/core/EntryAttachments.h @@ -32,7 +32,7 @@ public: void set(const QString& key, const QByteArray& value); void remove(const QString& key); void clear(); - int attachmentsSize(QList *foundAttachements); + int attachmentsSize(QList* foundAttachements); bool operator==(const EntryAttachments& other) const; bool operator!=(const EntryAttachments& other) const; EntryAttachments& operator=(EntryAttachments& other); diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index 33f2fee22..20d2c3128 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -92,7 +92,7 @@ bool readAllFromDevice(QIODevice* device, QByteArray& data) } } -QDateTime currentDateTimeUtc () +QDateTime currentDateTimeUtc() { #if QT_VERSION >= 0x040700 return QDateTime::currentDateTimeUtc(); diff --git a/src/gui/DatabaseSettingsWidget.cpp b/src/gui/DatabaseSettingsWidget.cpp index 4dcccd2d4..415370c9c 100644 --- a/src/gui/DatabaseSettingsWidget.cpp +++ b/src/gui/DatabaseSettingsWidget.cpp @@ -40,8 +40,8 @@ DatabaseSettingsWidget::~DatabaseSettingsWidget() { } -void DatabaseSettingsWidget::setForms(QString dbName, QString dbDescription, - QString defaultUsername, bool recylceBinEnabled, +void DatabaseSettingsWidget::setForms(const QString& dbName, const QString& dbDescription, + const QString& defaultUsername, bool recylceBinEnabled, int transformRounds, int historyMaxItems, int historyMaxSize) { @@ -162,7 +162,6 @@ void DatabaseSettingsWidget::toggleHistoryMaxSizeSpinBox(int state) else { m_ui->historyMaxSizeSpinBox->setEnabled(false); } - } void DatabaseSettingsWidget::transformRoundsBenchmark() diff --git a/src/gui/DatabaseSettingsWidget.h b/src/gui/DatabaseSettingsWidget.h index c84851084..398eb1b70 100644 --- a/src/gui/DatabaseSettingsWidget.h +++ b/src/gui/DatabaseSettingsWidget.h @@ -36,8 +36,8 @@ public: explicit DatabaseSettingsWidget(QWidget* parent = 0); ~DatabaseSettingsWidget(); - void setForms(QString dbName, QString dbDescription, - QString defaultUsername, bool recylceBinEnabled, + void setForms(const QString& dbName, const QString& dbDescription, + const QString& defaultUsername, bool recylceBinEnabled, int transformRounds, int historyMaxItems, int historyMaxSize); quint64 transformRounds(); diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index a303aa56f..e81b689c5 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -79,6 +79,8 @@ private Q_SLOTS: void emitCurrentModeChanged(); private: + void truncateHistories(); + Database* const m_db; QWidget* m_mainWidget; EditEntryWidget* m_editEntryWidget; @@ -91,8 +93,6 @@ private: Entry* m_newEntry; Group* m_newParent; QLineEdit* m_searchEdit; - - void truncateHistories(); }; #endif // KEEPASSX_DATABASEWIDGET_H diff --git a/src/gui/EntryModel.cpp b/src/gui/EntryModel.cpp index 7cd486480..6289a3485 100644 --- a/src/gui/EntryModel.cpp +++ b/src/gui/EntryModel.cpp @@ -61,7 +61,7 @@ void EntryModel::setGroup(Group* group) Q_EMIT switchedToView(); } -void EntryModel::setEntries(QList entries) +void EntryModel::setEntries(const QList& entries) { beginResetModel(); diff --git a/src/gui/EntryModel.h b/src/gui/EntryModel.h index 69bd3cc87..41d10b138 100644 --- a/src/gui/EntryModel.h +++ b/src/gui/EntryModel.h @@ -41,7 +41,7 @@ public: QStringList mimeTypes() const; QMimeData* mimeData(const QModelIndexList& indexes) const; - void setEntries(QList entries); + void setEntries(const QList& entries); Q_SIGNALS: void switchedToSearch(); @@ -58,12 +58,12 @@ private Q_SLOTS: void entryDataChanged(Entry* entry); private: + void severConnections(); + void makeConnections(const Group* group); + Group* m_group; QList m_entries; QList m_allGroups; - - void severConnections(); - void makeConnections(const Group* group); }; #endif // KEEPASSX_ENTRYMODEL_H diff --git a/src/gui/EntryView.cpp b/src/gui/EntryView.cpp index 784a8cce0..da1409f62 100644 --- a/src/gui/EntryView.cpp +++ b/src/gui/EntryView.cpp @@ -53,7 +53,7 @@ void EntryView::setGroup(Group* group) Q_EMIT entrySelectionChanged(); } -void EntryView::search(QList entries) +void EntryView::search(const QList& entries) { m_model->setEntries(entries); Q_EMIT entrySelectionChanged(); diff --git a/src/gui/EntryView.h b/src/gui/EntryView.h index bf7bab147..d1ac97cfa 100644 --- a/src/gui/EntryView.h +++ b/src/gui/EntryView.h @@ -36,7 +36,7 @@ public: bool isSingleEntrySelected(); void setCurrentEntry(Entry* entry); Entry* entryFromIndex(const QModelIndex& index); - void search(QList entries); + void search(const QList& entries); bool inSearch(); public Q_SLOTS: diff --git a/src/gui/IconModels.cpp b/src/gui/IconModels.cpp index da46101a4..80bcecfe3 100644 --- a/src/gui/IconModels.cpp +++ b/src/gui/IconModels.cpp @@ -54,7 +54,7 @@ CustomIconModel::CustomIconModel(QObject* parent) : { } -void CustomIconModel::setIcons(QHash icons, QList iconsOrder) +void CustomIconModel::setIcons(const QHash& icons, const QList& iconsOrder) { beginResetModel(); diff --git a/src/gui/IconModels.h b/src/gui/IconModels.h index 7bf903e9a..163569c66 100644 --- a/src/gui/IconModels.h +++ b/src/gui/IconModels.h @@ -43,7 +43,7 @@ public: virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; - void setIcons(QHash icons, QList iconsOrder); + void setIcons(const QHash& icons, const QList& iconsOrder); Uuid uuidFromIndex(const QModelIndex& index) const; QModelIndex indexFromUuid(const Uuid& uuid) const;