forked from qt-creator/qt-creator
Use QByteArray for variable names.
Less conversions, tighter code, less to type. Change-Id: I38eb27ca17e6f1d98cdbc41fa003cbedf0f0bb34 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user