summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2011-12-21 11:29:35 +0100
committerhjk <qthjk@ovi.com>2012-01-10 23:55:48 +0100
commit443e77a47db1c2923be9907ed7c8b01deec3f702 (patch)
treec354c6ae8a39c38b933aa1a2859e451c2c038590 /src/plugins
parent6571e01725718a6a7edea18b60e1c29a7c885b54 (diff)
downloadqt-creator-443e77a47db1c2923be9907ed7c8b01deec3f702.tar.gz
Use QByteArray for variable names.
Less conversions, tighter code, less to type. Change-Id: I38eb27ca17e6f1d98cdbc41fa003cbedf0f0bb34 Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp25
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.h2
-rw-r--r--src/plugins/coreplugin/variablechooser.cpp5
-rw-r--r--src/plugins/coreplugin/variablemanager.cpp30
-rw-r--r--src/plugins/coreplugin/variablemanager.h16
-rw-r--r--src/plugins/locator/executefilter.cpp4
-rw-r--r--src/plugins/projectexplorer/applicationrunconfiguration.cpp2
-rw-r--r--src/plugins/projectexplorer/buildconfiguration.cpp2
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp14
-rw-r--r--src/plugins/projectexplorer/projectexplorer.h2
-rw-r--r--src/plugins/qt4projectmanager/qt4projectmanager.cpp14
-rw-r--r--src/plugins/qt4projectmanager/qt4projectmanager.h2
-rw-r--r--src/plugins/texteditor/texteditorplugin.cpp44
-rw-r--r--src/plugins/texteditor/texteditorplugin.h2
14 files changed, 86 insertions, 78 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 9a4c4356ce..bbccef7cce 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -509,16 +509,16 @@ void EditorManager::init()
pluginManager()->addObject(d->m_openEditorsFactory);
VariableManager *vm = VariableManager::instance();
- vm->registerVariable(QLatin1String(kCurrentDocumentFilePath),
+ vm->registerVariable(kCurrentDocumentFilePath,
tr("Full path of the current document including file name."));
- vm->registerVariable(QLatin1String(kCurrentDocumentPath),
+ vm->registerVariable(kCurrentDocumentPath,
tr("Full path of the current document excluding file name."));
- vm->registerVariable(QLatin1String(kCurrentDocumentXPos),
+ vm->registerVariable(kCurrentDocumentXPos,
tr("X-coordinate of the current editor's upper left corner, relative to screen."));
- vm->registerVariable(QLatin1String(kCurrentDocumentYPos),
+ vm->registerVariable(kCurrentDocumentYPos,
tr("Y-coordinate of the current editor's upper left corner, relative to screen."));
- connect(vm, SIGNAL(variableUpdateRequested(QString)),
- this, SLOT(updateVariable(QString)));
+ connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
+ this, SLOT(updateVariable(QByteArray)));
}
void EditorManager::updateAutoSave()
@@ -2211,29 +2211,28 @@ QString EditorManager::windowTitleAddition() const
return d->m_titleAddition;
}
-void EditorManager::updateVariable(const QString &variable)
+void EditorManager::updateVariable(const QByteArray &variable)
{
- if (variable == QLatin1String(kCurrentDocumentFilePath)
- || variable == QLatin1String(kCurrentDocumentPath)) {
+ if (variable == kCurrentDocumentFilePath || variable == kCurrentDocumentPath) {
QString value;
IEditor *curEditor = currentEditor();
if (curEditor) {
QString fileName = curEditor->file()->fileName();
if (!fileName.isEmpty()) {
- if (variable == QLatin1String(kCurrentDocumentFilePath))
+ if (variable == kCurrentDocumentFilePath)
value = QFileInfo(fileName).filePath();
- else if (variable == QLatin1String(kCurrentDocumentPath))
+ else if (variable == kCurrentDocumentPath)
value = QFileInfo(fileName).path();
}
}
VariableManager::instance()->insert(variable, value);
- } else if (variable == QLatin1String(kCurrentDocumentXPos)) {
+ } else if (variable == kCurrentDocumentXPos) {
QString value;
IEditor *curEditor = currentEditor();
if (curEditor)
value = QString::number(curEditor->widget()->mapToGlobal(QPoint(0,0)).x());
VariableManager::instance()->insert(variable, value);
- } else if (variable == QLatin1String(kCurrentDocumentYPos)) {
+ } else if (variable == kCurrentDocumentYPos) {
QString value;
IEditor *curEditor = currentEditor();
if (curEditor)
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index f7a48bc5f6..5368a98f5a 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -218,7 +218,7 @@ private slots:
void vcsOpenCurrentEditor();
void updateWindowTitle();
void handleEditorStateChange();
- void updateVariable(const QString &variable);
+ void updateVariable(const QByteArray &variable);
void autoSave();
void closeEditorFromContextMenu();
diff --git a/src/plugins/coreplugin/variablechooser.cpp b/src/plugins/coreplugin/variablechooser.cpp
index 03501af7d1..546b0d58fd 100644
--- a/src/plugins/coreplugin/variablechooser.cpp
+++ b/src/plugins/coreplugin/variablechooser.cpp
@@ -62,9 +62,8 @@ VariableChooser::VariableChooser(QWidget *parent) :
setFocusProxy(ui->variableList);
VariableManager *vm = VariableManager::instance();
- foreach (const QString &variable, vm->variables()) {
+ foreach (const QByteArray &variable, vm->variables())
ui->variableList->addItem(variable);
- }
connect(ui->variableList, SIGNAL(currentTextChanged(QString)),
this, SLOT(updateDescription(QString)));
@@ -86,7 +85,7 @@ void VariableChooser::updateDescription(const QString &variable)
if (variable.isNull())
ui->variableDescription->setText(m_defaultDescription);
else
- ui->variableDescription->setText(VariableManager::instance()->variableDescription(variable));
+ ui->variableDescription->setText(VariableManager::instance()->variableDescription(variable.toUtf8()));
}
void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget)
diff --git a/src/plugins/coreplugin/variablemanager.cpp b/src/plugins/coreplugin/variablemanager.cpp
index 4cb7826a4a..93da641bd2 100644
--- a/src/plugins/coreplugin/variablemanager.cpp
+++ b/src/plugins/coreplugin/variablemanager.cpp
@@ -51,7 +51,7 @@ public:
virtual bool resolveMacro(const QString &name, QString *ret)
{
bool found;
- *ret = Core::VariableManager::instance()->value(name, &found);
+ *ret = Core::VariableManager::instance()->value(name.toUtf8(), &found);
return found;
}
};
@@ -59,11 +59,21 @@ public:
class VariableManagerPrivate
{
public:
- QHash<QString, QString> m_map;
+ QHash<QByteArray, QString> m_map;
VMMapExpander m_macroExpander;
- QMap<QString, QString> m_descriptions;
+ QMap<QByteArray, QString> m_descriptions;
};
+/*!
+ \class Core::VariableManager
+ \brief The VaraiableManager class holds a generic map from variable names
+ to string values.
+
+ The names of the variables are stored as QByteArray. They are typically
+ 7-bit-clean. In cases where this is not possible, Latin-1 encoding is
+ assumed.
+*/
+
static VariableManager *variableManagerInstance = 0;
VariableManager::VariableManager() : d(new VariableManagerPrivate)
@@ -77,17 +87,17 @@ VariableManager::~VariableManager()
delete d;
}
-void VariableManager::insert(const QString &variable, const QString &value)
+void VariableManager::insert(const QByteArray &variable, const QString &value)
{
d->m_map.insert(variable, value);
}
-bool VariableManager::remove(const QString &variable)
+bool VariableManager::remove(const QByteArray &variable)
{
return d->m_map.remove(variable) > 0;
}
-QString VariableManager::value(const QString &variable, bool *found)
+QString VariableManager::value(const QByteArray &variable, bool *found)
{
emit variableUpdateRequested(variable);
if (found) {
@@ -96,7 +106,7 @@ QString VariableManager::value(const QString &variable, bool *found)
return d->m_map.value(variable);
}
-QString VariableManager::value(const QString &variable, const QString &defaultValue)
+QString VariableManager::value(const QByteArray &variable, const QString &defaultValue)
{
emit variableUpdateRequested(variable);
return d->m_map.value(variable, defaultValue);
@@ -112,17 +122,17 @@ VariableManager *VariableManager::instance()
return variableManagerInstance;
}
-void VariableManager::registerVariable(const QString &variable, const QString &description)
+void VariableManager::registerVariable(const QByteArray &variable, const QString &description)
{
d->m_descriptions.insert(variable, description);
}
-QList<QString> VariableManager::variables() const
+QList<QByteArray> VariableManager::variables() const
{
return d->m_descriptions.keys();
}
-QString VariableManager::variableDescription(const QString &variable) const
+QString VariableManager::variableDescription(const QByteArray &variable) const
{
return d->m_descriptions.value(variable);
}
diff --git a/src/plugins/coreplugin/variablemanager.h b/src/plugins/coreplugin/variablemanager.h
index 0baeaf9067..863097378a 100644
--- a/src/plugins/coreplugin/variablemanager.h
+++ b/src/plugins/coreplugin/variablemanager.h
@@ -56,19 +56,19 @@ public:
static VariableManager *instance();
- void insert(const QString &variable, const QString &value);
- bool remove(const QString &variable);
- QString value(const QString &variable, bool *found = 0);
- QString value(const QString &variable, const QString &defaultValue);
+ void insert(const QByteArray &variable, const QString &value);
+ bool remove(const QByteArray &variable);
+ QString value(const QByteArray &variable, bool *found = 0);
+ QString value(const QByteArray &variable, const QString &defaultValue);
Utils::AbstractMacroExpander *macroExpander();
- void registerVariable(const QString &variable,
+ void registerVariable(const QByteArray &variable,
const QString &description);
- QList<QString> variables() const;
- QString variableDescription(const QString &variable) const;
+ QList<QByteArray> variables() const;
+ QString variableDescription(const QByteArray &variable) const;
signals:
- void variableUpdateRequested(const QString &variable);
+ void variableUpdateRequested(const QByteArray &variable);
private:
VariableManagerPrivate *d;
diff --git a/src/plugins/locator/executefilter.cpp b/src/plugins/locator/executefilter.cpp
index c1bad10c88..a6cc078ac6 100644
--- a/src/plugins/locator/executefilter.cpp
+++ b/src/plugins/locator/executefilter.cpp
@@ -92,9 +92,9 @@ void ExecuteFilter::accept(FilterEntry selection) const
VariableManager *vm = Core::VariableManager::instance();
bool found;
- QString workingDirectory = vm->value(QLatin1String("CurrentDocument:Path"), &found);
+ QString workingDirectory = vm->value("CurrentDocument:Path", &found);
if (!found || workingDirectory.isEmpty())
- workingDirectory = vm->value(QLatin1String("CurrentProject:Path"), &found);
+ workingDirectory = vm->value("CurrentProject:Path", &found);
ExecuteData d;
d.workingDirectory = workingDirectory;
diff --git a/src/plugins/projectexplorer/applicationrunconfiguration.cpp b/src/plugins/projectexplorer/applicationrunconfiguration.cpp
index 301ef5fa45..2064069f74 100644
--- a/src/plugins/projectexplorer/applicationrunconfiguration.cpp
+++ b/src/plugins/projectexplorer/applicationrunconfiguration.cpp
@@ -61,7 +61,7 @@ class VarManMacroExpander : public Utils::AbstractQtcMacroExpander {
public:
virtual bool resolveMacro(const QString &name, QString *ret)
{
- *ret = Core::VariableManager::instance()->value(name);
+ *ret = Core::VariableManager::instance()->value(name.toUtf8());
return !ret->isEmpty();
}
};
diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp
index 3f94a892d0..e576ce0a5c 100644
--- a/src/plugins/projectexplorer/buildconfiguration.cpp
+++ b/src/plugins/projectexplorer/buildconfiguration.cpp
@@ -74,7 +74,7 @@ bool BuildConfigMacroExpander::resolveMacro(const QString &name, QString *ret)
*ret = QDir::toNativeSeparators(m_bc->buildDirectory());
return true;
}
- *ret = Core::VariableManager::instance()->value(name);
+ *ret = Core::VariableManager::instance()->value(name.toUtf8());
return !ret->isEmpty();
}
} // namespace Internal
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index dc09f00bac..751665d735 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -1005,12 +1005,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
updateWelcomePage();
Core::VariableManager *vm = Core::VariableManager::instance();
- vm->registerVariable(QLatin1String(kCurrentProjectFilePath),
+ vm->registerVariable(kCurrentProjectFilePath,
tr("Full path of the current project's main file, including file name."));
- vm->registerVariable(QLatin1String(kCurrentProjectPath),
+ vm->registerVariable(kCurrentProjectPath,
tr("Full path of the current project's main file, excluding file name."));
- connect(vm, SIGNAL(variableUpdateRequested(QString)),
- this, SLOT(updateVariable(QString)));
+ connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
+ this, SLOT(updateVariable(QByteArray)));
return true;
}
@@ -1129,16 +1129,16 @@ void ProjectExplorerPlugin::loadCustomWizards()
}
}
-void ProjectExplorerPlugin::updateVariable(const QString &variable)
+void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
{
- if (variable == QLatin1String(kCurrentProjectFilePath)) {
+ if (variable == kCurrentProjectFilePath) {
if (currentProject() && currentProject()->file()) {
Core::VariableManager::instance()->insert(variable,
currentProject()->file()->fileName());
} else {
Core::VariableManager::instance()->remove(variable);
}
- } else if (variable == QLatin1String(kCurrentProjectPath)) {
+ } else if (variable == kCurrentProjectPath) {
if (currentProject() && currentProject()->file()) {
Core::VariableManager::instance()->insert(variable,
QFileInfo(currentProject()->file()->fileName()).path());
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index 5faad029b8..672e29e2cd 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -223,7 +223,7 @@ private slots:
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode);
void updateActions();
void loadCustomWizards();
- void updateVariable(const QString &variable);
+ void updateVariable(const QByteArray &variable);
void updateRunWithoutDeployMenu();
void publishProject();
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.cpp b/src/plugins/qt4projectmanager/qt4projectmanager.cpp
index c27c4f0dfb..552be42ff2 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.cpp
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.cpp
@@ -137,10 +137,10 @@ void Qt4Manager::init()
this, SLOT(editorChanged(Core::IEditor*)));
Core::VariableManager *vm = Core::VariableManager::instance();
- vm->registerVariable(QLatin1String(kInstallBins),
+ vm->registerVariable(kInstallBins,
tr("Full path to the bin/ install directory of the current project's Qt version."));
- connect(vm, SIGNAL(variableUpdateRequested(QString)),
- this, SLOT(updateVariable(QString)));
+ connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
+ this, SLOT(updateVariable(QByteArray)));
}
void Qt4Manager::editorChanged(Core::IEditor *editor)
@@ -182,19 +182,19 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor)
}
}
-void Qt4Manager::updateVariable(const QString &variable)
+void Qt4Manager::updateVariable(const QByteArray &variable)
{
- if (variable == QLatin1String(kInstallBins)) {
+ if (variable == kInstallBins) {
Qt4Project *qt4pro = qobject_cast<Qt4Project *>(projectExplorer()->currentProject());
if (!qt4pro) {
- Core::VariableManager::instance()->remove(QLatin1String(kInstallBins));
+ Core::VariableManager::instance()->remove(kInstallBins);
return;
}
QString value;
QtSupport::BaseQtVersion *qtv = qt4pro->activeTarget()->activeQt4BuildConfiguration()->qtVersion();
if (qtv)
value = qtv->versionInfo().value(QLatin1String("QT_INSTALL_BINS"));
- Core::VariableManager::instance()->insert(QLatin1String(kInstallBins), value);
+ Core::VariableManager::instance()->insert(kInstallBins, value);
}
}
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.h b/src/plugins/qt4projectmanager/qt4projectmanager.h
index 573559c6a4..0ff3176169 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.h
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.h
@@ -109,7 +109,7 @@ private slots:
void editorAboutToClose(Core::IEditor *editor);
void uiEditorContentsChanged();
void editorChanged(Core::IEditor*);
- void updateVariable(const QString &variable);
+ void updateVariable(const QByteArray &variable);
private:
QList<Qt4Project *> m_projects;
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index dc987b2caa..c27ef13d93 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -185,20 +185,20 @@ void TextEditorPlugin::extensionsInitialized()
addAutoReleasedObject(new FindInCurrentFile);
Core::VariableManager *vm = Core::VariableManager::instance();
- vm->registerVariable(QLatin1String(kCurrentDocumentSelection),
+ vm->registerVariable(kCurrentDocumentSelection,
tr("Selected text within the current document."));
- vm->registerVariable(QLatin1String(kCurrentDocumentRow),
+ vm->registerVariable(kCurrentDocumentRow,
tr("Line number of the text cursor position in current document (starts with 1)."));
- vm->registerVariable(QLatin1String(kCurrentDocumentColumn),
+ vm->registerVariable(kCurrentDocumentColumn,
tr("Column number of the text cursor position in current document (starts with 0)."));
- vm->registerVariable(QLatin1String(kCurrentDocumentRowCount),
+ vm->registerVariable(kCurrentDocumentRowCount,
tr("Number of lines visible in current document."));
- vm->registerVariable(QLatin1String(kCurrentDocumentColumnCount),
+ vm->registerVariable(kCurrentDocumentColumnCount,
tr("Number of columns visible in current document."));
- vm->registerVariable(QLatin1String(kCurrentDocumentFontSize),
+ vm->registerVariable(kCurrentDocumentFontSize,
tr("Current document's font size in points."));
- connect(vm, SIGNAL(variableUpdateRequested(QString)),
- this, SLOT(updateVariable(QString)));
+ connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
+ this, SLOT(updateVariable(QByteArray)));
connect(Core::ExternalToolManager::instance(), SIGNAL(replaceSelectionRequested(QString)),
this, SLOT(updateCurrentSelection(QString)));
}
@@ -232,32 +232,32 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings)
settings.fontSize() * settings.fontZoom() / 100));
}
-void TextEditorPlugin::updateVariable(const QString &variable)
+void TextEditorPlugin::updateVariable(const QByteArray &variable)
{
- static QSet<QString> variables = QSet<QString>()
- << QString::fromLatin1(kCurrentDocumentSelection)
- << QString::fromLatin1(kCurrentDocumentRow)
- << QString::fromLatin1(kCurrentDocumentColumn)
- << QString::fromLatin1(kCurrentDocumentRowCount)
- << QString::fromLatin1(kCurrentDocumentColumnCount)
- << QString::fromLatin1(kCurrentDocumentFontSize);
+ static QSet<QByteArray> variables = QSet<QByteArray>()
+ << kCurrentDocumentSelection
+ << kCurrentDocumentRow
+ << kCurrentDocumentColumn
+ << kCurrentDocumentRowCount
+ << kCurrentDocumentColumnCount
+ << kCurrentDocumentFontSize;
if (variables.contains(variable)) {
QString value;
Core::IEditor *iface = Core::EditorManager::instance()->currentEditor();
ITextEditor *editor = qobject_cast<ITextEditor *>(iface);
if (editor) {
- if (variable == QLatin1String(kCurrentDocumentSelection)) {
+ if (variable == kCurrentDocumentSelection) {
value = editor->selectedText();
value.replace(QChar::ParagraphSeparator, QLatin1String("\n"));
- } else if (variable == QLatin1String(kCurrentDocumentRow)) {
+ } else if (variable == kCurrentDocumentRow) {
value = QString::number(editor->currentLine());
- } else if (variable == QLatin1String(kCurrentDocumentColumn)) {
+ } else if (variable == kCurrentDocumentColumn) {
value = QString::number(editor->currentColumn());
- } else if (variable == QLatin1String(kCurrentDocumentRowCount)) {
+ } else if (variable == kCurrentDocumentRowCount) {
value = QString::number(editor->rowCount());
- } else if (variable == QLatin1String(kCurrentDocumentColumnCount)) {
+ } else if (variable == kCurrentDocumentColumnCount) {
value = QString::number(editor->columnCount());
- } else if (variable == QLatin1String(kCurrentDocumentFontSize)) {
+ } else if (variable == kCurrentDocumentFontSize) {
value = QString::number(editor->widget()->font().pointSize());
}
}
diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h
index 20b5e0d59f..9a220a18ff 100644
--- a/src/plugins/texteditor/texteditorplugin.h
+++ b/src/plugins/texteditor/texteditorplugin.h
@@ -75,7 +75,7 @@ private slots:
void invokeCompletion();
void invokeQuickFix();
void updateSearchResultsFont(const TextEditor::FontSettings &);
- void updateVariable(const QString &variable);
+ void updateVariable(const QByteArray &variable);
void updateCurrentSelection(const QString &text);
private: