QSideBar: replace a QPair with a struct
Instead of the incomprehensible "names" .first and .second, the code can now use .index and .path. Change-Id: I1449ba668f703b9a8b9391b0a0774072c8c6e8aa Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>bb10
parent
09ca03e1aa
commit
1d0ee89548
|
|
@ -274,7 +274,7 @@ void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move)
|
|||
continue;
|
||||
insertRows(row, 1);
|
||||
setUrl(index(row, 0), url, idx);
|
||||
watching.append(qMakePair(idx, cleanUrl));
|
||||
watching.append({idx, cleanUrl});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -326,7 +326,7 @@ void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto
|
|||
{
|
||||
QModelIndex parent = topLeft.parent();
|
||||
for (int i = 0; i < watching.count(); ++i) {
|
||||
QModelIndex index = watching.at(i).first;
|
||||
QModelIndex index = watching.at(i).index;
|
||||
if (index.model() && topLeft.model()) {
|
||||
Q_ASSERT(index.model() == topLeft.model());
|
||||
}
|
||||
|
|
@ -335,7 +335,7 @@ void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto
|
|||
&& index.column() >= topLeft.column()
|
||||
&& index.column() <= bottomRight.column()
|
||||
&& index.parent() == parent) {
|
||||
changed(watching.at(i).second);
|
||||
changed(watching.at(i).path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -349,12 +349,12 @@ void QUrlModel::layoutChanged()
|
|||
const int numPaths = watching.count();
|
||||
paths.reserve(numPaths);
|
||||
for (int i = 0; i < numPaths; ++i)
|
||||
paths.append(watching.at(i).second);
|
||||
paths.append(watching.at(i).path);
|
||||
watching.clear();
|
||||
for (int i = 0; i < numPaths; ++i) {
|
||||
QString path = paths.at(i);
|
||||
QModelIndex newIndex = fileSystemModel->index(path);
|
||||
watching.append(QPair<QModelIndex, QString>(newIndex, path));
|
||||
watching.append({newIndex, path});
|
||||
if (newIndex.isValid())
|
||||
changed(path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,9 +108,16 @@ private:
|
|||
void changed(const QString &path);
|
||||
void addIndexToWatch(const QString &path, const QModelIndex &index);
|
||||
QFileSystemModel *fileSystemModel;
|
||||
QVector<QPair<QModelIndex, QString> > watching;
|
||||
struct WatchItem {
|
||||
QModelIndex index;
|
||||
QString path;
|
||||
};
|
||||
friend class QTypeInfo<WatchItem>;
|
||||
|
||||
QVector<WatchItem> watching;
|
||||
QList<QUrl> invalidUrls;
|
||||
};
|
||||
Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_MOVABLE_TYPE);
|
||||
|
||||
class Q_AUTOTEST_EXPORT QSidebar : public QListView
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue