diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-09-30 14:09:04 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-04 07:40:08 +0200 |
commit | df9d882d41b741fef7c5beeddb0abe9d904443d8 (patch) | |
tree | 6f3e90dacad4581b7f1cabe235cca298833a3da4 /src/widgets/dialogs | |
parent | 109e088c7c5d0c9325966e88d55fd9f7a58f67ea (diff) |
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 30 | ||||
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 4 | ||||
-rw-r--r-- | src/widgets/dialogs/qsidebar.cpp | 10 | ||||
-rw-r--r-- | src/widgets/dialogs/qwizard.cpp | 32 |
4 files changed, 38 insertions, 38 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index ebbc27ba7e..1eb19dc399 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -652,7 +652,7 @@ void QFileDialogPrivate::retranslateStrings() if (proxyModel) abstractModel = proxyModel; #endif - int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); + int total = qMin(abstractModel->columnCount(QModelIndex()), actions.size() + 1); for (int i = 1; i < total; ++i) { actions.at(i - 1)->setText(QFileDialog::tr("Show ") + abstractModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); } @@ -2678,7 +2678,7 @@ void QFileDialog::accept() if (urls.isEmpty()) return; d->_q_emitUrlsSelected(urls); - if (urls.count() == 1) + if (urls.size() == 1) d->_q_emitUrlSelected(urls.first()); QDialog::accept(); return; @@ -2728,7 +2728,7 @@ void QFileDialog::accept() if (!info.exists()) { int maxNameLength = d->maxNameLength(info.path()); - if (maxNameLength >= 0 && info.fileName().length() > maxNameLength) + if (maxNameLength >= 0 && info.fileName().size() > maxNameLength) return; } @@ -2849,8 +2849,8 @@ bool QFileDialogPrivate::restoreWidgetState(QStringList &history, int splitterPo if (!qFileDialogUi->splitter->restoreState(splitterState)) return false; QList<int> list = qFileDialogUi->splitter->sizes(); - if (list.count() >= 2 && (list.at(0) == 0 || list.at(1) == 0)) { - for (int i = 0; i < list.count(); ++i) + if (list.size() >= 2 && (list.at(0) == 0 || list.at(1) == 0)) { + for (int i = 0; i < list.size(); ++i) list[i] = qFileDialogUi->splitter->widget(i)->sizeHint().width(); qFileDialogUi->splitter->setSizes(list); } @@ -2873,7 +2873,7 @@ bool QFileDialogPrivate::restoreWidgetState(QStringList &history, int splitterPo if (proxyModel) abstractModel = proxyModel; #endif - int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); + int total = qMin(abstractModel->columnCount(QModelIndex()), actions.size() + 1); for (int i = 1; i < total; ++i) actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i)); @@ -3329,7 +3329,7 @@ void QFileDialogPrivate::_q_pathChanged(const QString &newPath) if (currentHistoryLocation < 0 || currentHistory.value(currentHistoryLocation).path != newNativePath) { if (currentHistoryLocation >= 0) saveHistorySelection(); - while (currentHistoryLocation >= 0 && currentHistoryLocation + 1 < currentHistory.count()) { + while (currentHistoryLocation >= 0 && currentHistoryLocation + 1 < currentHistory.size()) { currentHistory.removeLast(); } currentHistory.append({newNativePath, PersistentModelIndexList()}); @@ -3661,7 +3661,7 @@ void QFileDialogPrivate::_q_updateOkButton() fileDir = info.canonicalFilePath(); } else { fileDir = fn.mid(0, fn.lastIndexOf(u'/')); - fileName = fn.mid(fileDir.length() + 1); + fileName = fn.mid(fileDir.size() + 1); } if (lineEditText.contains(".."_L1)) { fileDir = info.canonicalFilePath(); @@ -3679,7 +3679,7 @@ void QFileDialogPrivate::_q_updateOkButton() } if (!idx.isValid()) { int maxLength = maxNameLength(fileDir); - enableButton = maxLength < 0 || fileName.length() <= maxLength; + enableButton = maxLength < 0 || fileName.size() <= maxLength; } break; } @@ -3808,8 +3808,8 @@ void QFileDialogPrivate::_q_useNameFilter(int index) QString fileName = lineEdit()->text(); const QString fileNameExtension = QFileInfo(fileName).suffix(); if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) { - const int fileNameExtensionLength = fileNameExtension.length(); - fileName.replace(fileName.length() - fileNameExtensionLength, + const int fileNameExtensionLength = fileNameExtension.size(); + fileName.replace(fileName.size() - fileNameExtensionLength, fileNameExtensionLength, newNameFilterExtension); qFileDialogUi->listView->clearSelection(); lineEdit()->setText(fileName); @@ -4011,7 +4011,7 @@ void QFileDialogComboBox::showPopup() if (!urls.contains(path)) urls.prepend(path); } - if (urls.count() > 0) { + if (urls.size() > 0) { model()->insertRow(model()->rowCount()); idx = model()->index(model()->rowCount()-1, 0); // ### TODO maybe add a horizontal line before this @@ -4157,12 +4157,12 @@ QString QFSCompleter::pathFromIndex(const QModelIndex &index) const if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { #if defined(Q_OS_UNIX) if (currentLocation == QDir::separator()) - return path.mid(currentLocation.length()); + return path.mid(currentLocation.size()); #endif if (currentLocation.endsWith(u'/')) - return path.mid(currentLocation.length()); + return path.mid(currentLocation.size()); else - return path.mid(currentLocation.length()+1); + return path.mid(currentLocation.size()+1); } return index.data(QFileSystemModel::FilePathRole).toString(); } diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index eeab47f822..28bf9b0c03 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1031,14 +1031,14 @@ void QMessageBoxPrivate::detectEscapeButton() // If there is only one button, make it the escape button const QList<QAbstractButton *> buttons = buttonBox->buttons(); - if (buttons.count() == 1) { + if (buttons.size() == 1) { detectedEscapeButton = buttons.first(); return; } // If there are two buttons and one of them is the "Show Details..." // button, then make the other one the escape button - if (buttons.count() == 2 && detailsButton) { + if (buttons.size() == 2 && detailsButton) { auto idx = buttons.indexOf(detailsButton); if (idx != -1) { detectedEscapeButton = buttons.at(1 - idx); diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index bbbcb83630..8fb160ab65 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -211,7 +211,7 @@ void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) if (row == -1) row = rowCount(); row = qMin(row, rowCount()); - for (int i = list.count() - 1; i >= 0; --i) { + for (int i = list.size() - 1; i >= 0; --i) { QUrl url = list.at(i); if (!url.isValid() || url.scheme() != "file"_L1) continue; @@ -291,7 +291,7 @@ void QUrlModel::setFileSystemModel(QFileSystemModel *model) void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { QModelIndex parent = topLeft.parent(); - for (int i = 0; i < watching.count(); ++i) { + for (int i = 0; i < watching.size(); ++i) { QModelIndex index = watching.at(i).index; if (index.model() && topLeft.model()) { Q_ASSERT(index.model() == topLeft.model()); @@ -312,7 +312,7 @@ void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto void QUrlModel::layoutChanged() { QStringList paths; - const int numPaths = watching.count(); + const int numPaths = watching.size(); paths.reserve(numPaths); for (int i = 0; i < numPaths; ++i) paths.append(watching.at(i).path); @@ -417,7 +417,7 @@ void QSidebar::showContextMenu(const QPoint &position) connect(action, SIGNAL(triggered()), this, SLOT(removeEntry())); actions.append(action); } - if (actions.count() > 0) + if (actions.size() > 0) QMenu::exec(actions, mapToGlobal(position)); } #endif // QT_CONFIG(menu) @@ -431,7 +431,7 @@ void QSidebar::removeEntry() { QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); QList<QPersistentModelIndex> indexes; - const int numIndexes = idxs.count(); + const int numIndexes = idxs.size(); indexes.reserve(numIndexes); for (int i = 0; i < numIndexes; i++) indexes.append(idxs.at(i)); diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 6de0530c51..e06727d145 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -181,7 +181,7 @@ QWizardField::QWizardField(QWizardPage *page, const QString &spec, QObject *obje void QWizardField::resolve(const QList<QWizardDefaultProperty> &defaultPropertyTable) { if (property.isEmpty()) - findProperty(defaultPropertyTable.constData(), defaultPropertyTable.count()); + findProperty(defaultPropertyTable.constData(), defaultPropertyTable.size()); initialValue = object->property(property); } @@ -695,7 +695,7 @@ void QWizardPrivate::reset() if (current != -1) { q->currentPage()->hide(); cleanupPagesNotInHistory(); - for (int i = history.count() - 1; i >= 0; --i) + for (int i = history.size() - 1; i >= 0; --i) q->cleanupPage(history.at(i)); history.clear(); for (QWizardPage *page : qAsConst(pageMap)) @@ -732,7 +732,7 @@ void QWizardPrivate::addField(const QWizardField &field) return; } - fieldIndexMap.insert(myField.name, fields.count()); + fieldIndexMap.insert(myField.name, fields.size()); fields += myField; if (myField.mandatory && !myField.changedSignal.isEmpty()) QObject::connect(myField.object, myField.changedSignal, @@ -1425,10 +1425,10 @@ void QWizardPrivate::updateButtonTexts() void QWizardPrivate::updateButtonLayout() { if (buttonsHaveCustomLayout) { - QVarLengthArray<QWizard::WizardButton, QWizard::NButtons> array(buttonsCustomLayout.count()); - for (int i = 0; i < buttonsCustomLayout.count(); ++i) + QVarLengthArray<QWizard::WizardButton, QWizard::NButtons> array(buttonsCustomLayout.size()); + for (int i = 0; i < buttonsCustomLayout.size(); ++i) array[i] = buttonsCustomLayout.at(i); - setButtonLayout(array.constData(), array.count()); + setButtonLayout(array.constData(), array.size()); } else { // Positions: // Help Stretch Custom1 Custom2 Custom3 Cancel Back Next Commit Finish Cancel Help @@ -1645,15 +1645,15 @@ void QWizardPrivate::_q_updateButtonStates() const QWizardPage *page = q->currentPage(); bool complete = page && page->isComplete(); - btn.back->setEnabled(history.count() > 1 - && !q->page(history.at(history.count() - 2))->isCommitPage() + btn.back->setEnabled(history.size() > 1 + && !q->page(history.at(history.size() - 2))->isCommitPage() && (!canFinish || !(opts & QWizard::DisabledBackButtonOnLastPage))); btn.next->setEnabled(canContinue && complete); btn.commit->setEnabled(canContinue && complete); btn.finish->setEnabled(canFinish && complete); const bool backButtonVisible = buttonLayoutContains(QWizard::BackButton) - && (history.count() > 1 || !(opts & QWizard::NoBackButtonOnStartPage)) + && (history.size() > 1 || !(opts & QWizard::NoBackButtonOnStartPage)) && (canContinue || !(opts & QWizard::NoBackButtonOnLastPage)); bool commitPage = page && page->isCommitPage(); btn.back->setVisible(backButtonVisible); @@ -2228,7 +2228,7 @@ void QWizard::setPage(int theid, QWizardPage *page) page->setParent(d->pageFrame); QList<QWizardField> &pendingFields = page->d_func()->pendingFields; - for (int i = 0; i < pendingFields.count(); ++i) + for (int i = 0; i < pendingFields.size(); ++i) d->addField(pendingFields.at(i)); pendingFields.clear(); @@ -2296,7 +2296,7 @@ void QWizard::removePage(int id) removedPage = d->pageMap.take(id); d->history.removeOne(id); d->_q_updateButtonStates(); - } else if (d->history.count() == 1) { + } else if (d->history.size() == 1) { // Case 3: removing the current page which is the first (and only) one in the history d->reset(); removedPage = d->pageMap.take(id); @@ -2319,7 +2319,7 @@ void QWizard::removePage(int id) d->pageVBoxLayout->removeWidget(removedPage); - for (int i = d->fields.count() - 1; i >= 0; --i) { + for (int i = d->fields.size() - 1; i >= 0; --i) { if (d->fields.at(i).page == removedPage) { removedPage->d_func()->pendingFields += d->fields.at(i); d->removeFieldAt(i); @@ -2706,7 +2706,7 @@ void QWizard::setButtonLayout(const QList<WizardButton> &layout) { Q_D(QWizard); - for (int i = 0; i < layout.count(); ++i) { + for (int i = 0; i < layout.size(); ++i) { WizardButton button1 = layout.at(i); if (button1 == NoButton || button1 == Stretch) @@ -2891,7 +2891,7 @@ void QWizard::setDefaultProperty(const char *className, const char *property, const char *changedSignal) { Q_D(QWizard); - for (int i = d->defaultPropertyTable.count() - 1; i >= 0; --i) { + for (int i = d->defaultPropertyTable.size() - 1; i >= 0; --i) { if (qstrcmp(d->defaultPropertyTable.at(i).className, className) == 0) { d->defaultPropertyTable.remove(i); break; @@ -3071,7 +3071,7 @@ QSize QWizard::sizeHint() const void QWizard::back() { Q_D(QWizard); - int n = d->history.count() - 2; + int n = d->history.size() - 2; if (n < 0) return; d->switchToPage(d->history.at(n), QWizardPrivate::Backward); @@ -3670,7 +3670,7 @@ bool QWizardPage::isComplete() const return true; const QList<QWizardField> &wizardFields = d->wizard->d_func()->fields; - for (int i = wizardFields.count() - 1; i >= 0; --i) { + for (int i = wizardFields.size() - 1; i >= 0; --i) { const QWizardField &field = wizardFields.at(i); if (field.page == this && field.mandatory) { QVariant value = field.object->property(field.property); |