forked from qt-creator/qt-creator
some ProWriter API cleanup
detach the special handling of files from generic values
This commit is contained in:
@@ -266,7 +266,7 @@ void S60PublisherOvi::updateProFile(const QString &var, const QString &values)
|
|||||||
|
|
||||||
//todo: after ossi has added scope profile writing, make sure the following works
|
//todo: after ossi has added scope profile writing, make sure the following works
|
||||||
//QString scope("symbian");
|
//QString scope("symbian");
|
||||||
ProWriter::addVarValues(profile, &lines, m_qt4project->rootProjectNode()->path(), QStringList() << values, var);
|
ProWriter::addVarValues(profile, &lines, QStringList() << values, var);
|
||||||
|
|
||||||
if (qfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
if (qfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
qfile.write(lines.join("\n").toLocal8Bit());
|
qfile.write(lines.join("\n").toLocal8Bit());
|
||||||
|
@@ -175,17 +175,8 @@ static const ushort *skipToken(ushort tok, const ushort *&tokPtr, int &lineNo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProWriter::addVarValues(ProFile *profile, QStringList *lines,
|
void ProWriter::addVarValues(ProFile *profile, QStringList *lines,
|
||||||
const QDir &proFileDir, const QStringList &values, const QString &var,
|
const QStringList &values, const QString &var)
|
||||||
bool valuesAreFiles)
|
|
||||||
{
|
{
|
||||||
QStringList valuesToWrite;
|
|
||||||
if (valuesAreFiles) {
|
|
||||||
foreach (const QString &v, values)
|
|
||||||
valuesToWrite << proFileDir.relativeFilePath(v);
|
|
||||||
} else {
|
|
||||||
valuesToWrite = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if variable item exists as child of root item
|
// Check if variable item exists as child of root item
|
||||||
const ushort *tokPtr = profile->tokPtr();
|
const ushort *tokPtr = profile->tokPtr();
|
||||||
int lineNo = 0;
|
int lineNo = 0;
|
||||||
@@ -213,7 +204,7 @@ void ProWriter::addVarValues(ProFile *profile, QStringList *lines,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QString added;
|
QString added;
|
||||||
foreach (const QString &v, valuesToWrite)
|
foreach (const QString &v, values)
|
||||||
added += QLatin1String(" ") + v + QLatin1String(" \\\n");
|
added += QLatin1String(" ") + v + QLatin1String(" \\\n");
|
||||||
added.chop(3);
|
added.chop(3);
|
||||||
lines->insert(lineNo, added);
|
lines->insert(lineNo, added);
|
||||||
@@ -227,11 +218,21 @@ void ProWriter::addVarValues(ProFile *profile, QStringList *lines,
|
|||||||
|
|
||||||
// Create & append new variable item
|
// Create & append new variable item
|
||||||
QString added = QLatin1Char('\n') + var + QLatin1String(" +=");
|
QString added = QLatin1Char('\n') + var + QLatin1String(" +=");
|
||||||
foreach (const QString &v, valuesToWrite)
|
foreach (const QString &v, values)
|
||||||
added += QLatin1String(" \\\n ") + v;
|
added += QLatin1String(" \\\n ") + v;
|
||||||
*lines << added;
|
*lines << added;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProWriter::addFiles(ProFile *profile, QStringList *lines,
|
||||||
|
const QDir &proFileDir, const QStringList &values, const QString &var)
|
||||||
|
{
|
||||||
|
QStringList valuesToWrite;
|
||||||
|
foreach (const QString &v, values)
|
||||||
|
valuesToWrite << proFileDir.relativeFilePath(v);
|
||||||
|
|
||||||
|
addVarValues(profile, lines, valuesToWrite, var);
|
||||||
|
}
|
||||||
|
|
||||||
static void findProVariables(const ushort *tokPtr, const QStringList &vars,
|
static void findProVariables(const ushort *tokPtr, const QStringList &vars,
|
||||||
QList<int> *proVars, const uint firstLine = 0)
|
QList<int> *proVars, const uint firstLine = 0)
|
||||||
{
|
{
|
||||||
@@ -256,25 +257,17 @@ static void findProVariables(const ushort *tokPtr, const QStringList &vars,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
||||||
const QDir &proFileDir, const QStringList &values, const QStringList &vars,
|
const QStringList &values, const QStringList &vars)
|
||||||
bool valuesAreFiles)
|
|
||||||
{
|
{
|
||||||
QStringList notChanged = values;
|
QList<int> notChanged;
|
||||||
|
// yeah, this is a bit silly
|
||||||
|
for (int i = 0; i < values.size(); i++)
|
||||||
|
notChanged << i;
|
||||||
|
|
||||||
QList<int> varLines;
|
QList<int> varLines;
|
||||||
findProVariables(profile->tokPtr(), vars, &varLines);
|
findProVariables(profile->tokPtr(), vars, &varLines);
|
||||||
|
|
||||||
QStringList valuesToFind;
|
|
||||||
if (valuesAreFiles) {
|
|
||||||
// This is a tad stupid - basically, it can remove only entries which
|
|
||||||
// the above code added.
|
|
||||||
foreach (const QString &absoluteFilePath, values)
|
|
||||||
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
|
|
||||||
} else {
|
|
||||||
valuesToFind = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This code expects proVars to be sorted by the variables' appearance in the file.
|
// This code expects proVars to be sorted by the variables' appearance in the file.
|
||||||
int delta = 1;
|
int delta = 1;
|
||||||
foreach (int ln, varLines) {
|
foreach (int ln, varLines) {
|
||||||
@@ -326,9 +319,9 @@ QStringList ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
colNo++;
|
colNo++;
|
||||||
}
|
}
|
||||||
const QString fn = line.mid(varCol, colNo - varCol);
|
const QString fn = line.mid(varCol, colNo - varCol);
|
||||||
const int pos = valuesToFind.indexOf(fn);
|
const int pos = values.indexOf(fn);
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
notChanged.removeOne(values.at(pos));
|
notChanged.removeOne(pos);
|
||||||
if (colNo < lineLen)
|
if (colNo < lineLen)
|
||||||
colNo++;
|
colNo++;
|
||||||
else if (varCol)
|
else if (varCol)
|
||||||
@@ -380,3 +373,18 @@ QStringList ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
}
|
}
|
||||||
return notChanged;
|
return notChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
|
||||||
|
const QDir &proFileDir, const QStringList &values, const QStringList &vars)
|
||||||
|
{
|
||||||
|
// This is a tad stupid - basically, it can remove only entries which
|
||||||
|
// the above code added.
|
||||||
|
QStringList valuesToFind;
|
||||||
|
foreach (const QString &absoluteFilePath, values)
|
||||||
|
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
|
||||||
|
|
||||||
|
QStringList notChanged;
|
||||||
|
foreach (int i, removeVarValues(profile, lines, valuesToFind, vars))
|
||||||
|
notChanged.append(values.at(i));
|
||||||
|
return notChanged;
|
||||||
|
}
|
||||||
|
@@ -49,41 +49,15 @@ namespace Internal {
|
|||||||
class ProWriter
|
class ProWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static void addVarValues(ProFile *profile, QStringList *lines,
|
||||||
|
const QStringList &values, const QString &var);
|
||||||
|
static QList<int> removeVarValues(ProFile *profile, QStringList *lines,
|
||||||
|
const QStringList &values, const QStringList &vars);
|
||||||
|
|
||||||
static void addFiles(ProFile *profile, QStringList *lines,
|
static void addFiles(ProFile *profile, QStringList *lines,
|
||||||
const QDir &proFileDir, const QStringList &filePaths, const QString &var)
|
const QDir &proFileDir, const QStringList &filePaths, const QString &var);
|
||||||
{
|
|
||||||
addVarValues(profile, lines, proFileDir, filePaths, var, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QStringList removeFiles(ProFile *profile, QStringList *lines,
|
static QStringList removeFiles(ProFile *profile, QStringList *lines,
|
||||||
const QDir &proFileDir, const QStringList &filePaths,
|
const QDir &proFileDir, const QStringList &filePaths, const QStringList &vars);
|
||||||
const QStringList &vars)
|
|
||||||
{
|
|
||||||
return removeVarValues(profile, lines, proFileDir, filePaths, vars, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void addVarValues(ProFile *profile, QStringList *lines,
|
|
||||||
const QDir &proFileDir, const QStringList &values, const QString &var)
|
|
||||||
{
|
|
||||||
addVarValues(profile, lines, proFileDir, values, var, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QStringList removeVarValues(ProFile *profile, QStringList *lines,
|
|
||||||
const QDir &proFileDir, const QStringList &values,
|
|
||||||
const QStringList &vars)
|
|
||||||
{
|
|
||||||
return removeVarValues(profile, lines, proFileDir, values, vars, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static void addVarValues(ProFile *profile, QStringList *lines,
|
|
||||||
const QDir &proFileDir, const QStringList &values, const QString &var,
|
|
||||||
bool valuesAreFiles);
|
|
||||||
|
|
||||||
static QStringList removeVarValues(ProFile *profile, QStringList *lines,
|
|
||||||
const QDir &proFileDir, const QStringList &values,
|
|
||||||
const QStringList &vars, bool valuesAreFiles);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user