Make variable manager static.

This makes it follow our preferred singleton pattern.

Change-Id: I230e5ac5ef7f156da7123f7efe3a49bcb6a20669
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Eike Ziller
2013-03-11 11:52:05 +01:00
committed by hjk
parent 3d7163c628
commit e7cb32d621
15 changed files with 70 additions and 76 deletions

View File

@@ -610,5 +610,5 @@ void ExternalToolConfig::addCategory()
void ExternalToolConfig::updateEffectiveArguments()
{
ui->arguments->setToolTip(Utils::QtcProcess::expandMacros(ui->arguments->text(),
Core::VariableManager::instance()->macroExpander()));
Core::VariableManager::macroExpander()));
}

View File

@@ -465,13 +465,12 @@ void EditorManager::init()
d->m_openEditorsFactory = new OpenEditorsViewFactory();
ExtensionSystem::PluginManager::addObject(d->m_openEditorsFactory);
VariableManager *vm = VariableManager::instance();
vm->registerFileVariables(kCurrentDocumentPrefix, tr("Current document"));
vm->registerVariable(kCurrentDocumentXPos,
VariableManager::registerFileVariables(kCurrentDocumentPrefix, tr("Current document"));
VariableManager::registerVariable(kCurrentDocumentXPos,
tr("X-coordinate of the current editor's upper left corner, relative to screen."));
vm->registerVariable(kCurrentDocumentYPos,
VariableManager::registerVariable(kCurrentDocumentYPos,
tr("Y-coordinate of the current editor's upper left corner, relative to screen."));
connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
connect(VariableManager::instance(), SIGNAL(variableUpdateRequested(QByteArray)),
this, SLOT(updateVariable(QByteArray)));
}
@@ -2293,21 +2292,21 @@ void EditorManager::updateVariable(const QByteArray &variable)
if (curEditor) {
QString fileName = curEditor->document()->fileName();
if (!fileName.isEmpty())
value = VariableManager::instance()->fileVariableValue(variable, kCurrentDocumentPrefix,
value = VariableManager::fileVariableValue(variable, kCurrentDocumentPrefix,
fileName);
}
VariableManager::instance()->insert(variable, value);
VariableManager::insert(variable, value);
} 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);
VariableManager::insert(variable, value);
} else if (variable == kCurrentDocumentYPos) {
QString value;
IEditor *curEditor = currentEditor();
if (curEditor)
value = QString::number(curEditor->widget()->mapToGlobal(QPoint(0,0)).y());
VariableManager::instance()->insert(variable, value);
VariableManager::insert(variable, value);
}
}

View File

@@ -556,7 +556,7 @@ bool ExternalToolRunner::resolve()
QStringList expandedExecutables; /* for error message */
foreach (const QString &executable, m_tool->executables()) {
QString expanded = Utils::expandMacros(executable,
Core::VariableManager::instance()->macroExpander());
Core::VariableManager::macroExpander());
expandedExecutables << expanded;
m_resolvedExecutable =
Utils::Environment::systemEnvironment().searchInPath(expanded);
@@ -577,15 +577,15 @@ bool ExternalToolRunner::resolve()
}
{ // arguments
m_resolvedArguments = Utils::QtcProcess::expandMacros(m_tool->arguments(),
Core::VariableManager::instance()->macroExpander());
Core::VariableManager::macroExpander());
}
{ // input
m_resolvedInput = Utils::expandMacros(m_tool->input(),
Core::VariableManager::instance()->macroExpander());
Core::VariableManager::macroExpander());
}
{ // working directory
m_resolvedWorkingDirectory = Utils::expandMacros(m_tool->workingDirectory(),
Core::VariableManager::instance()->macroExpander());
Core::VariableManager::macroExpander());
}
return true;
}

View File

@@ -96,7 +96,7 @@ public:
static EditorManager *editorManager();
static ProgressManager *progressManager();
static ScriptManager *scriptManager();
static VariableManager *variableManager();
static QT_DEPRECATED VariableManager *variableManager(); // Use VariableManager::... directly.
static VcsManager *vcsManager();
static QT_DEPRECATED ModeManager *modeManager(); // Use ModeManager::... directly.
static MimeDatabase *mimeDatabase();

View File

