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

@@ -53,9 +53,25 @@ using namespace VcsBase;
namespace Mercurial {
namespace Internal {
// Parameter widget controlling whitespace diff mode, associated with a parameter
class MercurialDiffParameterWidget : public VcsBaseEditorParameterWidget
{
Q_OBJECT
public:
MercurialDiffParameterWidget(MercurialSettings *settings, QWidget *parent = 0) :
VcsBaseEditorParameterWidget(parent)
{
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
settings->boolPointer(MercurialSettings::diffIgnoreWhiteSpaceKey));
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
settings->boolPointer(MercurialSettings::diffIgnoreBlankLinesKey));
}
};
MercurialClient::MercurialClient(MercurialSettings *settings) :
VcsBaseClient(settings)
{
setDiffParameterWidgetCreator([=] { return new MercurialDiffParameterWidget(settings); });
}
MercurialSettings *MercurialClient::settings() const
@@ -414,50 +430,6 @@ void MercurialClient::parsePullOutput(const QString &output)
emit needMerge();
}
// 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 MercurialDiffParameters
{
QString workingDir;
QStringList files;
QStringList extraOptions;
};
// Parameter widget controlling whitespace diff mode, associated with a parameter
class MercurialDiffParameterWidget : public VcsBaseEditorParameterWidget
{
Q_OBJECT
public:
MercurialDiffParameterWidget(MercurialClient *client,
const MercurialDiffParameters &p, QWidget *parent = 0) :
VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
{
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
client->settings()->boolPointer(MercurialSettings::diffIgnoreWhiteSpaceKey));
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
client->settings()->boolPointer(MercurialSettings::diffIgnoreBlankLinesKey));
}
void executeCommand()
{
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
}
private:
MercurialClient *m_client;
const MercurialDiffParameters m_params;
};
VcsBaseEditorParameterWidget *MercurialClient::createDiffEditor(
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
{
MercurialDiffParameters parameters;
parameters.workingDir = workingDir;
parameters.files = files;
parameters.extraOptions = extraOptions;
return new MercurialDiffParameterWidget(this, parameters);
}
} // namespace Internal
} // namespace Mercurial