Skip to content

Commit

Permalink
clang-tidy: use auto
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb authored and droidmonkey committed May 1, 2022
1 parent f3f1520 commit 7e1d980
Show file tree
Hide file tree
Showing 32 changed files with 224 additions and 223 deletions.
2 changes: 1 addition & 1 deletion src/autotype/ShortcutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void ShortcutWidget::keyEvent(QKeyEvent* event)
return;
}

Qt::Key key = static_cast<Qt::Key>(event->key());
auto key = static_cast<Qt::Key>(event->key());

if (key <= 0 || key == Qt::Key_unknown) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/AddGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int AddGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPoin
return EXIT_FAILURE;
}

Group* newGroup = new Group();
auto newGroup = new Group();
newGroup->setUuid(QUuid::createUuid());
newGroup->setName(groupName);
newGroup->setParent(parentGroup);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Estimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void estimate(const char* pwd, bool advanced)
{
auto& out = Utils::STDOUT;

int len = static_cast<int>(strlen(pwd));
auto len = static_cast<int>(strlen(pwd));
if (!advanced) {
const auto e = PasswordHealth(pwd).entropy();
// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion src/core/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ bool Entry::equals(const Entry* other, CompareItemOptions options) const

Entry* Entry::clone(CloneFlags flags) const
{
Entry* entry = new Entry();
auto entry = new Entry();
entry->setUpdateTimeinfo(false);
if (flags & CloneNewUuid) {
entry->m_uuid = QUuid::createUuid();
Expand Down
2 changes: 1 addition & 1 deletion src/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ Group* Group::findChildByName(const QString& name)
*/
Group* Group::clone(Entry::CloneFlags entryFlags, Group::CloneFlags groupFlags) const
{
Group* clonedGroup = new Group();
auto clonedGroup = new Group();

clonedGroup->setUpdateTimeinfo(false);

Expand Down
32 changes: 16 additions & 16 deletions src/format/KeePass1Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
bool reachedEnd = false;

do {
quint16 fieldType = Endian::readSizedInt<quint16>(cipherStream, KeePass1::BYTEORDER, &ok);
auto fieldType = Endian::readSizedInt<quint16>(cipherStream, KeePass1::BYTEORDER, &ok);
if (!ok) {
raiseError(tr("Invalid group field type number"));
return nullptr;
}

int fieldSize = static_cast<int>(Endian::readSizedInt<quint32>(cipherStream, KeePass1::BYTEORDER, &ok));
auto fieldSize = static_cast<int>(Endian::readSizedInt<quint32>(cipherStream, KeePass1::BYTEORDER, &ok));
if (!ok) {
raiseError(tr("Invalid group field size"));
return nullptr;
Expand Down Expand Up @@ -513,7 +513,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
raiseError(tr("Incorrect group icon field size"));
return nullptr;
}
quint32 iconNumber = Endian::bytesToSizedInt<quint32>(fieldData, KeePass1::BYTEORDER);
auto iconNumber = Endian::bytesToSizedInt<quint32>(fieldData, KeePass1::BYTEORDER);
group->setIcon(iconNumber);
break;
}
Expand Down Expand Up @@ -564,13 +564,13 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
bool reachedEnd = false;

do {
quint16 fieldType = Endian::readSizedInt<quint16>(cipherStream, KeePass1::BYTEORDER, &ok);
auto fieldType = Endian::readSizedInt<quint16>(cipherStream, KeePass1::BYTEORDER, &ok);
if (!ok) {
raiseError(tr("Missing entry field type number"));
return nullptr;
}

int fieldSize = static_cast<int>(Endian::readSizedInt<quint32>(cipherStream, KeePass1::BYTEORDER, &ok));
auto fieldSize = static_cast<int>(Endian::readSizedInt<quint32>(cipherStream, KeePass1::BYTEORDER, &ok));
if (!ok) {
raiseError(tr("Invalid entry field size"));
return nullptr;
Expand Down Expand Up @@ -598,7 +598,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
raiseError(tr("Invalid entry group id field size"));
return nullptr;
}
quint32 groupId = Endian::bytesToSizedInt<quint32>(fieldData, KeePass1::BYTEORDER);
auto groupId = Endian::bytesToSizedInt<quint32>(fieldData, KeePass1::BYTEORDER);
m_entryGroupIds.insert(entry.data(), groupId);
break;
}
Expand All @@ -607,7 +607,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
raiseError(tr("Invalid entry icon field size"));
return nullptr;
}
quint32 iconNumber = Endian::bytesToSizedInt<quint32>(fieldData, KeePass1::BYTEORDER);
auto iconNumber = Endian::bytesToSizedInt<quint32>(fieldData, KeePass1::BYTEORDER);
entry->setIcon(iconNumber);
break;
}
Expand Down Expand Up @@ -806,15 +806,15 @@ bool KeePass1Reader::parseGroupTreeState(const QByteArray& data)
}

int pos = 0;
quint32 num = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto num = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

if (static_cast<quint32>(data.size() - 4) != (num * 5)) {
return false;
}

for (quint32 i = 0; i < num; i++) {
quint32 groupId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto groupId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

bool expanded = data.at(pos);
Expand All @@ -836,13 +836,13 @@ bool KeePass1Reader::parseCustomIcons4(const QByteArray& data)

int pos = 0;

quint32 numIcons = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto numIcons = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

quint32 numEntries = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto numEntries = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

quint32 numGroups = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto numGroups = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

QList<QUuid> iconUuids;
Expand All @@ -851,7 +851,7 @@ bool KeePass1Reader::parseCustomIcons4(const QByteArray& data)
if (data.size() < (pos + 4)) {
return false;
}
quint32 iconSize = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto iconSize = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

if (static_cast<quint32>(data.size()) < (pos + iconSize)) {
Expand All @@ -873,7 +873,7 @@ bool KeePass1Reader::parseCustomIcons4(const QByteArray& data)
QByteArray entryUuid = data.mid(pos, 16);
pos += 16;

quint32 iconId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto iconId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

if (m_entryUuids.contains(entryUuid) && (iconId < static_cast<quint32>(iconUuids.size()))) {
Expand All @@ -886,10 +886,10 @@ bool KeePass1Reader::parseCustomIcons4(const QByteArray& data)
}

for (quint32 i = 0; i < numGroups; i++) {
quint32 groupId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto groupId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

quint32 iconId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
auto iconId = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4;

if (m_groupIds.contains(groupId) && (iconId < static_cast<quint32>(iconUuids.size()))) {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void Application::processIncomingConnection()

void Application::socketReadyRead()
{
QLocalSocket* socket = qobject_cast<QLocalSocket*>(sender());
auto socket = qobject_cast<QLocalSocket*>(sender());
if (!socket) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/CategoryListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ QSize CategoryListWidget::minimumSizeHint() const

int CategoryListWidget::addCategory(const QString& labelText, const QIcon& icon)
{
QListWidgetItem* item = new QListWidgetItem(m_ui->categoryList);
auto item = new QListWidgetItem(m_ui->categoryList);
item->setText(labelText);
item->setIcon(icon);
m_ui->categoryList->addItem(item);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
this);
msgbox.setDefaultButton(QMessageBox::No);

QCheckBox* checkbox = new QCheckBox(tr("Remember my choice"), &msgbox);
auto checkbox = new QCheckBox(tr("Remember my choice"), &msgbox);
msgbox.setCheckBox(checkbox);
bool remember = false;
QObject::connect(checkbox, &QCheckBox::stateChanged, [&](int state) {
Expand Down
10 changes: 5 additions & 5 deletions src/gui/KMessageWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
QObject::connect(textLabel, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString)));
QObject::connect(textLabel, SIGNAL(linkHovered(QString)), q, SIGNAL(linkHovered(QString)));

QAction *closeAction = new QAction(q);
auto closeAction = new QAction(q);
closeAction->setText(KMessageWidget::tr("&Close"));
closeAction->setToolTip(KMessageWidget::tr("Close message"));
closeAction->setIcon(icons()->icon("message-close"));
Expand All @@ -114,7 +114,7 @@ void KMessageWidgetPrivate::createLayout()

const auto actions = q->actions();
for (QAction *action: actions) {
QToolButton *button = new QToolButton(content);
auto button = new QToolButton(content);
button->setDefaultAction(action);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
buttons.append(button);
Expand All @@ -126,12 +126,12 @@ void KMessageWidgetPrivate::createLayout()
closeButton->setAutoRaise(buttons.isEmpty());

if (wordWrap) {
QGridLayout *layout = new QGridLayout(content);
auto layout = new QGridLayout(content);
// Set alignment to make sure icon does not move down if text wraps
layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
layout->addWidget(textLabel, 0, 1);

QHBoxLayout *buttonLayout = new QHBoxLayout;
auto buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
for (QToolButton* button: asConst(buttons)) {
// For some reason, calling show() is necessary if wordwrap is true,
Expand All @@ -143,7 +143,7 @@ void KMessageWidgetPrivate::createLayout()
buttonLayout->addWidget(closeButton);
layout->addItem(buttonLayout, 1, 0, 1, 2);
} else {
QHBoxLayout *layout = new QHBoxLayout(content);
auto layout = new QHBoxLayout(content);
layout->addWidget(iconLabel);
layout->addWidget(textLabel);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/PasswordGeneratorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent)
// set font size of password quality and entropy labels dynamically to 80% of
// the default font size, but make it no smaller than 8pt
QFont defaultFont;
int smallerSize = static_cast<int>(defaultFont.pointSize() * 0.8f);
auto smallerSize = static_cast<int>(defaultFont.pointSize() * 0.8f);
if (smallerSize >= 8) {
defaultFont.setPointSize(smallerSize);
m_ui->entropyLabel->setFont(defaultFont);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/SearchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SearchWidget::~SearchWidget()
bool SearchWidget::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
auto keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Escape) {
emit escapePressed();
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/TotpExportSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TotpExportSettingsDialog::TotpExportSettingsDialog(DatabaseWidget* parent, Entry
QBuffer buffer;
qrc.writeSvg(&buffer, logicalDpiX());
m_totpSvgWidget->load(buffer.data());
const int minsize = static_cast<int>(logicalDpiX() * 2.5);
const auto minsize = static_cast<int>(logicalDpiX() * 2.5);
m_totpSvgWidget->setMinimumSize(minsize, minsize);
} else {
auto errorBox = new QMessageBox(parent);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/WelcomeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void WelcomeWidget::refreshLastDatabases()
m_ui->recentListWidget->clear();
const QStringList lastDatabases = config()->get(Config::LastDatabases).toStringList();
for (const QString& database : lastDatabases) {
QListWidgetItem* itm = new QListWidgetItem;
auto itm = new QListWidgetItem;
itm->setText(database);
m_ui->recentListWidget->addItem(itm);
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/csvImport/CsvImportWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void CsvImportWidget::writeDatabase()
if (not m_parserModel->data(m_parserModel->index(r, 1)).isValid()) {
continue;
}
Entry* entry = new Entry();
auto entry = new Entry();
entry->setUuid(QUuid::createUuid());
entry->setGroup(splitGroups(m_parserModel->data(m_parserModel->index(r, 0)).toString()));
entry->setTitle(m_parserModel->data(m_parserModel->index(r, 1)).toString());
Expand Down Expand Up @@ -325,7 +325,7 @@ Group* CsvImportWidget::splitGroups(const QString& label)
for (const QString& groupName : groupList) {
Group* children = hasChildren(current, groupName);
if (children == nullptr) {
Group* brandNew = new Group();
auto brandNew = new Group();
brandNew->setParent(current);
brandNew->setName(groupName);
brandNew->setUuid(QUuid::createUuid());
Expand Down
2 changes: 1 addition & 1 deletion src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void EditEntryWidget::copyPublicKey()
void EditEntryWidget::useExpiryPreset(QAction* action)
{
m_mainUi->expireCheck->setChecked(true);
TimeDelta delta = action->data().value<TimeDelta>();
auto delta = action->data().value<TimeDelta>();
QDateTime now = Clock::currentDateTime();
QDateTime expiryDateTime = now + delta;
m_mainUi->expireDatePicker->setDateTime(expiryDateTime);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/entry/EntryAttachmentsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,14 @@ bool EntryAttachmentsWidget::eventFilter(QObject* watched, QEvent* e)
if (watched == m_ui->attachmentsView->viewport() && !isReadOnly()) {
const QEvent::Type eventType = e->type();
if (eventType == QEvent::DragEnter || eventType == QEvent::DragMove) {
QDropEvent* dropEv = static_cast<QDropEvent*>(e);
auto dropEv = static_cast<QDropEvent*>(e);
const QMimeData* mimeData = dropEv->mimeData();
if (mimeData->hasUrls()) {
dropEv->acceptProposedAction();
return true;
}
} else if (eventType == QEvent::Drop) {
QDropEvent* dropEv = static_cast<QDropEvent*>(e);
auto dropEv = static_cast<QDropEvent*>(e);
const QMimeData* mimeData = dropEv->mimeData();
if (mimeData->hasUrls()) {
dropEv->acceptProposedAction();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/entry/EntryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const
return nullptr;
}

QMimeData* data = new QMimeData();
auto data = new QMimeData();
QByteArray encoded;
QDataStream stream(&encoded, QIODevice::WriteOnly);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/group/GroupModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ QMimeData* GroupModel::mimeData(const QModelIndexList& indexes) const
return nullptr;
}

QMimeData* data = new QMimeData();
auto data = new QMimeData();
QByteArray encoded;
QDataStream stream(&encoded, QIODevice::WriteOnly);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/osutils/nixutils/ScreenLockListenerDBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void ScreenLockListenerDBus::login1SessionObjectReceived(QDBusMessage response)
qDebug() << "org.freedesktop.login1.Manager.GetSession did not return a QDBusObjectPath";
return;
}
QDBusObjectPath path = arg0.value<QDBusObjectPath>();
auto path = arg0.value<QDBusObjectPath>();
QDBusConnection systemBus = QDBusConnection::systemBus();

systemBus.connect("", // service
Expand Down
4 changes: 2 additions & 2 deletions src/gui/reports/ReportsPageStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ QWidget* ReportsPageStatistics::createWidget()

void ReportsPageStatistics::loadSettings(QWidget* widget, QSharedPointer<Database> db)
{
ReportsWidgetStatistics* settingsWidget = reinterpret_cast<ReportsWidgetStatistics*>(widget);
auto settingsWidget = reinterpret_cast<ReportsWidgetStatistics*>(widget);
settingsWidget->loadSettings(db);
}

void ReportsPageStatistics::saveSettings(QWidget* widget)
{
ReportsWidgetStatistics* settingsWidget = reinterpret_cast<ReportsWidgetStatistics*>(widget);
auto settingsWidget = reinterpret_cast<ReportsWidgetStatistics*>(widget);
settingsWidget->saveSettings();
}
Loading

0 comments on commit 7e1d980

Please sign in to comment.