summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2019-10-29 17:11:00 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2019-11-04 13:37:17 +0000
commit03a52b9c8725992408f0087294ab1bc5be9159e6 (patch)
tree827c5b4db6621e9a4886614af1e9c4bc6c545b4a /src/shared
parent5e4d13f3439086fcec08f1598b3605f766843da8 (diff)
downloadqt-creator-03a52b9c8725992408f0087294ab1bc5be9159e6.tar.gz
QmakeProjectManager: Improve renaming functionality
This was implemented rather sloppily: The file was removed from all variables, but only added to one. Also, no care was taken to insert the new file name into the same block the old one was removed from. Fixes: QTCREATORBUG-19257 Change-Id: Ib309389ba7647189112d5c7dd7b3e784f921d2c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/proparser/prowriter.cpp34
-rw-r--r--src/shared/proparser/prowriter.h21
2 files changed, 39 insertions, 16 deletions
diff --git a/src/shared/proparser/prowriter.cpp b/src/shared/proparser/prowriter.cpp
index 282080013f..6d79524912 100644
--- a/src/shared/proparser/prowriter.cpp
+++ b/src/shared/proparser/prowriter.cpp
@@ -415,7 +415,7 @@ void ProWriter::addFiles(ProFile *profile, QStringList *lines, const QStringList
}
static void findProVariables(const ushort *tokPtr, const QStringList &vars,
- QList<int> *proVars, const uint firstLine = 0)
+ ProWriter::VarLocations &proVars, const uint firstLine = 0)
{
int lineNo = firstLine;
QString tmp;
@@ -433,8 +433,11 @@ static void findProVariables(const ushort *tokPtr, const QStringList &vars,
tokPtr += blockLen;
}
} else if (tok == TokAssign || tok == TokAppend || tok == TokAppendUnique) {
- if (getLiteral(lastXpr, tokPtr - 1, tmp) && vars.contains(tmp))
- *proVars << lineNo;
+ if (getLiteral(lastXpr, tokPtr - 1, tmp) && vars.contains(tmp)) {
+ QString varName = tmp;
+ varName.detach(); // tmp was constructed via setRawData()
+ proVars << qMakePair(varName, lineNo);
+ }
skipExpression(++tokPtr, lineNo);
} else {
lastXpr = skipToken(tok, tokPtr, lineNo);
@@ -443,21 +446,21 @@ static void findProVariables(const ushort *tokPtr, const QStringList &vars,
}
QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
- const QStringList &values, const QStringList &vars)
+ const QStringList &values, const QStringList &vars, VarLocations *removedLocations)
{
QList<int> notChanged;
// yeah, this is a bit silly
for (int i = 0; i < values.size(); i++)
notChanged << i;
- QList<int> varLines;
- findProVariables(profile->tokPtr(), vars, &varLines);
+ VarLocations varLocations;
+ findProVariables(profile->tokPtr(), vars, varLocations);
// This code expects proVars to be sorted by the variables' appearance in the file.
int delta = 1;
- for (int ln : qAsConst(varLines)) {
+ for (const VarLocation &loc : qAsConst(varLocations)) {
bool first = true;
- int lineNo = ln - delta;
+ int lineNo = loc.second - delta;
typedef QPair<int, int> ContPos;
QList<ContPos> contPos;
while (lineNo < lines->count()) {
@@ -507,6 +510,8 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
const int pos = values.indexOf(fn);
if (pos != -1) {
notChanged.removeOne(pos);
+ if (removedLocations)
+ *removedLocations << qMakePair(loc.first, loc.second - delta);
if (colNo < lineLen)
colNo++;
else if (varCol)
@@ -559,8 +564,13 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
return notChanged;
}
-QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
- const QDir &proFileDir, const QStringList &values, const QStringList &vars)
+QStringList ProWriter::removeFiles(
+ ProFile *profile,
+ QStringList *lines,
+ const QDir &proFileDir,
+ const QStringList &values,
+ const QStringList &vars,
+ VarLocations *removedLocations)
{
// This is a tad stupid - basically, it can remove only entries which
// the above code added.
@@ -569,7 +579,7 @@ QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
const QStringList notYetChanged =
- Utils::transform(removeVarValues(profile, lines, valuesToFind, vars),
+ Utils::transform(removeVarValues(profile, lines, valuesToFind, vars, removedLocations),
[values](int i) { return values.at(i); });
if (!profile->fileName().endsWith(".pri"))
@@ -585,7 +595,7 @@ QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
valuesToFind << (prefixPwd + baseDir.relativeFilePath(absoluteFilePath));
const QStringList notChanged =
- Utils::transform(removeVarValues(profile, lines, valuesToFind, vars),
+ Utils::transform(removeVarValues(profile, lines, valuesToFind, vars, removedLocations),
[notYetChanged](int i) { return notYetChanged.at(i); });
return notChanged;
diff --git a/src/shared/proparser/prowriter.h b/src/shared/proparser/prowriter.h
index 31467c0e66..bf19d23bc7 100644
--- a/src/shared/proparser/prowriter.h
+++ b/src/shared/proparser/prowriter.h
@@ -52,13 +52,26 @@ public:
static void putVarValues(ProFile *profile, QStringList *lines,
const QStringList &values, const QString &var, PutFlags flags,
const QString &scope, const QString &continuationIndent);
- static QList<int> removeVarValues(ProFile *profile, QStringList *lines,
- const QStringList &values, const QStringList &vars);
+
+ using VarLocation = QPair<QString, int>;
+ using VarLocations = QList<VarLocation>;
+ static QList<int> removeVarValues(
+ ProFile *profile,
+ QStringList *lines,
+ const QStringList &values,
+ const QStringList &vars,
+ VarLocations *removedLocations = nullptr
+ );
static void addFiles(ProFile *profile, QStringList *lines, const QStringList &filePaths,
const QString &var, const QString &continuationIndent);
- static QStringList removeFiles(ProFile *profile, QStringList *lines,
- const QDir &proFileDir, const QStringList &filePaths, const QStringList &vars);
+ static QStringList removeFiles(
+ ProFile *profile,
+ QStringList *lines,
+ const QDir &proFileDir,
+ const QStringList &filePaths,
+ const QStringList &vars,
+ VarLocations *removedLocations = nullptr);
private:
static bool locateVarValues(const ushort *tokPtr, const ushort *tokPtrEnd,