@@ -58,8 +58,7 @@ VariableChooser::VariableChooser(QWidget *parent) :
setFocusPolicy(Qt::StrongFocus);
setFocusProxy(ui->variableList);
VariableManager *vm = VariableManager::instance();
foreach (const QByteArray &variable, vm->variables())
foreach (const QByteArray &variable, VariableManager::variables())
ui->variableList->addItem(QString::fromLatin1(variable));
connect(ui->variableList, SIGNAL(currentTextChanged(QString)),
@@ -82,7 +81,7 @@ void VariableChooser::updateDescription(const QString &variable)
if (variable.isNull())
ui->variableDescription->setText(m_defaultDescription);
else
ui->variableDescription->setText(VariableManager::instance()->variableDescription(variable.toUtf8()));
ui->variableDescription->setText(VariableManager::variableDescription(variable.toUtf8()));
}
void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget)

View File

@@ -53,7 +53,7 @@ public:
virtual bool resolveMacro(const QString &name, QString *ret)
{
bool found;
*ret = Core::VariableManager::instance()->value(name.toUtf8(), &found);
*ret = Core::VariableManager::value(name.toUtf8(), &found);
return found;
}
};
@@ -77,9 +77,12 @@ public:
*/
static VariableManager *variableManagerInstance = 0;
static VariableManagerPrivate *d;
VariableManager::VariableManager() : d(new VariableManagerPrivate)
VariableManager::VariableManager()
{
d = new VariableManagerPrivate;
variableManagerInstance = this;
}
@@ -101,7 +104,7 @@ bool VariableManager::remove(const QByteArray &variable)
QString VariableManager::value(const QByteArray &variable, bool *found)
{
emit variableUpdateRequested(variable);
variableManagerInstance->variableUpdateRequested(variable);
if (found)
*found = d->m_map.contains(variable);
return d->m_map.value(variable);
@@ -158,12 +161,12 @@ QString VariableManager::fileVariableValue(const QByteArray &variable, const QBy
return QString();
}
QList<QByteArray> VariableManager::variables() const
QList<QByteArray> VariableManager::variables()
{
return d->m_descriptions.keys();
}
QString VariableManager::variableDescription(const QByteArray &variable) const
QString VariableManager::variableDescription(const QByteArray &variable)
{
return d->m_descriptions.value(variable);
}

View File

@@ -54,30 +54,27 @@ public:
static VariableManager *instance();
void insert(const QByteArray &variable, const QString &value);
bool remove(const QByteArray &variable);
QString value(const QByteArray &variable, bool *found = 0);
Utils::AbstractMacroExpander *macroExpander();
static void insert(const QByteArray &variable, const QString &value);
static bool remove(const QByteArray &variable);
static QString value(const QByteArray &variable, bool *found = 0);
static Utils::AbstractMacroExpander *macroExpander();
void registerVariable(const QByteArray &variable,
static void registerVariable(const QByteArray &variable,
const QString &description);
void registerFileVariables(const QByteArray &prefix,
static void registerFileVariables(const QByteArray &prefix,
const QString &heading);
bool isFileVariable(const QByteArray &variable, const QByteArray &prefix);
QString fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
static bool isFileVariable(const QByteArray &variable, const QByteArray &prefix);
static QString fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
const QString &fileName);
QString fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
static QString fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
const QFileInfo &fileInfo);
QList<QByteArray> variables() const;
QString variableDescription(const QByteArray &variable) const;
static QList<QByteArray> variables();
static QString variableDescription(const QByteArray &variable);
signals:
void variableUpdateRequested(const QByteArray &variable);
private:
VariableManagerPrivate *d;
};
} // namespace Core

View File

@@ -89,11 +89,10 @@ void ExecuteFilter::accept(FilterEntry selection) const
if (index != 0)
p->m_commandHistory.prepend(value);
VariableManager *vm = Core::VariableManager::instance();
bool found;
QString workingDirectory = vm->value("CurrentDocument:Path", &found);
QString workingDirectory = Core::VariableManager::value("CurrentDocument:Path", &found);
if (!found || workingDirectory.isEmpty())
workingDirectory = vm->value("CurrentProject:Path", &found);
workingDirectory = Core::VariableManager::value("CurrentProject:Path", &found);
ExecuteData d;
d.workingDirectory = workingDirectory;

View File

