Qt6: Adapt to removed QMap functionality

QMap::iterator::operator+() was removed in 14090760a8, necessitating
extra code using std::next/prev to workaround.

QMap::unite is gone, the replacement QMap::insert was only introduced
in 5.15.

QMap key values need to have an operator==() available.

Task-number: QTCREATORBUG-24098
Change-Id: Ic4cf429ab18cad58b1218180de40eb65586afd77
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
hjk
2020-08-12 09:40:51 +02:00
parent 0c4135e380
commit 89296a98a0
7 changed files with 27 additions and 11 deletions

View File

@@ -36,6 +36,11 @@ class QTCREATOR_UTILS_EXPORT DictKey
public:
DictKey(const QString &name, Qt::CaseSensitivity cs) : name(name), caseSensitivity(cs) {}
friend bool operator==(const DictKey &k1, const DictKey &k2)
{
return k1.name.compare(k2.name, k1.caseSensitivity) == 0;
}
QString name;
Qt::CaseSensitivity caseSensitivity;
};

View File

@@ -106,8 +106,8 @@ NameValueModel::~NameValueModel() = default;
QString NameValueModel::indexToVariable(const QModelIndex &index) const
{
return d->m_resultNameValueDictionary.key(d->m_resultNameValueDictionary.constBegin()
+ index.row());
const auto it = std::next(d->m_resultNameValueDictionary.constBegin(), index.row());
return d->m_resultNameValueDictionary.key(it);
}
void NameValueModel::setBaseNameValueDictionary(const NameValueDictionary &dictionary)
@@ -150,7 +150,8 @@ QVariant NameValueModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
const auto resultIterator = d->m_resultNameValueDictionary.constBegin() + index.row();
const auto resultIterator = std::next(d->m_resultNameValueDictionary.constBegin(), index.row());
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole:

View File

@@ -267,7 +267,7 @@ static void insertPosition(QMap<int, int> *map, int position)
bool gluedWithPrev = false;
if (itNext != map->begin()) {
auto itPrev = itNext - 1;
auto itPrev = std::prev(itNext);
const int keyStart = itPrev.key();
const int keyEnd = itPrev.value();
if (position >= keyStart && position <= keyEnd)
@@ -285,7 +285,7 @@ static void insertPosition(QMap<int, int> *map, int position)
itNext = map->erase(itNext);
if (gluedWithPrev) {
// glue with prev and next
auto itPrev = itNext - 1;
auto itPrev = std::prev(itNext);
*itPrev = keyEnd;
} else {
// glue with next

View File

@@ -328,7 +328,7 @@ int SideDiffEditorWidget::blockNumberForFileIndex(int fileIndex) const
if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
return -1;
return (m_fileInfo.constBegin() + fileIndex).key();
return std::next(m_fileInfo.constBegin(), fileIndex).key();
}
int SideDiffEditorWidget::fileIndexForBlockNumber(int blockNumber) const

View File

@@ -587,7 +587,7 @@ int UnifiedDiffEditorWidget::blockNumberForFileIndex(int fileIndex) const
if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
return -1;
return (m_fileInfo.constBegin() + fileIndex).key();
return std::next(m_fileInfo.constBegin(), fileIndex).key();
}
int UnifiedDiffEditorWidget::fileIndexForBlockNumber(int blockNumber) const

View File

@@ -697,8 +697,13 @@ void FakeVimExCommandsPage::apply()
}
settings->endArray();
globalCommandMapping.clear();
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
globalCommandMapping.insert(defaultMap);
globalCommandMapping.insert(newMapping);
#else
globalCommandMapping.unite(defaultMap);
globalCommandMapping.unite(newMapping);
#endif
}
}
@@ -950,8 +955,13 @@ void FakeVimUserCommandsPage::apply()
}
settings->endArray();
userMap.clear();
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
userMap.insert(dd->m_defaultUserCommandMap);
userMap.insert(current);
#else
userMap.unite(dd->m_defaultUserCommandMap);
userMap.unite(current);
#endif
}
}

View File

@@ -486,16 +486,16 @@ void TextEditorOverlay::mapEquivalentSelections()
m_equivalentSelections.clear();
m_equivalentSelections.resize(m_selections.size());
QMap<QString, int> all;
QMultiMap<QString, int> all;
for (int i = 0; i < m_selections.size(); ++i)
all.insertMulti(selectionText(i).toLower(), i);
all.insert(selectionText(i).toLower(), i);
const QList<QString> &uniqueKeys = all.uniqueKeys();
foreach (const QString &key, uniqueKeys) {
QList<int> indexes;
const auto cAll = all;
QMap<QString, int>::const_iterator lbit = cAll.lowerBound(key);
QMap<QString, int>::const_iterator ubit = cAll.upperBound(key);
QMultiMap<QString, int>::const_iterator lbit = cAll.lowerBound(key);
QMultiMap<QString, int>::const_iterator ubit = cAll.upperBound(key);
while (lbit != ubit) {
indexes.append(lbit.value());
++lbit;