forked from qt-creator/qt-creator
VCS: Replace QToolButtons in VCS toolbar with QActions
Change VcsBaseEditorParameterWidget to add actions/widgets to an existing toolbar, instead of being a widget itself. The class is renamed in a follow-up commit. Task-number: QTCREATORBUG-14934 Change-Id: I473a439d12a096f4cbb64f06faa0598ee72000de Reviewed-by: Tobias Hunger <tobias.hunger@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
6cd68d5401
commit
2c6adc1e74
@@ -50,8 +50,8 @@ class BazaarDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BazaarDiffParameterWidget(VcsBaseClientSettings &settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
BazaarDiffParameterWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
settings.boolPointer(BazaarSettings::diffIgnoreWhiteSpaceKey));
|
||||
@@ -77,8 +77,8 @@ class BazaarLogParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BazaarLogParameterWidget(VcsBaseClientSettings &settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
BazaarLogParameterWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"),
|
||||
tr("Show files changed in each revision.")),
|
||||
@@ -102,8 +102,12 @@ public:
|
||||
|
||||
BazaarClient::BazaarClient() : VcsBaseClient(new BazaarSettings)
|
||||
{
|
||||
setDiffParameterWidgetCreator([this] { return new BazaarDiffParameterWidget(settings()); });
|
||||
setLogParameterWidgetCreator([this] { return new BazaarLogParameterWidget(settings()); });
|
||||
setDiffParameterWidgetCreator([this](QToolBar *toolBar) {
|
||||
return new BazaarDiffParameterWidget(settings(), toolBar);
|
||||
});
|
||||
setLogParameterWidgetCreator([this](QToolBar *toolBar) {
|
||||
return new BazaarLogParameterWidget(settings(), toolBar);
|
||||
});
|
||||
}
|
||||
|
||||
bool BazaarClient::synchronousSetUserId()
|
||||
|
@@ -47,16 +47,15 @@ class CvsDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CvsDiffParameterWidget(VcsBaseClientSettings &settings, QWidget *parent = 0);
|
||||
CvsDiffParameterWidget(VcsBaseClientSettings &settings, QToolBar *toolBar);
|
||||
QStringList arguments() const;
|
||||
|
||||
private:
|
||||
VcsBaseClientSettings &m_settings;
|
||||
};
|
||||
|
||||
CvsDiffParameterWidget::CvsDiffParameterWidget(VcsBaseClientSettings &settings,
|
||||
QWidget *parent) :
|
||||
VcsBaseEditorParameterWidget(parent),
|
||||
CvsDiffParameterWidget::CvsDiffParameterWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar),
|
||||
m_settings(settings)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
@@ -76,7 +75,9 @@ QStringList CvsDiffParameterWidget::arguments() const
|
||||
|
||||
CvsClient::CvsClient() : VcsBaseClient(new CvsSettings)
|
||||
{
|
||||
setDiffParameterWidgetCreator([this] { return new CvsDiffParameterWidget(settings()); });
|
||||
setDiffParameterWidgetCreator([this](QToolBar *toolBar) {
|
||||
return new CvsDiffParameterWidget(settings(), toolBar);
|
||||
});
|
||||
}
|
||||
|
||||
CvsSettings &CvsClient::settings() const
|
||||
|
@@ -394,8 +394,8 @@ class BaseGitDiffArgumentsWidget : public VcsBaseEditorParameterWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BaseGitDiffArgumentsWidget(VcsBaseClientSettings &settings, QWidget *parent = nullptr) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
BaseGitDiffArgumentsWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar)
|
||||
{
|
||||
m_patienceButton
|
||||
= addToggleButton("--patience", tr("Patience"),
|
||||
@@ -408,8 +408,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
QToolButton *m_patienceButton;
|
||||
QToolButton *m_ignoreWSButton;
|
||||
QAction *m_patienceButton;
|
||||
QAction *m_ignoreWSButton;
|
||||
};
|
||||
|
||||
class GitBlameArgumentsWidget : public VcsBaseEditorParameterWidget
|
||||
@@ -417,8 +417,8 @@ class GitBlameArgumentsWidget : public VcsBaseEditorParameterWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GitBlameArgumentsWidget(VcsBaseClientSettings &settings, QWidget *parent = nullptr) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
GitBlameArgumentsWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar)
|
||||
{
|
||||
mapSetting(addToggleButton(QString(), tr("Omit Date"),
|
||||
tr("Hide the date of a change from the output.")),
|
||||
@@ -434,21 +434,21 @@ class GitLogArgumentsWidget : public BaseGitDiffArgumentsWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GitLogArgumentsWidget(VcsBaseClientSettings &settings, QWidget *parent = nullptr) :
|
||||
BaseGitDiffArgumentsWidget(settings, parent)
|
||||
GitLogArgumentsWidget(VcsBaseClientSettings &settings, QToolBar *toolBar = nullptr) :
|
||||
BaseGitDiffArgumentsWidget(settings, toolBar)
|
||||
{
|
||||
QToolButton *diffButton = addToggleButton("--patch", tr("Show Diff"),
|
||||
QAction *diffButton = addToggleButton("--patch", tr("Show Diff"),
|
||||
tr("Show difference."));
|
||||
mapSetting(diffButton, settings.boolPointer(GitSettings::logDiffKey));
|
||||
connect(diffButton, &QToolButton::toggled, m_patienceButton, &QToolButton::setVisible);
|
||||
connect(diffButton, &QToolButton::toggled, m_ignoreWSButton, &QToolButton::setVisible);
|
||||
connect(diffButton, &QAction::toggled, m_patienceButton, &QAction::setVisible);
|
||||
connect(diffButton, &QAction::toggled, m_ignoreWSButton, &QAction::setVisible);
|
||||
m_patienceButton->setVisible(diffButton->isChecked());
|
||||
m_ignoreWSButton->setVisible(diffButton->isChecked());
|
||||
const QStringList graphArguments = {
|
||||
"--graph", "--oneline", "--topo-order",
|
||||
QLatin1String("--pretty=format:") + graphLogFormatC
|
||||
};
|
||||
QToolButton *graphButton = addToggleButton(graphArguments, tr("Graph"),
|
||||
QAction *graphButton = addToggleButton(graphArguments, tr("Graph"),
|
||||
tr("Show textual graph log."));
|
||||
mapSetting(graphButton, settings.boolPointer(GitSettings::graphLogKey));
|
||||
}
|
||||
@@ -813,7 +813,7 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||
QString msgArg;
|
||||
if (!fileName.isEmpty())
|
||||
msgArg = fileName;
|
||||
else if (!args.isEmpty())
|
||||
else if (!args.isEmpty() && !args.first().startsWith('-'))
|
||||
msgArg = args.first();
|
||||
else
|
||||
msgArg = workingDirectory;
|
||||
@@ -824,11 +824,14 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||
const QString sourceFile = VcsBaseEditor::getSource(workingDir, fileName);
|
||||
VcsBaseEditorWidget *editor = createVcsEditor(editorId, title, sourceFile,
|
||||
codecFor(CodecLogOutput), "logTitle", msgArg);
|
||||
if (!editor->configurationWidget()) {
|
||||
auto *argWidget = new GitLogArgumentsWidget(settings());
|
||||
QStringList effectiveArgs = args;
|
||||
if (!editor->configurationAdded()) {
|
||||
auto *argWidget = new GitLogArgumentsWidget(settings(), editor->toolBar());
|
||||
argWidget->setBaseArguments(args);
|
||||
connect(argWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=]() { this->log(workingDir, fileName, enableAnnotationContextMenu, args); });
|
||||
editor->setConfigurationWidget(argWidget);
|
||||
[=]() { this->log(workingDir, fileName, enableAnnotationContextMenu, argWidget->arguments()); });
|
||||
effectiveArgs = argWidget->arguments();
|
||||
editor->setConfigurationAdded();
|
||||
}
|
||||
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
|
||||
editor->setWorkingDirectory(workingDir);
|
||||
@@ -838,11 +841,7 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||
if (logCount > 0)
|
||||
arguments << "-n" << QString::number(logCount);
|
||||
|
||||
auto *argWidget = editor->configurationWidget();
|
||||
argWidget->setBaseArguments(args);
|
||||
QStringList userArgs = argWidget->arguments();
|
||||
|
||||
arguments.append(userArgs);
|
||||
arguments.append(effectiveArgs);
|
||||
|
||||
if (!fileName.isEmpty())
|
||||
arguments << "--follow" << "--" << fileName;
|
||||
@@ -911,21 +910,22 @@ VcsBaseEditorWidget *GitClient::annotate(
|
||||
VcsBaseEditorWidget *editor
|
||||
= createVcsEditor(editorId, title, sourceFile, codecFor(CodecSource, sourceFile),
|
||||
"blameFileName", id);
|
||||
if (!editor->configurationWidget()) {
|
||||
auto *argWidget = new GitBlameArgumentsWidget(settings());
|
||||
QStringList effectiveArgs = extraOptions;
|
||||
if (!editor->configurationAdded()) {
|
||||
auto *argWidget = new GitBlameArgumentsWidget(settings(), editor->toolBar());
|
||||
argWidget->setBaseArguments(extraOptions);
|
||||
connect(argWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] {
|
||||
const int line = VcsBaseEditor::lineNumberOfCurrentEditor();
|
||||
annotate(workingDir, file, revision, line, extraOptions);
|
||||
annotate(workingDir, file, revision, line, argWidget->arguments());
|
||||
} );
|
||||
editor->setConfigurationWidget(argWidget);
|
||||
effectiveArgs = argWidget->arguments();
|
||||
editor->setConfigurationAdded();
|
||||
}
|
||||
|
||||
editor->setWorkingDirectory(workingDir);
|
||||
QStringList arguments = { "blame", "--root" };
|
||||
arguments << editor->configurationWidget()->arguments();
|
||||
arguments << "--" << file;
|
||||
arguments << effectiveArgs << "--" << file;
|
||||
if (!revision.isEmpty())
|
||||
arguments << revision;
|
||||
vcsExec(workingDir, arguments, editor, false, 0, lineNumber);
|
||||
|
@@ -54,8 +54,8 @@ class MercurialDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MercurialDiffParameterWidget(VcsBaseClientSettings &settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
MercurialDiffParameterWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
settings.boolPointer(MercurialSettings::diffIgnoreWhiteSpaceKey));
|
||||
@@ -66,7 +66,9 @@ public:
|
||||
|
||||
MercurialClient::MercurialClient() : VcsBaseClient(new MercurialSettings)
|
||||
{
|
||||
setDiffParameterWidgetCreator([this] { return new MercurialDiffParameterWidget(settings()); });
|
||||
setDiffParameterWidgetCreator([this](QToolBar *toolBar) {
|
||||
return new MercurialDiffParameterWidget(settings(), toolBar);
|
||||
});
|
||||
}
|
||||
|
||||
bool MercurialClient::manifestSync(const QString &repository, const QString &relativeFilename)
|
||||
|
@@ -1199,7 +1199,7 @@ class PerforceDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PerforceDiffParameterWidget(const PerforceDiffParameters &p, QWidget *parent = 0);
|
||||
explicit PerforceDiffParameterWidget(const PerforceDiffParameters &p, QToolBar *toolBar);
|
||||
void triggerReRun();
|
||||
|
||||
signals:
|
||||
@@ -1209,8 +1209,9 @@ private:
|
||||
const PerforceDiffParameters m_parameters;
|
||||
};
|
||||
|
||||
PerforceDiffParameterWidget::PerforceDiffParameterWidget(const PerforceDiffParameters &p, QWidget *parent) :
|
||||
VcsBaseEditorParameterWidget(parent), m_parameters(p)
|
||||
PerforceDiffParameterWidget::PerforceDiffParameterWidget(const PerforceDiffParameters &p,
|
||||
QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar), m_parameters(p)
|
||||
{
|
||||
setBaseArguments(p.diffArguments);
|
||||
addToggleButton(QLatin1String("w"), tr("Ignore Whitespace"));
|
||||
@@ -1269,12 +1270,12 @@ void PerforcePlugin::p4Diff(const PerforceDiffParameters &p)
|
||||
auto diffEditorWidget = qobject_cast<VcsBaseEditorWidget *>(editor->widget());
|
||||
// Wire up the parameter widget to trigger a re-run on
|
||||
// parameter change and 'revert' from inside the diff editor.
|
||||
auto pw = new PerforceDiffParameterWidget(p);
|
||||
auto pw = new PerforceDiffParameterWidget(p, diffEditorWidget->toolBar());
|
||||
connect(pw, &PerforceDiffParameterWidget::reRunDiff,
|
||||
this, [this](const PerforceDiffParameters &p) { p4Diff(p); });
|
||||
connect(diffEditorWidget, &VcsBaseEditorWidget::diffChunkReverted,
|
||||
pw, &PerforceDiffParameterWidget::triggerReRun);
|
||||
diffEditorWidget->setConfigurationWidget(pw);
|
||||
diffEditorWidget->setConfigurationAdded();
|
||||
}
|
||||
|
||||
void PerforcePlugin::describe(const QString & source, const QString &n)
|
||||
|
@@ -56,8 +56,8 @@ class SubversionLogParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SubversionLogParameterWidget(VcsBaseClientSettings &settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
SubversionLogParameterWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
|
||||
VcsBaseEditorParameterWidget(toolBar)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"),
|
||||
tr("Show files changed in each revision")),
|
||||
@@ -67,7 +67,9 @@ public:
|
||||
|
||||
SubversionClient::SubversionClient() : VcsBaseClient(new SubversionSettings)
|
||||
{
|
||||
setLogParameterWidgetCreator([this] { return new SubversionLogParameterWidget(settings()); });
|
||||
setLogParameterWidgetCreator([this](QToolBar *toolBar) {
|
||||
return new SubversionLogParameterWidget(settings(), toolBar);
|
||||
});
|
||||
}
|
||||
|
||||
VcsCommand *SubversionClient::createCommitCmd(const QString &repositoryRoot,
|
||||
|
@@ -7269,6 +7269,11 @@ void TextEditorWidget::setCursorPosition(int pos)
|
||||
setTextCursor(tc);
|
||||
}
|
||||
|
||||
QToolBar *TextEditorWidget::toolBar()
|
||||
{
|
||||
return d->m_toolBar;
|
||||
}
|
||||
|
||||
void BaseTextEditor::select(int toPos)
|
||||
{
|
||||
editorWidget()->setBlockSelection(false);
|
||||
|
@@ -190,6 +190,7 @@ public:
|
||||
using QPlainTextEdit::cursorRect;
|
||||
QRect cursorRect(int pos) const;
|
||||
void setCursorPosition(int pos);
|
||||
QToolBar *toolBar();
|
||||
|
||||
void print(QPrinter *);
|
||||
|
||||
|
@@ -270,21 +270,21 @@ void VcsBaseClientImpl::saveSettings()
|
||||
class VcsBaseClientPrivate
|
||||
{
|
||||
public:
|
||||
VcsBaseEditorParameterWidget *createDiffEditor();
|
||||
VcsBaseEditorParameterWidget *createLogEditor();
|
||||
VcsBaseEditorParameterWidget *createDiffEditor(VcsBaseEditorWidget *editor);
|
||||
VcsBaseEditorParameterWidget *createLogEditor(VcsBaseEditorWidget *editor);
|
||||
|
||||
VcsBaseClient::ParameterWidgetCreator m_diffParamWidgetCreator;
|
||||
VcsBaseClient::ParameterWidgetCreator m_logParamWidgetCreator;
|
||||
};
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createDiffEditor()
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createDiffEditor(VcsBaseEditorWidget *editor)
|
||||
{
|
||||
return m_diffParamWidgetCreator ? m_diffParamWidgetCreator() : 0;
|
||||
return m_diffParamWidgetCreator ? m_diffParamWidgetCreator(editor->toolBar()) : 0;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createLogEditor()
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createLogEditor(VcsBaseEditorWidget *editor)
|
||||
{
|
||||
return m_logParamWidgetCreator ? m_logParamWidgetCreator() : 0;
|
||||
return m_logParamWidgetCreator ? m_logParamWidgetCreator(editor->toolBar()) : 0;
|
||||
}
|
||||
|
||||
VcsBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) :
|
||||
@@ -425,19 +425,21 @@ void VcsBaseClient::diff(const QString &workingDir, const QStringList &files,
|
||||
vcsCmdString.toLatin1().constData(), id);
|
||||
editor->setWorkingDirectory(workingDir);
|
||||
|
||||
VcsBaseEditorParameterWidget *paramWidget = editor->configurationWidget();
|
||||
if (!paramWidget && (paramWidget = d->createDiffEditor())) {
|
||||
QStringList effectiveArgs = extraOptions;
|
||||
if (!editor->configurationAdded()) {
|
||||
if (VcsBaseEditorParameterWidget *paramWidget = d->createDiffEditor(editor)) {
|
||||
// editor has been just created, createVcsEditor() didn't set a configuration widget yet
|
||||
connect(editor, &VcsBaseEditorWidget::diffChunkReverted,
|
||||
paramWidget, &VcsBaseEditorParameterWidget::executeCommand);
|
||||
connect(paramWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] { diff(workingDir, files, extraOptions); } );
|
||||
editor->setConfigurationWidget(paramWidget);
|
||||
[=] { diff(workingDir, files, extraOptions + paramWidget->arguments()); } );
|
||||
effectiveArgs = paramWidget->arguments();
|
||||
editor->setConfigurationAdded();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList args;
|
||||
const QStringList paramArgs = paramWidget != 0 ? paramWidget->arguments() : QStringList();
|
||||
args << vcsCmdString << extraOptions << paramArgs << files;
|
||||
args << vcsCmdString << effectiveArgs << files;
|
||||
QTextCodec *codec = source.isEmpty() ? static_cast<QTextCodec *>(0) : VcsBaseEditor::getCodec(source);
|
||||
VcsCommand *command = createCommand(workingDir, editor);
|
||||
command->setCodec(codec);
|
||||
@@ -458,17 +460,20 @@ void VcsBaseClient::log(const QString &workingDir, const QStringList &files,
|
||||
vcsCmdString.toLatin1().constData(), id);
|
||||
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
|
||||
|
||||
VcsBaseEditorParameterWidget *paramWidget = editor->configurationWidget();
|
||||
if (!paramWidget && (paramWidget = d->createLogEditor())) {
|
||||
QStringList effectiveArgs = extraOptions;
|
||||
if (!editor->configurationAdded()) {
|
||||
if (VcsBaseEditorParameterWidget *paramWidget = d->createLogEditor(editor)) {
|
||||
// editor has been just created, createVcsEditor() didn't set a configuration widget yet
|
||||
connect(paramWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=]() { this->log(workingDir, files, extraOptions, enableAnnotationContextMenu); } );
|
||||
editor->setConfigurationWidget(paramWidget);
|
||||
[=]() { this->log(workingDir, files, extraOptions + paramWidget->arguments(),
|
||||
enableAnnotationContextMenu); } );
|
||||
effectiveArgs = paramWidget->arguments();
|
||||
editor->setConfigurationAdded();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList args;
|
||||
const QStringList paramArgs = paramWidget != 0 ? paramWidget->arguments() : QStringList();
|
||||
args << vcsCmdString << extraOptions << paramArgs << files;
|
||||
args << vcsCmdString << effectiveArgs << files;
|
||||
enqueueJob(createCommand(workingDir, editor), args);
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,7 @@
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QFileInfo;
|
||||
class QProcessEnvironment;
|
||||
class QToolBar;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core { class Id; }
|
||||
@@ -223,7 +224,7 @@ protected:
|
||||
|
||||
virtual QStringList revisionSpec(const QString &revision) const = 0;
|
||||
|
||||
typedef std::function<VcsBaseEditorParameterWidget *()> ParameterWidgetCreator;
|
||||
typedef std::function<VcsBaseEditorParameterWidget *(QToolBar *)> ParameterWidgetCreator;
|
||||
void setDiffParameterWidgetCreator(ParameterWidgetCreator creator);
|
||||
void setLogParameterWidgetCreator(ParameterWidgetCreator creator);
|
||||
|
||||
|
@@ -565,7 +565,7 @@ public:
|
||||
QString m_annotateRevisionTextFormat;
|
||||
QString m_annotatePreviousRevisionTextFormat;
|
||||
QString m_copyRevisionTextFormat;
|
||||
VcsBaseEditorParameterWidget *m_configurationWidget = nullptr;
|
||||
bool m_configurationAdded = false;
|
||||
QList<AbstractTextCursorHandler *> m_textCursorHandlers;
|
||||
QPointer<VcsCommand> m_command;
|
||||
QObject *m_describeReceiver = nullptr;
|
||||
@@ -1390,20 +1390,14 @@ QString VcsBaseEditor::getTitleId(const QString &workingDirectory,
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool VcsBaseEditorWidget::setConfigurationWidget(VcsBaseEditorParameterWidget *w)
|
||||
void VcsBaseEditorWidget::setConfigurationAdded()
|
||||
{
|
||||
if (d->m_configurationWidget)
|
||||
return false;
|
||||
|
||||
d->m_configurationWidget = w;
|
||||
insertExtraToolBarWidget(TextEditorWidget::Right, w);
|
||||
|
||||
return true;
|
||||
d->m_configurationAdded = true;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseEditorWidget::configurationWidget() const
|
||||
bool VcsBaseEditorWidget::configurationAdded() const
|
||||
{
|
||||
return d->m_configurationWidget;
|
||||
return d->m_configurationAdded;
|
||||
}
|
||||
|
||||
void VcsBaseEditorWidget::setCommand(VcsCommand *command)
|
||||
|
@@ -209,8 +209,8 @@ public:
|
||||
|
||||
EditorContentType contentType() const;
|
||||
|
||||
bool setConfigurationWidget(VcsBaseEditorParameterWidget *w);
|
||||
VcsBaseEditorParameterWidget *configurationWidget() const;
|
||||
void setConfigurationAdded();
|
||||
bool configurationAdded() const;
|
||||
|
||||
void setCommand(VcsCommand *command);
|
||||
|
||||
|
@@ -26,7 +26,7 @@
|
||||
#include "vcsbaseeditorparameterwidget.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QToolButton>
|
||||
#include <QAction>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include <QStringList>
|
||||
@@ -77,14 +77,18 @@ private:
|
||||
class VcsBaseEditorParameterWidgetPrivate
|
||||
{
|
||||
public:
|
||||
VcsBaseEditorParameterWidgetPrivate() :
|
||||
m_layout(0)
|
||||
{ }
|
||||
VcsBaseEditorParameterWidgetPrivate(QToolBar *toolBar) : m_toolBar(toolBar)
|
||||
{
|
||||
if (!toolBar)
|
||||
return;
|
||||
toolBar->setContentsMargins(3, 0, 3, 0);
|
||||
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
}
|
||||
|
||||
QStringList m_baseArguments;
|
||||
QHBoxLayout *m_layout;
|
||||
QList<VcsBaseEditorParameterWidget::OptionMapping> m_optionMappings;
|
||||
QHash<QWidget*, SettingMappingData> m_settingMapping;
|
||||
QHash<QObject *, SettingMappingData> m_settingMapping;
|
||||
QToolBar *m_toolBar;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
@@ -92,11 +96,10 @@ public:
|
||||
/*!
|
||||
\class VcsBase::VcsBaseEditorParameterWidget
|
||||
|
||||
\brief The VcsBaseEditorParameterWidget is a toolbar-like widget for use
|
||||
with VcsBase::VcsBaseEditor::setConfigurationWidget()
|
||||
influencing for example the generation of VCS diff output.
|
||||
\brief The VcsBaseEditorParameterWidget is a widget/action aggregator for use
|
||||
with VcsBase::VcsBaseEditor, influencing for example the generation of VCS diff output.
|
||||
|
||||
The widget maintains a list of command line arguments (starting from baseArguments())
|
||||
The class maintains a list of command line arguments (starting from baseArguments())
|
||||
which are set according to the state of the inside widgets. A change signal is provided
|
||||
that should trigger the rerun of the VCS operation.
|
||||
*/
|
||||
@@ -108,12 +111,9 @@ VcsBaseEditorParameterWidget::ComboBoxItem::ComboBoxItem(const QString &text,
|
||||
{
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget::VcsBaseEditorParameterWidget(QWidget *parent) :
|
||||
QWidget(parent), d(new Internal::VcsBaseEditorParameterWidgetPrivate)
|
||||
VcsBaseEditorParameterWidget::VcsBaseEditorParameterWidget(QToolBar *toolBar) :
|
||||
QObject(toolBar), d(new Internal::VcsBaseEditorParameterWidgetPrivate(toolBar))
|
||||
{
|
||||
d->m_layout = new QHBoxLayout(this);
|
||||
d->m_layout->setContentsMargins(3, 0, 3, 0);
|
||||
d->m_layout->setSpacing(2);
|
||||
connect(this, &VcsBaseEditorParameterWidget::argumentsChanged,
|
||||
this, &VcsBaseEditorParameterWidget::handleArgumentsChanged);
|
||||
}
|
||||
@@ -142,23 +142,26 @@ QStringList VcsBaseEditorParameterWidget::arguments() const
|
||||
return args;
|
||||
}
|
||||
|
||||
QToolButton *VcsBaseEditorParameterWidget::addToggleButton(const QString &option,
|
||||
QAction *VcsBaseEditorParameterWidget::addToggleButton(const QString &option,
|
||||
const QString &label,
|
||||
const QString &tooltip)
|
||||
{
|
||||
return addToggleButton(option.isEmpty() ? QStringList() : QStringList(option), label, tooltip);
|
||||
}
|
||||
|
||||
QToolButton *VcsBaseEditorParameterWidget::addToggleButton(const QStringList &options, const QString &label, const QString &tooltip)
|
||||
QAction *VcsBaseEditorParameterWidget::addToggleButton(const QStringList &options,
|
||||
const QString &label,
|
||||
const QString &tooltip)
|
||||
{
|
||||
auto tb = new QToolButton;
|
||||
tb->setText(label);
|
||||
tb->setToolTip(tooltip);
|
||||
tb->setCheckable(true);
|
||||
connect(tb, &QToolButton::toggled, this, &VcsBaseEditorParameterWidget::argumentsChanged);
|
||||
d->m_layout->addWidget(tb);
|
||||
d->m_optionMappings.append(OptionMapping(options, tb));
|
||||
return tb;
|
||||
auto action = new QAction(label, d->m_toolBar);
|
||||
action->setToolTip(tooltip);
|
||||
action->setCheckable(true);
|
||||
connect(action, &QAction::toggled, this, &VcsBaseEditorParameterWidget::argumentsChanged);
|
||||
const QList<QAction *> actions = d->m_toolBar->actions();
|
||||
// Insert the action before line/column and split actions.
|
||||
d->m_toolBar->insertAction(actions.at(qMax(actions.count() - 2, 0)), action);
|
||||
d->m_optionMappings.append(OptionMapping(options, action));
|
||||
return action;
|
||||
}
|
||||
|
||||
QComboBox *VcsBaseEditorParameterWidget::addComboBox(const QStringList &options,
|
||||
@@ -169,12 +172,12 @@ QComboBox *VcsBaseEditorParameterWidget::addComboBox(const QStringList &options,
|
||||
cb->addItem(item.displayText, item.value);
|
||||
connect(cb, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &VcsBaseEditorParameterWidget::argumentsChanged);
|
||||
d->m_layout->addWidget(cb);
|
||||
d->m_toolBar->addWidget(cb);
|
||||
d->m_optionMappings.append(OptionMapping(options, cb));
|
||||
return cb;
|
||||
}
|
||||
|
||||
void VcsBaseEditorParameterWidget::mapSetting(QToolButton *button, bool *setting)
|
||||
void VcsBaseEditorParameterWidget::mapSetting(QAction *button, bool *setting)
|
||||
{
|
||||
if (!d->m_settingMapping.contains(button) && button) {
|
||||
d->m_settingMapping.insert(button, Internal::SettingMappingData(setting));
|
||||
@@ -226,16 +229,16 @@ void VcsBaseEditorParameterWidget::executeCommand()
|
||||
emit commandExecutionRequested();
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping(const QString &option, QWidget *w) :
|
||||
widget(w)
|
||||
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping(const QString &option, QObject *obj) :
|
||||
object(obj)
|
||||
{
|
||||
if (!option.isEmpty())
|
||||
options << option;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping(const QStringList &optionList, QWidget *w) :
|
||||
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping(const QStringList &optionList, QObject *obj) :
|
||||
options(optionList),
|
||||
widget(w)
|
||||
object(obj)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -246,11 +249,11 @@ const QList<VcsBaseEditorParameterWidget::OptionMapping> &VcsBaseEditorParameter
|
||||
|
||||
QStringList VcsBaseEditorParameterWidget::argumentsForOption(const OptionMapping &mapping) const
|
||||
{
|
||||
const QToolButton *tb = qobject_cast<const QToolButton *>(mapping.widget);
|
||||
if (tb && tb->isChecked())
|
||||
const QAction *action = qobject_cast<const QAction *>(mapping.object);
|
||||
if (action && action->isChecked())
|
||||
return mapping.options;
|
||||
|
||||
const QComboBox *cb = qobject_cast<const QComboBox *>(mapping.widget);
|
||||
const QComboBox *cb = qobject_cast<const QComboBox *>(mapping.object);
|
||||
if (cb) {
|
||||
const QString value = cb->itemData(cb->currentIndex()).toString();
|
||||
QStringList args;
|
||||
@@ -265,26 +268,25 @@ QStringList VcsBaseEditorParameterWidget::argumentsForOption(const OptionMapping
|
||||
void VcsBaseEditorParameterWidget::updateMappedSettings()
|
||||
{
|
||||
foreach (const OptionMapping &optMapping, d->m_optionMappings) {
|
||||
if (d->m_settingMapping.contains(optMapping.widget)) {
|
||||
Internal::SettingMappingData& settingData = d->m_settingMapping[optMapping.widget];
|
||||
if (d->m_settingMapping.contains(optMapping.object)) {
|
||||
Internal::SettingMappingData& settingData = d->m_settingMapping[optMapping.object];
|
||||
switch (settingData.type()) {
|
||||
case Internal::SettingMappingData::Bool :
|
||||
{
|
||||
const QToolButton *tb = qobject_cast<const QToolButton *>(optMapping.widget);
|
||||
if (tb)
|
||||
*settingData.boolSetting = tb->isChecked();
|
||||
if (auto action = qobject_cast<const QAction *>(optMapping.object))
|
||||
*settingData.boolSetting = action->isChecked();
|
||||
break;
|
||||
}
|
||||
case Internal::SettingMappingData::String :
|
||||
{
|
||||
const QComboBox *cb = qobject_cast<const QComboBox *>(optMapping.widget);
|
||||
const QComboBox *cb = qobject_cast<const QComboBox *>(optMapping.object);
|
||||
if (cb && cb->currentIndex() != -1)
|
||||
*settingData.stringSetting = cb->itemData(cb->currentIndex()).toString();
|
||||
break;
|
||||
}
|
||||
case Internal::SettingMappingData::Int:
|
||||
{
|
||||
const QComboBox *cb = qobject_cast<const QComboBox *>(optMapping.widget);
|
||||
const QComboBox *cb = qobject_cast<const QComboBox *>(optMapping.object);
|
||||
if (cb && cb->currentIndex() != -1)
|
||||
*settingData.intSetting = cb->currentIndex();
|
||||
break;
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#include "vcsbase_global.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
#include <QToolBar>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
@@ -38,15 +38,17 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace VcsBase {
|
||||
|
||||
class VcsBaseEditorWidget;
|
||||
|
||||
namespace Internal { class VcsBaseEditorParameterWidgetPrivate; }
|
||||
|
||||
// Documentation->inside.
|
||||
class VCSBASE_EXPORT VcsBaseEditorParameterWidget : public QWidget
|
||||
class VCSBASE_EXPORT VcsBaseEditorParameterWidget : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VcsBaseEditorParameterWidget(QWidget *parent = 0);
|
||||
explicit VcsBaseEditorParameterWidget(QToolBar *toolBar);
|
||||
~VcsBaseEditorParameterWidget() override;
|
||||
|
||||
class VCSBASE_EXPORT ComboBoxItem
|
||||
@@ -61,13 +63,13 @@ public:
|
||||
QStringList baseArguments() const;
|
||||
void setBaseArguments(const QStringList &);
|
||||
|
||||
QToolButton *addToggleButton(const QString &option, const QString &label,
|
||||
QAction *addToggleButton(const QString &option, const QString &label,
|
||||
const QString &tooltip = QString());
|
||||
QToolButton *addToggleButton(const QStringList &options, const QString &label,
|
||||
QAction *addToggleButton(const QStringList &options, const QString &label,
|
||||
const QString &tooltip = QString());
|
||||
QComboBox *addComboBox(const QStringList &options, const QList<ComboBoxItem> &items);
|
||||
|
||||
void mapSetting(QToolButton *button, bool *setting);
|
||||
void mapSetting(QAction *button, bool *setting);
|
||||
void mapSetting(QComboBox *comboBox, QString *setting);
|
||||
void mapSetting(QComboBox *comboBox, int *setting);
|
||||
|
||||
@@ -89,10 +91,10 @@ protected:
|
||||
{
|
||||
public:
|
||||
OptionMapping() = default;
|
||||
OptionMapping(const QString &option, QWidget *w);
|
||||
OptionMapping(const QStringList &optionList, QWidget *w);
|
||||
OptionMapping(const QString &option, QObject *obj);
|
||||
OptionMapping(const QStringList &optionList, QObject *obj);
|
||||
QStringList options;
|
||||
QWidget *widget = nullptr;
|
||||
QObject *object = nullptr;
|
||||
};
|
||||
|
||||
const QList<OptionMapping> &optionMappings() const;
|
||||
|
Reference in New Issue
Block a user