@@ -73,7 +73,7 @@ bool BuildConfigMacroExpander::resolveMacro(const QString &name, QString *ret)
*ret = QDir::toNativeSeparators(m_bc->buildDirectory());
return true;
}
*ret = Core::VariableManager::instance()->value(name.toUtf8());
*ret = Core::VariableManager::value(name.toUtf8());
return !ret->isEmpty();
}
} // namespace Internal

View File

@@ -57,7 +57,7 @@ Utils::AbstractMacroExpander *LocalApplicationRunConfiguration::macroExpander()
{
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->macroExpander();
return Core::VariableManager::instance()->macroExpander();
return Core::VariableManager::macroExpander();
}
} // namespace ProjectExplorer

View File

@@ -86,7 +86,7 @@ bool ProcessStep::init()
if (!bc)
bc = target()->activeBuildConfiguration();
ProcessParameters *pp = processParameters();
pp->setMacroExpander(bc ? bc->macroExpander() : Core::VariableManager::instance()->macroExpander());
pp->setMacroExpander(bc ? bc->macroExpander() : Core::VariableManager::macroExpander());
pp->setEnvironment(bc ? bc->environment() : Utils::Environment::systemEnvironment());
pp->setWorkingDirectory(workingDirectory());
pp->setCommand(m_command);
@@ -274,7 +274,7 @@ void ProcessStepConfigWidget::updateDetails()
BuildConfiguration *bc = m_step->buildConfiguration();
if (!bc) // iff the step is actually in the deploy list
bc = m_step->target()->activeBuildConfiguration();
param.setMacroExpander(bc ? bc->macroExpander() : Core::VariableManager::instance()->macroExpander());
param.setMacroExpander(bc ? bc->macroExpander() : Core::VariableManager::macroExpander());
param.setEnvironment(bc ? bc->environment() : Utils::Environment::systemEnvironment());
param.setWorkingDirectory(m_step->workingDirectory());

View File

@@ -1004,19 +1004,18 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
updateWelcomePage();
Core::VariableManager *vm = Core::VariableManager::instance();
vm->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, tr("Current project's main file"));
vm->registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH,
Core::VariableManager::registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, tr("Current project's main file"));
Core::VariableManager::registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH,
tr("Full build path of the current project's active build configuration."));
vm->registerVariable(Constants::VAR_CURRENTPROJECT_NAME, tr("The current project's name."));
vm->registerVariable(Constants::VAR_CURRENTKIT_NAME, tr("The currently active kit's name."));
vm->registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
Core::VariableManager::registerVariable(Constants::VAR_CURRENTPROJECT_NAME, tr("The current project's name."));
Core::VariableManager::registerVariable(Constants::VAR_CURRENTKIT_NAME, tr("The currently active kit's name."));
Core::VariableManager::registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
tr("The currently active kit's name in a filesystem friendly version."));
vm->registerVariable(Constants::VAR_CURRENTKIT_ID, tr("The currently active kit's id."));
vm->registerVariable(Constants::VAR_CURRENTBUILD_NAME, tr("The currently active build configuration's name."));
vm->registerVariable(Constants::VAR_CURRENTBUILD_TYPE, tr("The currently active build configuration's type."));
Core::VariableManager::registerVariable(Constants::VAR_CURRENTKIT_ID, tr("The currently active kit's id."));
Core::VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_NAME, tr("The currently active build configuration's name."));
Core::VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_TYPE, tr("The currently active build configuration's type."));
connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QByteArray)),
this, SLOT(updateVariable(QByteArray)));
return true;
@@ -1144,10 +1143,10 @@ void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
{
if (variable == Constants::VAR_CURRENTPROJECT_BUILDPATH) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
Core::VariableManager::instance()->insert(variable,
Core::VariableManager::insert(variable,
currentProject()->activeTarget()->activeBuildConfiguration()->buildDirectory());
} else {
Core::VariableManager::instance()->remove(variable);
Core::VariableManager::remove(variable);
}
} else if (variable == Constants::VAR_CURRENTBUILD_TYPE) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
@@ -1159,9 +1158,9 @@ void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
typeString = tr("release");
else
typeString = tr("unknown");
Core::VariableManager::instance()->insert(variable, typeString);
Core::VariableManager::insert(variable, typeString);
} else {
Core::VariableManager::instance()->remove(variable);
Core::VariableManager::remove(variable);
}
} else {
QString projectName;
@@ -1182,9 +1181,9 @@ void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
ProjectExpander expander(projectFilePath, projectName, kit, buildConfigurationName);
QString result;
if (expander.resolveProjectMacro(QString::fromUtf8(variable), &result))
Core::VariableManager::instance()->insert(variable, result);
Core::VariableManager::insert(variable, result);
else
Core::VariableManager::instance()->remove(variable);
Core::VariableManager::remove(variable);
}
}

