Merge pull request #1329 from adolfogc/refactor/database-widget

Refactor src/DatabaseWidget.cpp
This commit is contained in:
Janek Bevendorff 2018-01-09 12:59:32 +01:00 committed by GitHub
commit 92ab7bece2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -303,8 +303,9 @@ QList<int> DatabaseWidget::entryHeaderViewSizes() const
void DatabaseWidget::setEntryViewHeaderSizes(const QList<int>& sizes) void DatabaseWidget::setEntryViewHeaderSizes(const QList<int>& sizes)
{ {
if (sizes.size() != m_entryView->header()->count()) { const bool enoughSizes = sizes.size() == m_entryView->header()->count();
Q_ASSERT(false); Q_ASSERT(enoughSizes);
if (!enoughSizes) {
return; return;
} }
@ -332,8 +333,8 @@ Database* DatabaseWidget::database()
void DatabaseWidget::createEntry() void DatabaseWidget::createEntry()
{ {
Q_ASSERT(m_groupView->currentGroup());
if (!m_groupView->currentGroup()) { if (!m_groupView->currentGroup()) {
Q_ASSERT(false);
return; return;
} }
@ -375,33 +376,32 @@ void DatabaseWidget::replaceDatabase(Database* db)
void DatabaseWidget::cloneEntry() void DatabaseWidget::cloneEntry()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
CloneDialog* cloneDialog = new CloneDialog(this, m_db, currentEntry); auto cloneDialog = new CloneDialog(this, m_db, currentEntry);
cloneDialog->show(); cloneDialog->show();
return;
} }
void DatabaseWidget::showTotp() void DatabaseWidget::showTotp()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
TotpDialog* totpDialog = new TotpDialog(this, currentEntry); auto totpDialog = new TotpDialog(this, currentEntry);
totpDialog->open(); totpDialog->open();
} }
void DatabaseWidget::copyTotp() void DatabaseWidget::copyTotp()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
setClipboardTextAndMinimize(currentEntry->totp()); setClipboardTextAndMinimize(currentEntry->totp());
@ -410,12 +410,12 @@ void DatabaseWidget::copyTotp()
void DatabaseWidget::setupTotp() void DatabaseWidget::setupTotp()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
SetupTotpDialog* setupTotpDialog = new SetupTotpDialog(this, currentEntry); auto setupTotpDialog = new SetupTotpDialog(this, currentEntry);
if (currentEntry->hasTotp()) { if (currentEntry->hasTotp()) {
setupTotpDialog->setSeed(currentEntry->totpSeed()); setupTotpDialog->setSeed(currentEntry->totpSeed());
setupTotpDialog->setStep(currentEntry->totpStep()); setupTotpDialog->setStep(currentEntry->totpStep());
@ -425,7 +425,6 @@ void DatabaseWidget::setupTotp()
} }
setupTotpDialog->open(); setupTotpDialog->open();
} }
@ -433,8 +432,8 @@ void DatabaseWidget::deleteEntries()
{ {
const QModelIndexList selected = m_entryView->selectionModel()->selectedRows(); const QModelIndexList selected = m_entryView->selectionModel()->selectedRows();
Q_ASSERT(!selected.isEmpty());
if (selected.isEmpty()) { if (selected.isEmpty()) {
Q_ASSERT(false);
return; return;
} }
@ -505,8 +504,8 @@ void DatabaseWidget::setFocus()
void DatabaseWidget::copyTitle() void DatabaseWidget::copyTitle()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -516,8 +515,8 @@ void DatabaseWidget::copyTitle()
void DatabaseWidget::copyUsername() void DatabaseWidget::copyUsername()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -527,8 +526,8 @@ void DatabaseWidget::copyUsername()
void DatabaseWidget::copyPassword() void DatabaseWidget::copyPassword()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -538,8 +537,8 @@ void DatabaseWidget::copyPassword()
void DatabaseWidget::copyURL() void DatabaseWidget::copyURL()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -549,8 +548,8 @@ void DatabaseWidget::copyURL()
void DatabaseWidget::copyNotes() void DatabaseWidget::copyNotes()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -560,8 +559,8 @@ void DatabaseWidget::copyNotes()
void DatabaseWidget::copyAttribute(QAction* action) void DatabaseWidget::copyAttribute(QAction* action)
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -579,8 +578,8 @@ void DatabaseWidget::setClipboardTextAndMinimize(const QString& text)
void DatabaseWidget::performAutoType() void DatabaseWidget::performAutoType()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -590,8 +589,8 @@ void DatabaseWidget::performAutoType()
void DatabaseWidget::openUrl() void DatabaseWidget::openUrl()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return; return;
} }
@ -1348,8 +1347,8 @@ bool DatabaseWidget::isGroupSelected() const
bool DatabaseWidget::currentEntryHasTitle() bool DatabaseWidget::currentEntryHasTitle()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return false; return false;
} }
return !currentEntry->title().isEmpty(); return !currentEntry->title().isEmpty();
@ -1358,8 +1357,8 @@ bool DatabaseWidget::currentEntryHasTitle()
bool DatabaseWidget::currentEntryHasUsername() bool DatabaseWidget::currentEntryHasUsername()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return false; return false;
} }
return !currentEntry->resolveMultiplePlaceholders(currentEntry->username()).isEmpty(); return !currentEntry->resolveMultiplePlaceholders(currentEntry->username()).isEmpty();
@ -1368,8 +1367,8 @@ bool DatabaseWidget::currentEntryHasUsername()
bool DatabaseWidget::currentEntryHasPassword() bool DatabaseWidget::currentEntryHasPassword()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return false; return false;
} }
return !currentEntry->resolveMultiplePlaceholders(currentEntry->password()).isEmpty(); return !currentEntry->resolveMultiplePlaceholders(currentEntry->password()).isEmpty();
@ -1378,8 +1377,8 @@ bool DatabaseWidget::currentEntryHasPassword()
bool DatabaseWidget::currentEntryHasUrl() bool DatabaseWidget::currentEntryHasUrl()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return false; return false;
} }
return !currentEntry->resolveMultiplePlaceholders(currentEntry->url()).isEmpty(); return !currentEntry->resolveMultiplePlaceholders(currentEntry->url()).isEmpty();
@ -1389,8 +1388,8 @@ bool DatabaseWidget::currentEntryHasUrl()
bool DatabaseWidget::currentEntryHasTotp() bool DatabaseWidget::currentEntryHasTotp()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return false; return false;
} }
return currentEntry->hasTotp(); return currentEntry->hasTotp();
@ -1399,8 +1398,8 @@ bool DatabaseWidget::currentEntryHasTotp()
bool DatabaseWidget::currentEntryHasNotes() bool DatabaseWidget::currentEntryHasNotes()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) { if (!currentEntry) {
Q_ASSERT(false);
return false; return false;
} }
return !currentEntry->resolveMultiplePlaceholders(currentEntry->notes()).isEmpty(); return !currentEntry->resolveMultiplePlaceholders(currentEntry->notes()).isEmpty();