Vcs: in VcsBaseClient use functors to create log/diff parameter widgets

Also API of VcsBaseEditorParameterWidget was changed to take benefit of C++11 lambdas.
Slot executeCommand() is no longer virtual and only fires signal commandExecutionRequested().
The Vcs client just has to bind a lambda to this signal instead of some boiler-plate code
like keeping track of the arguments of diff/log with "struct XxxDiffParameters", etc.

Change-Id: I347c97d84a8324e9c661df4e6d9a6075980b020f
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Hugues Delorme
2015-01-20 17:42:16 +01:00
parent 3956fab1dd
commit 4b5d2ccef7
11 changed files with 157 additions and 321 deletions

View File

@@ -65,59 +65,40 @@ SynchronousProcessResponse::Result CvsDiffExitCodeInterpreter::interpretExitCode
return SynchronousProcessResponse::Finished;
}
// Collect all parameters required for a diff to be able to associate them
// with a diff editor and re-run the diff with parameters.
struct CvsDiffParameters
{
QString workingDir;
QStringList extraOptions;
QStringList files;
};
// Parameter widget controlling whitespace diff mode, associated with a parameter
class CvsDiffParameterWidget : public VcsBaseEditorParameterWidget
{
Q_OBJECT
public:
explicit CvsDiffParameterWidget(CvsClient *client,
const CvsDiffParameters &p,
QWidget *parent = 0);
explicit CvsDiffParameterWidget(CvsSettings *settings, QWidget *parent = 0);
QStringList arguments() const;
void executeCommand();
private:
CvsClient *m_client;
const CvsDiffParameters m_params;
const CvsSettings *m_settings;
};
CvsDiffParameterWidget::CvsDiffParameterWidget(CvsClient *client,
const CvsDiffParameters &p,
QWidget *parent)
: VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
CvsDiffParameterWidget::CvsDiffParameterWidget(CvsSettings *settings, QWidget *parent)
: VcsBaseEditorParameterWidget(parent),
m_settings(settings)
{
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
client->settings()->boolPointer(CvsSettings::diffIgnoreWhiteSpaceKey));
settings->boolPointer(CvsSettings::diffIgnoreWhiteSpaceKey));
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
client->settings()->boolPointer(CvsSettings::diffIgnoreBlankLinesKey));
settings->boolPointer(CvsSettings::diffIgnoreBlankLinesKey));
}
QStringList CvsDiffParameterWidget::arguments() const
{
QStringList args;
args = m_client->settings()->stringValue(CvsSettings::diffOptionsKey).split(QLatin1Char(' '), QString::SkipEmptyParts);
args = m_settings->stringValue(CvsSettings::diffOptionsKey).split(QLatin1Char(' '), QString::SkipEmptyParts);
args += VcsBaseEditorParameterWidget::arguments();
return args;
}
void CvsDiffParameterWidget::executeCommand()
{
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
}
CvsClient::CvsClient(CvsSettings *settings) :
VcsBaseClient(settings)
{
setDiffParameterWidgetCreator([=] { return new CvsDiffParameterWidget(settings); });
}
CvsSettings *CvsClient::settings() const
@@ -169,17 +150,6 @@ VcsBaseClient::StatusItem CvsClient::parseStatusLine(const QString &line) const
return VcsBaseClient::StatusItem();
}
VcsBaseEditorParameterWidget *CvsClient::createDiffEditor(
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
{
Q_UNUSED(extraOptions)
CvsDiffParameters p;
p.workingDir = workingDir;
p.files = files;
p.extraOptions = extraOptions;
return new CvsDiffParameterWidget(this, p);
}
} // namespace Internal
} // namespace Cvs

View File

@@ -53,14 +53,9 @@ public:
QStringList revisionSpec(const QString &revision) const;
StatusItem parseStatusLine(const QString &line) const;
protected:
Utils::ExitCodeInterpreter *exitCodeInterpreter(VcsCommandTag cmd, QObject *parent) const;
Core::Id vcsEditorKind(VcsCommandTag cmd) const;
VcsBase::VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
private:
};
} // namespace Internal