View File

@@ -49,10 +49,10 @@ bool ProjectExpander::resolveProjectMacro(const QString &name, QString *ret)
result = m_projectName;
found = true;
}
} else if (Core::VariableManager::instance()->isFileVariable(
} else if (Core::VariableManager::isFileVariable(
name.toUtf8(), ProjectExplorer::Constants::VAR_CURRENTPROJECT_PREFIX)) {
if (!m_projectFile.filePath().isEmpty()) {
result = Core::VariableManager::instance()->fileVariableValue(name.toUtf8(),
result = Core::VariableManager::fileVariableValue(name.toUtf8(),
ProjectExplorer::Constants::VAR_CURRENTPROJECT_PREFIX,
m_projectFile);
found = true;
@@ -79,7 +79,7 @@ bool ProjectExpander::resolveMacro(const QString &name, QString *ret)
{
bool found = resolveProjectMacro(name, ret);
if (!found) {
QString result = Core::VariableManager::instance()->value(name.toUtf8(), &found);
QString result = Core::VariableManager::value(name.toUtf8(), &found);
if (ret)
*ret = result;
}

View File

@@ -90,13 +90,12 @@ bool QtSupportPlugin::initialize(const QStringList &arguments, QString *errorMes
void QtSupportPlugin::extensionsInitialized()
{
Core::VariableManager *vm = Core::VariableManager::instance();
vm->registerVariable(kHostBins,
Core::VariableManager::registerVariable(kHostBins,
tr("Full path to the host bin directory of the current project's Qt version."));
vm->registerVariable(kInstallBins,
Core::VariableManager::registerVariable(kInstallBins,
tr("Full path to the target bin directory of the current project's Qt version."
" You probably want %1 instead.").arg(QString::fromLatin1(kHostBins)));
connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QByteArray)),
this, SLOT(updateVariable(QByteArray)));
QtVersionManager::instance()->extensionsInitialized();

View File

@@ -231,20 +231,19 @@ void TextEditorPlugin::extensionsInitialized()
addAutoReleasedObject(new FindInCurrentFile);
addAutoReleasedObject(new FindInOpenFiles);
Core::VariableManager *vm = Core::VariableManager::instance();
vm->registerVariable(kCurrentDocumentSelection,
Core::VariableManager::registerVariable(kCurrentDocumentSelection,
tr("Selected text within the current document."));
vm->registerVariable(kCurrentDocumentRow,
Core::VariableManager::registerVariable(kCurrentDocumentRow,
tr("Line number of the text cursor position in current document (starts with 1)."));
vm->registerVariable(kCurrentDocumentColumn,
Core::VariableManager::registerVariable(kCurrentDocumentColumn,
tr("Column number of the text cursor position in current document (starts with 0)."));
vm->registerVariable(kCurrentDocumentRowCount,
Core::VariableManager::registerVariable(kCurrentDocumentRowCount,
tr("Number of lines visible in current document."));
vm->registerVariable(kCurrentDocumentColumnCount,
Core::VariableManager::registerVariable(kCurrentDocumentColumnCount,
tr("Number of columns visible in current document."));
vm->registerVariable(kCurrentDocumentFontSize,
Core::VariableManager::registerVariable(kCurrentDocumentFontSize,
tr("Current document's font size in points."));
connect(vm, SIGNAL(variableUpdateRequested(QByteArray)),
connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QByteArray)),
this, SLOT(updateVariable(QByteArray)));
connect(Core::ExternalToolManager::instance(), SIGNAL(replaceSelectionRequested(QString)),
this, SLOT(updateCurrentSelection(QString)));
@@ -313,7 +312,7 @@ void TextEditorPlugin::updateVariable(const QByteArray &variable)
value = QString::number(editor->widget()->font().pointSize());
}
}
Core::VariableManager::instance()->insert(variable, value);
Core::VariableManager::insert(variable, value);
}
}