diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2018-10-12 16:03:22 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2018-10-12 16:03:22 +0200 |
commit | 69512ff6f286371d2846b84a809bbfbc9a7e7289 (patch) | |
tree | 91f6c2db783c1731ba8232eeb3a27c3a7f885d3a /src | |
parent | 6315d1e9371864f0ed6b3854a4b50561b062befe (diff) |
Some cleanup with help of Clang-Tidy and Clazy (part 2 of x)
Diffstat (limited to 'src')
-rw-r--r-- | src/filecontent.cpp | 2 | ||||
-rw-r--r-- | src/imitatepass.cpp | 2 | ||||
-rw-r--r-- | src/keygendialog.cpp | 4 | ||||
-rw-r--r-- | src/mainwindow.cpp | 10 | ||||
-rw-r--r-- | src/pass.cpp | 2 | ||||
-rw-r--r-- | src/passworddialog.cpp | 6 | ||||
-rw-r--r-- | src/qprogressindicator.cpp | 6 | ||||
-rw-r--r-- | src/realpass.cpp | 2 | ||||
-rw-r--r-- | src/settingsconstants.cpp | 2 | ||||
-rw-r--r-- | src/storemodel.cpp | 12 | ||||
-rw-r--r-- | src/trayicon.cpp | 6 | ||||
-rw-r--r-- | src/usersdialog.cpp | 22 |
12 files changed, 37 insertions, 39 deletions
diff --git a/src/filecontent.cpp b/src/filecontent.cpp index 0e22a377..d77983c2 100644 --- a/src/filecontent.cpp +++ b/src/filecontent.cpp @@ -7,7 +7,7 @@ FileContent FileContent::parse(const QString &fileContent, QString password = lines.takeFirst(); QStringList remainingData; NamedValues namedValues; - for (QString line : lines) { + for (const QString &line : lines) { if (line.contains(":")) { int colon = line.indexOf(':'); QString name = line.left(colon); diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index f1c84e40..7998bf0f 100644 --- a/src/imitatepass.cpp +++ b/src/imitatepass.cpp @@ -12,7 +12,7 @@ using namespace Enums; * @brief ImitatePass::ImitatePass for situaions when pass is not available * we imitate the behavior of pass https://www.passwordstore.org/ */ -ImitatePass::ImitatePass() {} +ImitatePass::ImitatePass() = default; /** * @brief ImitatePass::GitInit git init wrapper diff --git a/src/keygendialog.cpp b/src/keygendialog.cpp index 62fcffda..c626c58f 100644 --- a/src/keygendialog.cpp +++ b/src/keygendialog.cpp @@ -132,7 +132,7 @@ void KeygenDialog::done(int r) { } // check email - QRegExp mailre("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b"); + QRegExp mailre(R"(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)"); mailre.setCaseSensitivity(Qt::CaseInsensitive); mailre.setPatternSyntax(QRegExp::RegExp); if (!mailre.exactMatch(ui->email->text())) { @@ -147,7 +147,7 @@ void KeygenDialog::done(int r) { ui->checkBox->setEnabled(false); ui->plainTextEdit->setEnabled(false); - QProgressIndicator *pi = new QProgressIndicator(); + auto *pi = new QProgressIndicator(); pi->startAnimation(); pi->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c92f74dc..f5d3c915 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -830,7 +830,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { */ bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == ui->lineEdit && event->type() == QEvent::KeyPress) { - QKeyEvent *key = static_cast<QKeyEvent *>(event); + auto *key = dynamic_cast<QKeyEvent *>(event); if (key->key() == Qt::Key_Down) { ui->treeView->setFocus(); } @@ -1016,7 +1016,7 @@ void MainWindow::addToGridLayout(int position, const QString &field, ly->setContentsMargins(5, 2, 2, 2); frame->setLayout(ly); if (QtPassSettings::getClipBoardType() != Enums::CLIPBOARD_NEVER) { - QPushButtonWithClipboard *fieldLabel = + auto *fieldLabel = new QPushButtonWithClipboard(trimmedValue, this); connect(fieldLabel, &QPushButtonWithClipboard::clicked, m_qtPass, &QtPass::copyTextToClipboard); @@ -1028,7 +1028,7 @@ void MainWindow::addToGridLayout(int position, const QString &field, // set the echo mode to password, if the field is "password" if (QtPassSettings::isHidePassword() && trimmedField == tr("Password")) { - QLineEdit *line = new QLineEdit(); + auto *line = new QLineEdit(); line->setObjectName(trimmedField); line->setText(trimmedValue); line->setReadOnly(true); @@ -1037,7 +1037,7 @@ void MainWindow::addToGridLayout(int position, const QString &field, line->setEchoMode(QLineEdit::Password); frame->layout()->addWidget(line); } else { - QTextBrowser *line = new QTextBrowser(); + auto *line = new QTextBrowser(); line->setOpenExternalLinks(true); line->setOpenLinks(true); line->setMaximumHeight(26); @@ -1047,7 +1047,7 @@ void MainWindow::addToGridLayout(int position, const QString &field, line->setObjectName(trimmedField); trimmedValue.replace( QRegExp("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"), - "<a href=\"\\1\">\\1</a>"); + R"(<a href="\1">\1</a>)"); line->setText(trimmedValue); line->setReadOnly(true); line->setStyleSheet("border-style: none ; background: transparent;"); diff --git a/src/pass.cpp b/src/pass.cpp index 788b868b..70fee7a6 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -184,7 +184,7 @@ QList<UserInfo> Pass::listKeys(QString keystring, bool secret) { */ void Pass::finished(int id, int exitCode, const QString &out, const QString &err) { - PROCESS pid = static_cast<PROCESS>(id); + auto pid = static_cast<PROCESS>(id); if (exitCode != 0) { emit processErrorExit(exitCode, err); return; diff --git a/src/passworddialog.cpp b/src/passworddialog.cpp index 9691e3ef..ca3b5244 100644 --- a/src/passworddialog.cpp +++ b/src/passworddialog.cpp @@ -65,7 +65,7 @@ PasswordDialog::PasswordDialog(const QString &file, const bool &isNew, } /** - * @brief PasswordDialog::~PasswordDialog basic destructor. + * @brief Pass{}{}wordDialog::~PasswordDialog basic destructor. */ PasswordDialog::~PasswordDialog() { delete ui; } @@ -134,7 +134,7 @@ void PasswordDialog::setPassword(QString password) { // show remaining values (if there are) otherLines.clear(); for (const NamedValue &nv : namedValues) { - QLineEdit *line = new QLineEdit(); + auto *line = new QLineEdit(); line->setObjectName(nv.name); line->setText(nv.value); ui->formLayout->addRow(new QLabel(nv.name), line); @@ -179,7 +179,7 @@ void PasswordDialog::setTemplate(QString rawFields, bool useTemplate) { foreach (QString field, m_fields) { if (field.isEmpty()) continue; - QLineEdit *line = new QLineEdit(); + auto *line = new QLineEdit(); line->setObjectName(field); ui->formLayout->addRow(new QLabel(field), line); setTabOrder(previous, line); diff --git a/src/qprogressindicator.cpp b/src/qprogressindicator.cpp index 009981f3..ae90f939 100644 --- a/src/qprogressindicator.cpp +++ b/src/qprogressindicator.cpp @@ -60,7 +60,7 @@ void QProgressIndicator::setColor(const QColor &color) { * @brief QProgressIndicator::sizeHint default minimum size. * @return QSize(20, 20) */ -QSize QProgressIndicator::sizeHint() const { return QSize(20, 20); } +QSize QProgressIndicator::sizeHint() const { return {20, 20}; } /** * @brief QProgressIndicator::heightForWidth square ratio. @@ -90,8 +90,8 @@ void QProgressIndicator::paintEvent(QPaintEvent * /*event*/) { QPainter p(this); p.setRenderHint(QPainter::Antialiasing); - int outerRadius = int((width - 1) * 0.5); - int innerRadius = int((width - 1) * 0.5 * 0.38); + auto outerRadius = int((width - 1) * 0.5); + auto innerRadius = int((width - 1) * 0.5 * 0.38); int capsuleHeight = outerRadius - innerRadius; int capsuleWidth = diff --git a/src/realpass.cpp b/src/realpass.cpp index 071f618b..bf420340 100644 --- a/src/realpass.cpp +++ b/src/realpass.cpp @@ -6,7 +6,7 @@ using namespace Enums; -RealPass::RealPass() {} +RealPass::RealPass() = default; /** * @brief RealPass::GitInit pass git init wrapper diff --git a/src/settingsconstants.cpp b/src/settingsconstants.cpp index 066931f3..5a38b814 100644 --- a/src/settingsconstants.cpp +++ b/src/settingsconstants.cpp @@ -1,6 +1,6 @@ #include "settingsconstants.h" -SettingsConstants::SettingsConstants() {} +SettingsConstants::SettingsConstants() = default; const QString SettingsConstants::version = "version"; diff --git a/src/storemodel.cpp b/src/storemodel.cpp index 2b7d3ac7..0f6dca0a 100644 --- a/src/storemodel.cpp +++ b/src/storemodel.cpp @@ -125,9 +125,9 @@ Qt::ItemFlags StoreModel::flags(const QModelIndex &index) const { if (index.isValid()) { return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; - } else { + } return Qt::ItemIsDropEnabled | defaultFlags; - } + } QStringList StoreModel::mimeTypes() const { @@ -152,7 +152,7 @@ QMimeData *StoreModel::mimeData(const QModelIndexList &indexes) const { stream << info; } - QMimeData *mimeData = new QMimeData(); + auto *mimeData = new QMimeData(); mimeData->setData("application/vnd+qtpass.dragAndDropInfoPasswordStore", encodedData); return mimeData; @@ -218,14 +218,14 @@ bool StoreModel::dropMimeData(const QMimeData *data, Qt::DropAction action, QFileInfo destFileinfo = fs->fileInfo(mapToSource(destIndex)); QFileInfo srcFileInfo = QFileInfo(info.path); QDir qdir; - QString cleanedSrc = qdir.cleanPath(srcFileInfo.absoluteFilePath()); - QString cleanedDest = qdir.cleanPath(destFileinfo.absoluteFilePath()); + QString cleanedSrc = QDir::cleanPath(srcFileInfo.absoluteFilePath()); + QString cleanedDest = QDir::cleanPath(destFileinfo.absoluteFilePath()); if (info.isDir) { QDir srcDir = QDir(info.path); // dropped dir onto dir if (destFileinfo.isDir()) { QDir destDir = QDir(cleanedDest).filePath(srcFileInfo.fileName()); - QString cleanedDestDir = qdir.cleanPath(destDir.absolutePath()); + QString cleanedDestDir = QDir::cleanPath(destDir.absolutePath()); if (action == Qt::MoveAction) { QtPassSettings::getPass()->Move(cleanedSrc, cleanedDestDir); } else if (action == Qt::CopyAction) { diff --git a/src/trayicon.cpp b/src/trayicon.cpp index a9fe5784..99f80def 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -19,7 +19,7 @@ TrayIcon::TrayIcon(QMainWindow *parent) sysTrayIcon(nullptr), trayIconMenu(nullptr), isAllocated(false) { parentwin = parent; - if (QSystemTrayIcon::isSystemTrayAvailable() == true) { + if (QSystemTrayIcon::isSystemTrayAvailable()) { createActions(); createTrayIcon(); @@ -45,7 +45,7 @@ TrayIcon::TrayIcon(QMainWindow *parent) * @param visible */ void TrayIcon::setVisible(bool visible) { - if (visible == true) + if (visible) parentwin->show(); else parentwin->hide(); @@ -99,7 +99,7 @@ void TrayIcon::createTrayIcon() { * @brief TrayIcon::showHideParent toggle app visibility. */ void TrayIcon::showHideParent() { - if (parentwin->isVisible() == true) + if (parentwin->isVisible()) parentwin->hide(); else parentwin->show(); diff --git a/src/usersdialog.cpp b/src/usersdialog.cpp index ddbafaeb..34b28fb9 100644 --- a/src/usersdialog.cpp +++ b/src/usersdialog.cpp @@ -28,9 +28,9 @@ UsersDialog::UsersDialog(QString dir, QWidget *parent) QList<UserInfo> secret_keys = QtPassSettings::getPass()->listKeys("", true); foreach (const UserInfo &sec, secret_keys) { - for (QList<UserInfo>::iterator it = users.begin(); it != users.end(); ++it) - if (sec.key_id == it->key_id) - it->have_secret = true; + for (auto & user : users) + if (sec.key_id == user.key_id) + user.have_secret = true; } QList<UserInfo> selected_users; @@ -41,9 +41,9 @@ UsersDialog::UsersDialog(QString dir, QWidget *parent) if (!recipients.isEmpty()) selected_users = QtPassSettings::getPass()->listKeys(recipients); foreach (const UserInfo &sel, selected_users) { - for (QList<UserInfo>::iterator it = users.begin(); it != users.end(); ++it) - if (sel.key_id == it->key_id) - it->enabled = true; + for (auto & user : users) + if (sel.key_id == user.key_id) + user.enabled = true; } if (count > selected_users.size()) { @@ -51,7 +51,7 @@ UsersDialog::UsersDialog(QString dir, QWidget *parent) QStringList recipients = QtPassSettings::getPass()->getRecipientList( m_dir.isEmpty() ? "" : m_dir); foreach (const QString recipient, recipients) { - if (QtPassSettings::getPass()->listKeys(recipient).size() < 1) { + if (QtPassSettings::getPass()->listKeys(recipient).empty()) { UserInfo i; i.enabled = true; i.key_id = recipient; @@ -120,7 +120,7 @@ void UsersDialog::keyPressEvent(QKeyEvent *event) { void UsersDialog::itemChange(QListWidgetItem *item) { if (!item) return; - UserInfo *info = item->data(Qt::UserRole).value<UserInfo *>(); + auto *info = item->data(Qt::UserRole).value<UserInfo *>(); if (!info) return; info->enabled = item->checkState() == Qt::Checked; @@ -137,9 +137,7 @@ void UsersDialog::populateList(const QString &filter) { nameFilter.setCaseSensitivity(Qt::CaseInsensitive); ui->listWidget->clear(); if (!m_userList.isEmpty()) { - for (QList<UserInfo>::iterator it = m_userList.begin(); - it != m_userList.end(); ++it) { - UserInfo &user(*it); + for (auto & user : m_userList) { if (filter.isEmpty() || nameFilter.exactMatch(user.name)) { if (!user.isValid() && !ui->checkBox->isChecked()) continue; @@ -155,7 +153,7 @@ void UsersDialog::populateList(const QString &filter) { if (user.expiry.toTime_t() > 0) userText += " " + tr("expires") + " " + user.expiry.toString(Qt::SystemLocaleShortDate); - QListWidgetItem *item = new QListWidgetItem(userText, ui->listWidget); + auto *item = new QListWidgetItem(userText, ui->listWidget); item->setCheckState(user.enabled ? Qt::Checked : Qt::Unchecked); item->setData(Qt::UserRole, QVariant::fromValue(&user)); if (user.have_secret) { |