forked from qt-creator/qt-creator
VCS: Allow VcsBaseEditorConfig to operate on aspects
Change-Id: Id7b5b1a1020ea002e631e401c49b8eda6dfb8944 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "vcsbaseeditorconfig.h"
|
#include "vcsbaseeditorconfig.h"
|
||||||
|
|
||||||
|
#include <utils/aspects.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
@@ -34,8 +35,9 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace VcsBase {
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace VcsBase {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class SettingMappingData
|
class SettingMappingData
|
||||||
@@ -46,7 +48,10 @@ public:
|
|||||||
Invalid,
|
Invalid,
|
||||||
Bool,
|
Bool,
|
||||||
String,
|
String,
|
||||||
Int
|
Int,
|
||||||
|
AspectBool,
|
||||||
|
AspectString,
|
||||||
|
AspectInt
|
||||||
};
|
};
|
||||||
|
|
||||||
SettingMappingData() : boolSetting(nullptr)
|
SettingMappingData() : boolSetting(nullptr)
|
||||||
@@ -61,6 +66,15 @@ public:
|
|||||||
SettingMappingData(int *setting) : intSetting(setting), m_type(Int)
|
SettingMappingData(int *setting) : intSetting(setting), m_type(Int)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
SettingMappingData(BoolAspect *setting) : boolAspectSetting(setting), m_type(AspectBool)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
SettingMappingData(StringAspect *setting) : stringAspectSetting(setting), m_type(AspectString)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
SettingMappingData(IntegerAspect *setting) : intAspectSetting(setting), m_type(AspectInt)
|
||||||
|
{ }
|
||||||
|
|
||||||
Type type() const
|
Type type() const
|
||||||
{
|
{
|
||||||
return m_type;
|
return m_type;
|
||||||
@@ -70,6 +84,9 @@ public:
|
|||||||
bool *boolSetting;
|
bool *boolSetting;
|
||||||
QString *stringSetting;
|
QString *stringSetting;
|
||||||
int *intSetting;
|
int *intSetting;
|
||||||
|
BoolAspect *boolAspectSetting;
|
||||||
|
StringAspect *stringAspectSetting;
|
||||||
|
IntegerAspect *intAspectSetting;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -197,6 +214,17 @@ void VcsBaseEditorConfig::mapSetting(QAction *button, bool *setting)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VcsBaseEditorConfig::mapSetting(QAction *button, BoolAspect *setting)
|
||||||
|
{
|
||||||
|
if (!d->m_settingMapping.contains(button) && button) {
|
||||||
|
d->m_settingMapping.insert(button, Internal::SettingMappingData(setting));
|
||||||
|
if (setting) {
|
||||||
|
QSignalBlocker blocker(button);
|
||||||
|
button->setChecked(setting->value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, QString *setting)
|
void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, QString *setting)
|
||||||
{
|
{
|
||||||
if (!d->m_settingMapping.contains(comboBox) && comboBox) {
|
if (!d->m_settingMapping.contains(comboBox) && comboBox) {
|
||||||
@@ -210,6 +238,19 @@ void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, QString *setting)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, StringAspect *setting)
|
||||||
|
{
|
||||||
|
if (!d->m_settingMapping.contains(comboBox) && comboBox) {
|
||||||
|
d->m_settingMapping.insert(comboBox, Internal::SettingMappingData(setting));
|
||||||
|
if (setting) {
|
||||||
|
QSignalBlocker blocker(comboBox);
|
||||||
|
const int itemIndex = comboBox->findData(setting->value());
|
||||||
|
if (itemIndex != -1)
|
||||||
|
comboBox->setCurrentIndex(itemIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, int *setting)
|
void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, int *setting)
|
||||||
{
|
{
|
||||||
if (d->m_settingMapping.contains(comboBox) || !comboBox)
|
if (d->m_settingMapping.contains(comboBox) || !comboBox)
|
||||||
@@ -224,6 +265,20 @@ void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, int *setting)
|
|||||||
comboBox->setCurrentIndex(*setting);
|
comboBox->setCurrentIndex(*setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VcsBaseEditorConfig::mapSetting(QComboBox *comboBox, IntegerAspect *setting)
|
||||||
|
{
|
||||||
|
if (d->m_settingMapping.contains(comboBox) || !comboBox)
|
||||||
|
return;
|
||||||
|
|
||||||
|
d->m_settingMapping.insert(comboBox, Internal::SettingMappingData(setting));
|
||||||
|
|
||||||
|
if (!setting || setting->value() < 0 || setting->value() >= comboBox->count())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QSignalBlocker blocker(comboBox);
|
||||||
|
comboBox->setCurrentIndex(setting->value());
|
||||||
|
}
|
||||||
|
|
||||||
void VcsBaseEditorConfig::handleArgumentsChanged()
|
void VcsBaseEditorConfig::handleArgumentsChanged()
|
||||||
{
|
{
|
||||||
updateMappedSettings();
|
updateMappedSettings();
|
||||||
@@ -287,6 +342,12 @@ void VcsBaseEditorConfig::updateMappedSettings()
|
|||||||
*settingData.boolSetting = action->isChecked();
|
*settingData.boolSetting = action->isChecked();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Internal::SettingMappingData::AspectBool :
|
||||||
|
{
|
||||||
|
if (auto action = qobject_cast<const QAction *>(optMapping.object))
|
||||||
|
settingData.boolAspectSetting->setValue(action->isChecked());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Internal::SettingMappingData::String :
|
case Internal::SettingMappingData::String :
|
||||||
{
|
{
|
||||||
auto cb = qobject_cast<const QComboBox *>(optMapping.object);
|
auto cb = qobject_cast<const QComboBox *>(optMapping.object);
|
||||||
@@ -294,6 +355,13 @@ void VcsBaseEditorConfig::updateMappedSettings()
|
|||||||
*settingData.stringSetting = cb->itemData(cb->currentIndex()).toString();
|
*settingData.stringSetting = cb->itemData(cb->currentIndex()).toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Internal::SettingMappingData::AspectString :
|
||||||
|
{
|
||||||
|
auto cb = qobject_cast<const QComboBox *>(optMapping.object);
|
||||||
|
if (cb && cb->currentIndex() != -1)
|
||||||
|
settingData.stringAspectSetting->setValue(cb->itemData(cb->currentIndex()).toString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Internal::SettingMappingData::Int:
|
case Internal::SettingMappingData::Int:
|
||||||
{
|
{
|
||||||
auto cb = qobject_cast<const QComboBox *>(optMapping.object);
|
auto cb = qobject_cast<const QComboBox *>(optMapping.object);
|
||||||
@@ -301,6 +369,13 @@ void VcsBaseEditorConfig::updateMappedSettings()
|
|||||||
*settingData.intSetting = cb->currentIndex();
|
*settingData.intSetting = cb->currentIndex();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Internal::SettingMappingData::AspectInt:
|
||||||
|
{
|
||||||
|
auto cb = qobject_cast<const QComboBox *>(optMapping.object);
|
||||||
|
if (cb && cb->currentIndex() != -1)
|
||||||
|
settingData.intAspectSetting->setValue(cb->currentIndex());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Internal::SettingMappingData::Invalid : break;
|
case Internal::SettingMappingData::Invalid : break;
|
||||||
} // end switch ()
|
} // end switch ()
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,12 @@ class QComboBox;
|
|||||||
class QToolButton;
|
class QToolButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
class BoolAspect;
|
||||||
|
class IntegerAspect;
|
||||||
|
class StringAspect;
|
||||||
|
} // Utils
|
||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
|
|
||||||
class VcsBaseEditorWidget;
|
class VcsBaseEditorWidget;
|
||||||
@@ -75,6 +81,10 @@ public:
|
|||||||
void mapSetting(QComboBox *comboBox, QString *setting);
|
void mapSetting(QComboBox *comboBox, QString *setting);
|
||||||
void mapSetting(QComboBox *comboBox, int *setting);
|
void mapSetting(QComboBox *comboBox, int *setting);
|
||||||
|
|
||||||
|
void mapSetting(QAction *button, Utils::BoolAspect *setting);
|
||||||
|
void mapSetting(QComboBox *comboBox, Utils::StringAspect *setting);
|
||||||
|
void mapSetting(QComboBox *comboBox, Utils::IntegerAspect *setting);
|
||||||
|
|
||||||
// Return the effective arguments according to setting.
|
// Return the effective arguments according to setting.
|
||||||
virtual QStringList arguments() const;
|
virtual QStringList arguments() const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user