Apply clang format on all GUI files

This commit is contained in:
Martchus 2018-03-14 00:17:14 +01:00
parent 836e6bbcb2
commit 575d0cabdb
5 changed files with 220 additions and 241 deletions

View File

@ -432,15 +432,15 @@ bool MainWindow::openFile(const QString &path, bool readOnly)
} }
// show error message // show error message
const QString errmsg const QString errmsg = tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(ioError));
= tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(ioError));
m_ui->statusBar->showMessage(errmsg, 5000); m_ui->statusBar->showMessage(errmsg, 5000);
QMessageBox::critical(this, QApplication::applicationName(), errmsg); QMessageBox::critical(this, QApplication::applicationName(), errmsg);
return false; return false;
} }
// warn before loading a very big file // warn before loading a very big file
if (m_file.size() > 10485760 && QMessageBox::warning(this, QApplication::applicationName(), if (m_file.size() > 10485760
&& QMessageBox::warning(this, QApplication::applicationName(),
tr("The file you want to load seems to be very big. Do you really want to open it?"), QMessageBox::Yes, QMessageBox::No) tr("The file you want to load seems to be very big. Do you really want to open it?"), QMessageBox::Yes, QMessageBox::No)
== QMessageBox::No) { == QMessageBox::No) {
m_file.clear(); m_file.clear();
@ -942,8 +942,8 @@ void MainWindow::addEntry(EntryType type)
return; return;
} }
bool result; bool result;
const QString text = QInputDialog::getText(this, type == EntryType::Account ? tr("Add account") : tr("Add category"), const QString text = QInputDialog::getText(this, type == EntryType::Account ? tr("Add account") : tr("Add category"), tr("Enter the entry name"),
tr("Enter the entry name"), QLineEdit::Normal, tr("new entry"), &result); QLineEdit::Normal, tr("new entry"), &result);
if (!result) { if (!result) {
return; return;
} }

View File

