forked from qt-creator/qt-creator
CppTools: Apply new SettingsPage patterns
Change-Id: Id7410041d5813dc3df9aeb650074f961e394cd2d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -36,13 +36,39 @@
|
|||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
using namespace CppTools;
|
namespace CppTools {
|
||||||
using namespace CppTools::Internal;
|
namespace Internal {
|
||||||
|
|
||||||
CppCodeModelSettingsWidget::CppCodeModelSettingsWidget()
|
class CppCodeModelSettingsWidget final : public Core::IOptionsPageWidget
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(CppTools::Internal::CppCodeModelSettingsWidget)
|
||||||
|
|
||||||
|
public:
|
||||||
|
CppCodeModelSettingsWidget(const QSharedPointer<CppCodeModelSettings> &s);
|
||||||
|
~CppCodeModelSettingsWidget() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void apply() final;
|
||||||
|
|
||||||
|
void setupGeneralWidgets();
|
||||||
|
void setupClangCodeModelWidgets();
|
||||||
|
|
||||||
|
bool applyGeneralWidgetsToSettings() const;
|
||||||
|
bool applyClangCodeModelWidgetsToSettings() const;
|
||||||
|
|
||||||
|
Ui::CppCodeModelSettingsPage *m_ui = nullptr;
|
||||||
|
QSharedPointer<CppCodeModelSettings> m_settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
CppCodeModelSettingsWidget::CppCodeModelSettingsWidget(const QSharedPointer<CppCodeModelSettings> &s)
|
||||||
: m_ui(new Ui::CppCodeModelSettingsPage)
|
: m_ui(new Ui::CppCodeModelSettingsPage)
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
m_settings = s;
|
||||||
|
|
||||||
|
setupGeneralWidgets();
|
||||||
|
setupClangCodeModelWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCodeModelSettingsWidget::~CppCodeModelSettingsWidget()
|
CppCodeModelSettingsWidget::~CppCodeModelSettingsWidget()
|
||||||
@@ -50,15 +76,7 @@ CppCodeModelSettingsWidget::~CppCodeModelSettingsWidget()
|
|||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCodeModelSettingsWidget::setSettings(const QSharedPointer<CppCodeModelSettings> &s)
|
void CppCodeModelSettingsWidget::apply()
|
||||||
{
|
|
||||||
m_settings = s;
|
|
||||||
|
|
||||||
setupGeneralWidgets();
|
|
||||||
setupClangCodeModelWidgets();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppCodeModelSettingsWidget::applyToSettings() const
|
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
@@ -160,31 +178,14 @@ bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
CppCodeModelSettingsPage::CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings)
|
CppCodeModelSettingsPage::CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings)
|
||||||
: m_settings(settings)
|
|
||||||
{
|
{
|
||||||
setId(Constants::CPP_CODE_MODEL_SETTINGS_ID);
|
setId(Constants::CPP_CODE_MODEL_SETTINGS_ID);
|
||||||
setDisplayName(QCoreApplication::translate("CppTools",Constants::CPP_CODE_MODEL_SETTINGS_NAME));
|
setDisplayName(CppCodeModelSettingsWidget::tr("Code Model"));
|
||||||
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
||||||
setDisplayCategory(QCoreApplication::translate("CppTools", "C++"));
|
setDisplayCategory(QCoreApplication::translate("CppTools", "C++"));
|
||||||
setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png");
|
setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png");
|
||||||
|
setWidgetCreator([settings] { return new CppCodeModelSettingsWidget(settings); });
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *CppCodeModelSettingsPage::widget()
|
} // Internal
|
||||||
{
|
} // CppTools
|
||||||
if (!m_widget) {
|
|
||||||
m_widget = new CppCodeModelSettingsWidget;
|
|
||||||
m_widget->setSettings(m_settings);
|
|
||||||
}
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppCodeModelSettingsPage::apply()
|
|
||||||
{
|
|
||||||
if (m_widget)
|
|
||||||
m_widget->applyToSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppCodeModelSettingsPage::finish()
|
|
||||||
{
|
|
||||||
delete m_widget;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -30,52 +30,14 @@
|
|||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QComboBox)
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QSettings)
|
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
namespace Ui { class CppCodeModelSettingsPage; }
|
class CppCodeModelSettingsPage final : public Core::IOptionsPage
|
||||||
|
|
||||||
class CppCodeModelSettingsWidget: public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
CppCodeModelSettingsWidget();
|
|
||||||
~CppCodeModelSettingsWidget() override;
|
|
||||||
|
|
||||||
void setSettings(const QSharedPointer<CppCodeModelSettings> &s);
|
|
||||||
void applyToSettings() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setupGeneralWidgets();
|
|
||||||
void setupClangCodeModelWidgets();
|
|
||||||
|
|
||||||
bool applyGeneralWidgetsToSettings() const;
|
|
||||||
bool applyClangCodeModelWidgetsToSettings() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::CppCodeModelSettingsPage *m_ui = nullptr;
|
|
||||||
QSharedPointer<CppCodeModelSettings> m_settings;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CppCodeModelSettingsPage: public Core::IOptionsPage
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings);
|
explicit CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings);
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const QSharedPointer<CppCodeModelSettings> m_settings;
|
|
||||||
QPointer<CppCodeModelSettingsWidget> m_widget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal namespace
|
} // Internal namespace
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ const char CPP_CODE_STYLE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code
|
|||||||
const char CPP_FILE_SETTINGS_ID[] = "B.Cpp.File Naming";
|
const char CPP_FILE_SETTINGS_ID[] = "B.Cpp.File Naming";
|
||||||
const char CPP_FILE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "File Naming");
|
const char CPP_FILE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "File Naming");
|
||||||
const char CPP_CODE_MODEL_SETTINGS_ID[] = "C.Cpp.Code Model";
|
const char CPP_CODE_MODEL_SETTINGS_ID[] = "C.Cpp.Code Model";
|
||||||
const char CPP_CODE_MODEL_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code Model");
|
|
||||||
const char CPP_DIAGNOSTIC_CONFIG_SETTINGS_ID[] = "C.Cpp.Diagnostic Config";
|
const char CPP_DIAGNOSTIC_CONFIG_SETTINGS_ID[] = "C.Cpp.Diagnostic Config";
|
||||||
const char CPP_DIAGNOSTIC_CONFIG_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Diagnostic Configurations");
|
const char CPP_DIAGNOSTIC_CONFIG_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Diagnostic Configurations");
|
||||||
const char CPP_SETTINGS_CATEGORY[] = "I.C++";
|
const char CPP_SETTINGS_CATEGORY[] = "I.C++";
|
||||||
|
|||||||
Reference in New Issue
Block a user