summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-09-30 14:09:04 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-10-04 07:40:08 +0200
commitdf9d882d41b741fef7c5beeddb0abe9d904443d8 (patch)
tree6f3e90dacad4581b7f1cabe235cca298833a3da4 /src/gui/itemmodels
parent109e088c7c5d0c9325966e88d55fd9f7a58f67ea (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/gui/itemmodels')
-rw-r--r--src/gui/itemmodels/qfileinfogatherer.cpp4
-rw-r--r--src/gui/itemmodels/qfilesystemmodel.cpp24
-rw-r--r--src/gui/itemmodels/qfilesystemmodel_p.h4
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp36
4 files changed, 34 insertions, 34 deletions
diff --git a/src/gui/itemmodels/qfileinfogatherer.cpp b/src/gui/itemmodels/qfileinfogatherer.cpp
index f6ddf97c3b..fdba75d736 100644
--- a/src/gui/itemmodels/qfileinfogatherer.cpp
+++ b/src/gui/itemmodels/qfileinfogatherer.cpp
@@ -143,7 +143,7 @@ void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStr
void QFileInfoGatherer::updateFile(const QString &filePath)
{
QString dir = filePath.mid(0, filePath.lastIndexOf(u'/'));
- QString fileName = filePath.mid(dir.length() + 1);
+ QString fileName = filePath.mid(dir.size() + 1);
fetchExtendedInformation(dir, QStringList(fileName));
}
@@ -394,7 +394,7 @@ void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bo
updatedFiles.append(QPair<QString, QFileInfo>(fileInfo.fileName(), fileInfo));
QElapsedTimer current;
current.start();
- if ((firstTime && updatedFiles.count() > 100) || base.msecsTo(current) > 1000) {
+ if ((firstTime && updatedFiles.size() > 100) || base.msecsTo(current) > 1000) {
emit updates(path, updatedFiles);
updatedFiles.clear();
base = current;
diff --git a/src/gui/itemmodels/qfilesystemmodel.cpp b/src/gui/itemmodels/qfilesystemmodel.cpp
index f0dcb6d801..4cb393c5a1 100644
--- a/src/gui/itemmodels/qfilesystemmodel.cpp
+++ b/src/gui/itemmodels/qfilesystemmodel.cpp
@@ -420,7 +420,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS
// we couldn't find the path element, we create a new node since we
// _know_ that the path is valid
if (alreadyExisted) {
- if ((parent->children.count() == 0)
+ if ((parent->children.size() == 0)
|| (parent->caseSensitive()
&& parent->children.value(element)->fileName != element)
|| (!parent->caseSensitive()
@@ -476,7 +476,7 @@ void QFileSystemModel::timerEvent(QTimerEvent *event)
if (event->timerId() == d->fetchingTimer.timerId()) {
d->fetchingTimer.stop();
#if QT_CONFIG(filesystemwatcher)
- for (int i = 0; i < d->toFetch.count(); ++i) {
+ for (int i = 0; i < d->toFetch.size(); ++i) {
const QFileSystemModelPrivate::QFileSystemNode *node = d->toFetch.at(i).node;
if (!node->hasInformation()) {
d->fileInfoGatherer.fetchExtendedInformation(d->toFetch.at(i).dir,
@@ -640,10 +640,10 @@ int QFileSystemModel::rowCount(const QModelIndex &parent) const
return 0;
if (!parent.isValid())
- return d->root.visibleChildren.count();
+ return d->root.visibleChildren.size();
const QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent);
- return parentNode->visibleChildren.count();
+ return parentNode->visibleChildren.size();
}
/*!
@@ -1058,7 +1058,7 @@ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent
{
Q_Q(QFileSystemModel);
QFileSystemModelPrivate::QFileSystemNode *indexNode = node(parent);
- if (indexNode->children.count() == 0)
+ if (indexNode->children.size() == 0)
return;
QList<QFileSystemModelPrivate::QFileSystemNode *> values;
@@ -1076,7 +1076,7 @@ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent
indexNode->visibleChildren.clear();
//No more dirty item we reset our internal dirty index
indexNode->dirtyChildrenIndex = -1;
- const int numValues = values.count();
+ const int numValues = values.size();
indexNode->visibleChildren.reserve(numValues);
for (int i = 0; i < numValues; ++i) {
indexNode->visibleChildren.append(values.at(i)->fileName);
@@ -1380,7 +1380,7 @@ QString QFileSystemModelPrivate::filePath(const QModelIndex &index) const
}
QString fullPath = QDir::fromNativeSeparators(path.join(QDir::separator()));
#if !defined(Q_OS_WIN)
- if ((fullPath.length() > 2) && fullPath[0] == u'/' && fullPath[1] == u'/')
+ if ((fullPath.size() > 2) && fullPath[0] == u'/' && fullPath[1] == u'/')
fullPath = fullPath.mid(1);
#else
if (fullPath.length() == 2 && fullPath.endsWith(u':'))
@@ -1742,7 +1742,7 @@ bool QFileSystemModel::rmdir(const QModelIndex &aindex)
void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, const QStringList &files)
{
QFileSystemModelPrivate::QFileSystemNode *parentNode = node(directory, false);
- if (parentNode->children.count() == 0)
+ if (parentNode->children.size() == 0)
return;
QStringList toRemove;
QStringList newFiles = files;
@@ -1844,11 +1844,11 @@ void QFileSystemModelPrivate::addVisibleFiles(QFileSystemNode *parentNode, const
QModelIndex parent = index(parentNode);
bool indexHidden = isHiddenByFilter(parentNode, parent);
if (!indexHidden) {
- q->beginInsertRows(parent, parentNode->visibleChildren.count() , parentNode->visibleChildren.count() + newFiles.count() - 1);
+ q->beginInsertRows(parent, parentNode->visibleChildren.size() , parentNode->visibleChildren.size() + newFiles.count() - 1);
}
if (parentNode->dirtyChildrenIndex == -1)
- parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count();
+ parentNode->dirtyChildrenIndex = parentNode->visibleChildren.size();
for (const auto &newFile : newFiles) {
parentNode->visibleChildren.append(newFile);
@@ -1962,7 +1962,7 @@ void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path,
int visibleMin = parentNode->visibleLocation(min);
int visibleMax = parentNode->visibleLocation(max);
if (visibleMin >= 0
- && visibleMin < parentNode->visibleChildren.count()
+ && visibleMin < parentNode->visibleChildren.size()
&& parentNode->visibleChildren.at(visibleMin) == min
&& visibleMax >= 0) {
QModelIndex bottom = q->index(translateVisibleLocation(parentNode, visibleMin), 0, parentIndex);
@@ -1978,7 +1978,7 @@ void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path,
addVisibleFiles(parentNode, newFiles);
}
- if (newFiles.count() > 0 || (sortColumn != 0 && rowsToUpdate.count() > 0)) {
+ if (newFiles.count() > 0 || (sortColumn != 0 && rowsToUpdate.size() > 0)) {
forceSort = true;
delayedSort();
}
diff --git a/src/gui/itemmodels/qfilesystemmodel_p.h b/src/gui/itemmodels/qfilesystemmodel_p.h
index fa83208936..62a23205e4 100644
--- a/src/gui/itemmodels/qfilesystemmodel_p.h
+++ b/src/gui/itemmodels/qfilesystemmodel_p.h
@@ -92,7 +92,7 @@ public:
inline bool isDir() const {
if (info)
return info->isDir();
- if (children.count() > 0)
+ if (children.size() > 0)
return true;
return false;
}
@@ -209,7 +209,7 @@ public:
inline int translateVisibleLocation(QFileSystemNode *parent, int row) const {
if (sortOrder != Qt::AscendingOrder) {
if (parent->dirtyChildrenIndex == -1)
- return parent->visibleChildren.count() - row - 1;
+ return parent->visibleChildren.size() - row - 1;
if (row < parent->dirtyChildrenIndex)
return parent->dirtyChildrenIndex - row - 1;
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index bfb5e8e134..febabda6dd 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -319,11 +319,11 @@ void QStandardItemPrivate::sortChildren(int column, Qt::SortOrder order)
}
QModelIndexList changedPersistentIndexesFrom, changedPersistentIndexesTo;
- QList<QStandardItem*> sorted_children(children.count());
+ QList<QStandardItem*> sorted_children(children.size());
for (int i = 0; i < rowCount(); ++i) {
- int r = (i < sortable.count()
+ int r = (i < sortable.size()
? sortable.at(i).second
- : unsortable.at(i - sortable.count()));
+ : unsortable.at(i - sortable.size()));
for (int c = 0; c < columnCount(); ++c) {
QStandardItem *itm = q->child(r, c);
sorted_children[childIndex(i, c)] = itm;
@@ -371,7 +371,7 @@ void QStandardItemPrivate::setModel(QStandardItemModel *mod)
}
itm->d_func()->model = mod;
const QList<QStandardItem*> &childList = itm->d_func()->children;
- for (int i = 0; i < childList.count(); ++i) {
+ for (int i = 0; i < childList.size(); ++i) {
QStandardItem *chi = childList.at(i);
if (chi)
stack.push(chi);
@@ -432,7 +432,7 @@ bool QStandardItemPrivate::insertRows(int row, const QList<QStandardItem*> &item
Q_Q(QStandardItem);
if ((row < 0) || (row > rowCount()) || items.isEmpty())
return false;
- int count = items.count();
+ int count = items.size();
if (model)
model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);
if (rowCount() == 0) {
@@ -446,7 +446,7 @@ bool QStandardItemPrivate::insertRows(int row, const QList<QStandardItem*> &item
if (index != -1)
children.insert(index, columnCount() * count, nullptr);
}
- for (int i = 0; i < items.count(); ++i) {
+ for (int i = 0; i < items.size(); ++i) {
QStandardItem *item = items.at(i);
item->d_func()->model = model;
item->d_func()->parent = q;
@@ -478,7 +478,7 @@ bool QStandardItemPrivate::insertRows(int row, int count, const QList<QStandardI
}
if (!items.isEmpty()) {
int index = childIndex(row, 0);
- int limit = qMin(items.count(), columnCount() * count);
+ int limit = qMin(items.size(), columnCount() * count);
for (int i = 0; i < limit; ++i) {
QStandardItem *item = items.at(i);
if (item) {
@@ -523,7 +523,7 @@ bool QStandardItemPrivate::insertColumns(int column, int count, const QList<QSta
}
}
if (!items.isEmpty()) {
- int limit = qMin(items.count(), rowCount() * count);
+ int limit = qMin(items.size(), rowCount() * count);
for (int i = 0; i < limit; ++i) {
QStandardItem *item = items.at(i);
if (item) {
@@ -1588,8 +1588,8 @@ void QStandardItem::insertRow(int row, const QList<QStandardItem*> &items)
Q_D(QStandardItem);
if (row < 0)
return;
- if (columnCount() < items.count())
- setColumnCount(items.count());
+ if (columnCount() < items.size())
+ setColumnCount(items.size());
d->insertRows(row, 1, items);
}
@@ -1617,8 +1617,8 @@ void QStandardItem::insertColumn(int column, const QList<QStandardItem*> &items)
Q_D(QStandardItem);
if (column < 0)
return;
- if (rowCount() < items.count())
- setRowCount(items.count());
+ if (rowCount() < items.size())
+ setRowCount(items.size());
d->insertColumns(column, 1, items);
}
@@ -3133,7 +3133,7 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const
continue;
const QList<QStandardItem*> &childList = itm->d_func()->children;
- for (int i = 0; i < childList.count(); ++i) {
+ for (int i = 0; i < childList.size(); ++i) {
QStandardItem *chi = childList.at(i);
if (chi) {
itemsSet.remove(chi);
@@ -3143,7 +3143,7 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const
}
}
- stack.reserve(itemsSet.count());
+ stack.reserve(itemsSet.size());
for (QStandardItem *item : qAsConst(itemsSet))
stack.push(item);
@@ -3153,7 +3153,7 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const
if (itemsSet.contains(item)) //if the item is selection 'top-level', stream its position
stream << item->row() << item->column();
- stream << *item << item->columnCount() << int(item->d_ptr->children.count());
+ stream << *item << item->columnCount() << int(item->d_ptr->children.size());
stack += item->d_ptr->children;
}
@@ -3242,15 +3242,15 @@ bool QStandardItemModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
// Compute the number of continuous rows upon insertion and modify the rows to match
QList<int> rowsToInsert(bottom + 1);
- for (int i = 0; i < rows.count(); ++i)
+ for (int i = 0; i < rows.size(); ++i)
rowsToInsert[rows.at(i)] = 1;
- for (int i = 0; i < rowsToInsert.count(); ++i) {
+ for (int i = 0; i < rowsToInsert.size(); ++i) {
if (rowsToInsert.at(i) == 1){
rowsToInsert[i] = dragRowCount;
++dragRowCount;
}
}
- for (int i = 0; i < rows.count(); ++i)
+ for (int i = 0; i < rows.size(); ++i)
rows[i] = top + rowsToInsert.at(rows.at(i));
QBitArray isWrittenTo(dragRowCount * dragColumnCount);