@ -5,8 +5,8 @@
#include <QDialog> #include <QDialog>
#include <vector>
#include <memory> #include <memory>
#include <vector>
namespace QtGui { namespace QtGui {

View File

@ -13,9 +13,10 @@ namespace QtGui {
/*! /*!
* \brief Constructs a new filter entry model. * \brief Constructs a new filter entry model.
*/ */
EntryFilterModel::EntryFilterModel(QObject *parent) : EntryFilterModel::EntryFilterModel(QObject *parent)
QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
{} {
}
bool EntryFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const bool EntryFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{ {
@ -43,4 +44,4 @@ bool EntryFilterModel::hasAcceptedChildren(const QModelIndex &index) const
return false; return false;
} }
} } // namespace QtGui

View File

@ -8,10 +8,10 @@
#include <c++utilities/io/catchiofailure.h> #include <c++utilities/io/catchiofailure.h>
#include <QIcon>
#include <QBuffer> #include <QBuffer>
#include <QMimeData>
#include <QDebug> #include <QDebug>
#include <QIcon>
#include <QMimeData>
#include <sstream> #include <sstream>
@ -32,11 +32,12 @@ namespace QtGui {
/*! /*!
* \brief Constructs a new entry model. * \brief Constructs a new entry model.
*/ */
EntryModel::EntryModel(QObject *parent) : EntryModel::EntryModel(QObject *parent)
QAbstractItemModel(parent), : QAbstractItemModel(parent)
m_rootEntry(nullptr), , m_rootEntry(nullptr)
m_insertType(EntryType::Node) , m_insertType(EntryType::Node)
{} {
}
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
/*! /*!
@ -44,12 +45,13 @@ EntryModel::EntryModel(QObject *parent) :
* *
* This constructor is only available when PASSWORD_MANAGER_GUI_QTWIDGETS is defined. * This constructor is only available when PASSWORD_MANAGER_GUI_QTWIDGETS is defined.
*/ */
EntryModel::EntryModel(QUndoStack *undoStack, QObject *parent) : EntryModel::EntryModel(QUndoStack *undoStack, QObject *parent)
QAbstractItemModel(parent), : QAbstractItemModel(parent)
StackSupport(undoStack), , StackSupport(undoStack)
m_rootEntry(nullptr), , m_rootEntry(nullptr)
m_insertType(EntryType::Node) , m_insertType(EntryType::Node)
{} {
}
#endif #endif
/*! /*!
@ -144,8 +146,8 @@ QModelIndex EntryModel::index(int row, int column, const QModelIndex &parent) co
return createIndex(row, column, children[static_cast<size_t>(row)]); return createIndex(row, column, children[static_cast<size_t>(row)]);
} }
break; break;
} case EntryType::Account: }
; case EntryType::Account:;
} }
return QModelIndex(); return QModelIndex();
} }
@ -216,8 +218,7 @@ QVariant EntryModel::data(const QModelIndex &index, int role) const
switch (index.column()) { switch (index.column()) {
case 0: case 0:
return QString::fromStdString(entry->label()); return QString::fromStdString(entry->label());
default: default:;
;
} }
break; break;
case Qt::DecorationRole: case Qt::DecorationRole:
@ -237,12 +238,10 @@ QVariant EntryModel::data(const QModelIndex &index, int role) const
IoUtilities::catchIoFailure(); IoUtilities::catchIoFailure();
return false; return false;
} }
} } break;
break;
case DefaultExpandedRole: case DefaultExpandedRole:
return entry->type() == EntryType::Node && static_cast<const NodeEntry *>(entry)->isExpandedByDefault(); return entry->type() == EntryType::Node && static_cast<const NodeEntry *>(entry)->isExpandedByDefault();
default: default:;
;
} }
return QVariant(); return QVariant();
} }
@ -277,8 +276,7 @@ bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int ro
entry->setLabel(value.toString().toStdString()); entry->setLabel(value.toString().toStdString());
emit dataChanged(index, index, QVector<int>() << role); emit dataChanged(index, index, QVector<int>() << role);
return true; return true;
default: default:;
;
} }
break; break;
case SerializedRole: { case SerializedRole: {
@ -307,8 +305,7 @@ bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int ro
} catch (...) { } catch (...) {
IoUtilities::catchIoFailure(); IoUtilities::catchIoFailure();
} }
} } break;
break;
case DefaultExpandedRole: case DefaultExpandedRole:
switch (entry->type()) { switch (entry->type()) {
case EntryType::Account: case EntryType::Account:
@ -319,8 +316,7 @@ bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int ro
return true; return true;
} }
break; break;
default: default:;
;
} }
return false; return false;
} }
@ -335,8 +331,7 @@ bool EntryModel::setItemData(const QModelIndex &index, const QMap<int, QVariant>
Qt::ItemFlags EntryModel::flags(const QModelIndex &index) const Qt::ItemFlags EntryModel::flags(const QModelIndex &index) const
{ {
return isNode(index) return isNode(index) ? QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled
? QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled
: QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled; : QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
} }
@ -349,16 +344,13 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
switch (section) { switch (section) {
case 0: case 0:
return tr("Name"); return tr("Name");
default: default:;
;
} }
break; break;
default: default:;
;
} }
break; break;
default: default:;
;
} }
return QVariant(); return QVariant();
} }
@ -370,8 +362,7 @@ int EntryModel::rowCount(const QModelIndex &parent) const
switch (parentEntry->type()) { switch (parentEntry->type()) {
case EntryType::Node: case EntryType::Node:
return static_cast<NodeEntry *>(parentEntry)->children().size(); return static_cast<NodeEntry *>(parentEntry)->children().size();
case EntryType::Account: case EntryType::Account:;
;
} }
} }
} else if (m_rootEntry) { } else if (m_rootEntry) {
@ -446,8 +437,7 @@ bool EntryModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co
} }
#endif #endif
// check validation of specified arguments // check validation of specified arguments
if(!sourceParent.isValid() || !destinationParent.isValid() if (!sourceParent.isValid() || !destinationParent.isValid() || sourceRow < 0 || count <= 0
|| sourceRow < 0 || count <= 0
|| entry(sourceParent)->type() != EntryType::Node // source and destination parent entries || entry(sourceParent)->type() != EntryType::Node // source and destination parent entries
|| entry(destinationParent)->type() != EntryType::Node) { // need to be node entries || entry(destinationParent)->type() != EntryType::Node) { // need to be node entries
return false; return false;
@ -568,4 +558,4 @@ Qt::DropActions EntryModel::supportedDropActions() const
return Qt::MoveAction; return Qt::MoveAction;
} }
} } // namespace QtGui

View File

@ -26,12 +26,13 @@ namespace QtGui {
/*! /*!
* \brief Constructs a new field model. * \brief Constructs a new field model.
*/ */
FieldModel::FieldModel(QObject *parent) : FieldModel::FieldModel(QObject *parent)
QAbstractTableModel(parent), : QAbstractTableModel(parent)
m_accountEntry(nullptr), , m_accountEntry(nullptr)
m_fields(nullptr), , m_fields(nullptr)
m_passwordVisibility(PasswordVisibility::OnlyWhenEditing) , m_passwordVisibility(PasswordVisibility::OnlyWhenEditing)
{} {
}
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
/*! /*!
@ -39,12 +40,13 @@ FieldModel::FieldModel(QObject *parent) :
* *
* This constructor is only available when PASSWORD_MANAGER_GUI_QTWIDGETS is defined. * This constructor is only available when PASSWORD_MANAGER_GUI_QTWIDGETS is defined.
*/ */
FieldModel::FieldModel(QUndoStack *undoStack, QObject *parent) : FieldModel::FieldModel(QUndoStack *undoStack, QObject *parent)
QAbstractTableModel(parent), : QAbstractTableModel(parent)
StackSupport(undoStack), , StackSupport(undoStack)
m_accountEntry(nullptr), , m_accountEntry(nullptr)
m_fields(nullptr) , m_fields(nullptr)
{} {
}
#endif #endif
/*! /*!
@ -81,19 +83,16 @@ QVariant FieldModel::data(const QModelIndex &index, int role) const
case 0: case 0:
return QString::fromStdString((*m_fields)[static_cast<size_t>(index.row())].name()); return QString::fromStdString((*m_fields)[static_cast<size_t>(index.row())].name());
case 1: case 1:
return (m_passwordVisibility == PasswordVisibility::Always return (m_passwordVisibility == PasswordVisibility::Always || role == Qt::EditRole
|| role == Qt::EditRole
|| (*m_fields)[static_cast<size_t>(index.row())].type() != FieldType::Password) || (*m_fields)[static_cast<size_t>(index.row())].type() != FieldType::Password)
? QString::fromStdString((*m_fields)[static_cast<size_t>(index.row())].value()) ? QString::fromStdString((*m_fields)[static_cast<size_t>(index.row())].value())
: QString((*m_fields)[static_cast<size_t>(index.row())].value().size(), QChar(0x2022)); : QString((*m_fields)[static_cast<size_t>(index.row())].value().size(), QChar(0x2022));
default: default:;
;
} }
break; break;
case FieldTypeRole: case FieldTypeRole:
return static_cast<int>((*m_fields)[static_cast<size_t>(index.row())].type()); return static_cast<int>((*m_fields)[static_cast<size_t>(index.row())].type());
default: default:;
;
} }
// return data for empty field at the end which enables the user to append fields // return data for empty field at the end which enables the user to append fields
} else if (static_cast<size_t>(index.row()) == m_fields->size()) { } else if (static_cast<size_t>(index.row()) == m_fields->size()) {
@ -105,12 +104,10 @@ QVariant FieldModel::data(const QModelIndex &index, int role) const
return QString(); return QString();
case 1: case 1:
return QString(); return QString();
default: default:;
;
} }
break; break;
default: default:;
;
} }
} }
return QVariant(); return QVariant();
@ -155,8 +152,7 @@ bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int ro
m_fields->at(index.row()).setValue(value.toString().toStdString()); m_fields->at(index.row()).setValue(value.toString().toStdString());
roles << role; roles << role;
break; break;
default: default:;
;
} }
break; break;
case FieldTypeRole: { case FieldTypeRole: {
@ -167,8 +163,8 @@ bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int ro
m_fields->at(index.row()).setType(static_cast<FieldType>(fieldType)); m_fields->at(index.row()).setType(static_cast<FieldType>(fieldType));
} }
break; break;
} default: }
; default:;
} }
// remove last field if empty, showing an empty field at the end to enabled appending new rows is provided by the data method // remove last field if empty, showing an empty field at the end to enabled appending new rows is provided by the data method
if (!roles.isEmpty() && static_cast<size_t>(index.row()) == m_fields->size() - 1 && m_fields->at(index.row()).isEmpty()) { if (!roles.isEmpty() && static_cast<size_t>(index.row()) == m_fields->size() - 1 && m_fields->at(index.row()).isEmpty()) {
@ -196,12 +192,10 @@ bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int ro
endInsertRows(); endInsertRows();
roles << role; roles << role;
break; break;
default: default:;
;
} }
break; break;
default: default:;
;
} }
} }
// return false if nothing could be changed // return false if nothing could be changed
@ -216,8 +210,7 @@ bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int ro
case FieldTypeRole: case FieldTypeRole:
roles << Qt::DisplayRole << Qt::EditRole; roles << Qt::DisplayRole << Qt::EditRole;
break; break;
default: default:;
;
} }
// emit data changed signal on sucess // emit data changed signal on sucess
emit dataChanged(index, index, roles); emit dataChanged(index, index, roles);
@ -240,16 +233,13 @@ QVariant FieldModel::headerData(int section, Qt::Orientation orientation, int ro
return tr("Name"); return tr("Name");
case 1: case 1:
return tr("Value"); return tr("Value");
default: default:;
;
} }
break; break;
default: default:;
;
} }
break; break;
default: default:;
;
} }
return QVariant(); return QVariant();
} }
@ -335,6 +325,4 @@ const Field *FieldModel::field(size_t row) const
return nullptr; return nullptr;
} }
} } // namespace QtGui