Differential D1047 Diff 2606 languages/plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp
Changeset View
Changeset View
Standalone View
Standalone View
languages/plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
48 | { | 48 | { | ||
49 | const auto defaultArguments = SettingsManager::globalInstance()->defaultParserArguments(); | 49 | const auto defaultArguments = SettingsManager::globalInstance()->defaultParserArguments(); | ||
50 | 50 | | |||
51 | auto standard = languageStandard(arguments); | 51 | auto standard = languageStandard(arguments); | ||
52 | 52 | | |||
53 | auto tmpArgs(arguments); | 53 | auto tmpArgs(arguments); | ||
54 | tmpArgs.replace(standard, "c++11"); | 54 | tmpArgs.replace(standard, "c++11"); | ||
55 | 55 | | |||
56 | if (tmpArgs == defaultArguments && standards.contains(standard)) { | 56 | if (tmpArgs == defaultArguments.cppArguments && standards.contains(standard)) { | ||
57 | return false; | 57 | return false; | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | return true; | 60 | return true; | ||
61 | } | 61 | } | ||
62 | 62 | | |||
63 | const int customProfileIdx = 0; | 63 | const int customProfileIdx = 0; | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | ParserWidget::ParserWidget(QWidget* parent) | 66 | ParserWidget::ParserWidget(QWidget* parent) | ||
67 | : QWidget(parent) | 67 | : QWidget(parent) | ||
68 | , m_ui(new Ui::ParserWidget()) | 68 | , m_ui(new Ui::ParserWidget()) | ||
69 | { | 69 | { | ||
70 | m_ui->setupUi(this); | 70 | m_ui->setupUi(this); | ||
71 | 71 | | |||
72 | connect(m_ui->parserOptions, &QLineEdit::textEdited, this, &ParserWidget::textEdited); | 72 | connect(m_ui->parserOptionsC, &QLineEdit::textEdited, this, &ParserWidget::textEdited); | ||
73 | connect(m_ui->languageStandards, static_cast<void(QComboBox::*)(const | 73 | connect(m_ui->parserOptionsCpp, &QLineEdit::textEdited, this, &ParserWidget::textEdited); | ||
74 | connect(m_ui->parseHeadersInPlainC, &QCheckBox::stateChanged, this, &ParserWidget::textEdited); | ||||
75 | connect(m_ui->languageStandardsC, static_cast<void(QComboBox::*)(const | ||||
74 | QString&)>(&QComboBox::activated), this, | 76 | QString&)>(&QComboBox::activated), this, | ||
75 | &ParserWidget::languageStandardChanged); | 77 | &ParserWidget::languageStandardChangedC); | ||
78 | connect(m_ui->languageStandardsCpp, static_cast<void(QComboBox::*)(const | ||||
79 | QString&)>(&QComboBox::activated), this, | ||||
80 | &ParserWidget::languageStandardChangedCpp); | ||||
76 | 81 | | |||
77 | updateEnablements(); | 82 | updateEnablements(); | ||
78 | } | 83 | } | ||
79 | 84 | | |||
80 | ParserWidget::~ParserWidget() = default; | 85 | ParserWidget::~ParserWidget() = default; | ||
81 | 86 | | |||
82 | void ParserWidget::textEdited() | 87 | void ParserWidget::textEdited() | ||
83 | { | 88 | { | ||
84 | emit changed(); | 89 | emit changed(); | ||
85 | } | 90 | } | ||
86 | 91 | | |||
87 | void ParserWidget::languageStandardChanged(const QString& standard) | 92 | void ParserWidget::languageStandardChangedC(const QString& standard) | ||
93 | { | ||||
94 | if (m_ui->languageStandardsC->currentIndex() == customProfileIdx) { | ||||
mwolff: using sender() is not so nice, please make this two distinct functions and connect them… | |||||
95 | m_ui->parserOptionsC->setText(SettingsManager::globalInstance()->defaultParserArguments().cArguments); | ||||
96 | } else { | ||||
97 | auto text = SettingsManager::globalInstance()->defaultParserArguments().cArguments; | ||||
98 | auto currentStandard = languageStandard(text); | ||||
99 | m_ui->parserOptionsC->setText(text.replace(currentStandard, standard)); | ||||
100 | } | ||||
101 | | ||||
102 | textEdited(); | ||||
103 | updateEnablements(); | ||||
104 | } | ||||
105 | | ||||
106 | void ParserWidget::languageStandardChangedCpp(const QString& standard) | ||||
88 | { | 107 | { | ||
89 | if (m_ui->languageStandards->currentIndex() == customProfileIdx) { | 108 | if (m_ui->languageStandardsCpp->currentIndex() == customProfileIdx) { | ||
90 | m_ui->parserOptions->setText(SettingsManager::globalInstance()->defaultParserArguments()); | 109 | m_ui->parserOptionsCpp->setText(SettingsManager::globalInstance()->defaultParserArguments().cppArguments); | ||
91 | } else { | 110 | } else { | ||
92 | auto text = SettingsManager::globalInstance()->defaultParserArguments(); | 111 | auto text = SettingsManager::globalInstance()->defaultParserArguments().cppArguments; | ||
93 | auto currentStandard = languageStandard(text); | 112 | auto currentStandard = languageStandard(text); | ||
94 | m_ui->parserOptions->setText(text.replace(currentStandard, standard)); | 113 | m_ui->parserOptionsCpp->setText(text.replace(currentStandard, standard)); | ||
95 | } | 114 | } | ||
96 | 115 | | |||
97 | textEdited(); | 116 | textEdited(); | ||
98 | updateEnablements(); | 117 | updateEnablements(); | ||
99 | } | 118 | } | ||
100 | 119 | | |||
101 | void ParserWidget::setParserArguments(const QString& arguments) | 120 | void ParserWidget::setParserArguments(const ParserArguments& arguments) | ||
102 | { | 121 | { | ||
122 | auto setArguments = [this](QComboBox* languageStandards, QLineEdit* parserOptions, const QString& arguments) { | ||||
103 | QStringList standards; | 123 | QStringList standards; | ||
104 | for (int i = 1; i < m_ui->languageStandards->count(); i++) { | 124 | for (int i = 1; i < languageStandards->count(); i++) { | ||
105 | standards << m_ui->languageStandards->itemText(i); | 125 | standards << languageStandards->itemText(i); | ||
106 | } | 126 | } | ||
107 | 127 | | |||
108 | if (isCustomParserArguments(arguments, standards)) { | 128 | if (isCustomParserArguments(arguments, standards)) { | ||
109 | m_ui->languageStandards->setCurrentIndex(customProfileIdx); | 129 | languageStandards->setCurrentIndex(customProfileIdx); | ||
110 | } else { | 130 | } else { | ||
111 | m_ui->languageStandards->setCurrentText(languageStandard(arguments)); | 131 | languageStandards->setCurrentText(languageStandard(arguments)); | ||
112 | } | 132 | } | ||
113 | 133 | | |||
114 | m_ui->parserOptions->setText(arguments); | 134 | parserOptions->setText(arguments); | ||
135 | }; | ||||
136 | | ||||
137 | setArguments(m_ui->languageStandardsCpp, m_ui->parserOptionsCpp, arguments.cppArguments); | ||||
138 | setArguments(m_ui->languageStandardsC, m_ui->parserOptionsC, arguments.cArguments); | ||||
139 | | ||||
140 | m_ui->parseHeadersInPlainC->setChecked(!arguments.parseAmbiguousAsCPP); | ||||
141 | | ||||
115 | updateEnablements(); | 142 | updateEnablements(); | ||
116 | } | 143 | } | ||
117 | 144 | | |||
118 | QString ParserWidget::parserArguments() const | 145 | ParserArguments ParserWidget::parserArguments() const | ||
119 | { | 146 | { | ||
120 | return m_ui->parserOptions->text(); | 147 | return {m_ui->parserOptionsC->text(), m_ui->parserOptionsCpp->text(), !m_ui->parseHeadersInPlainC->isChecked()}; | ||
121 | } | 148 | } | ||
122 | 149 | | |||
123 | void ParserWidget::updateEnablements() | 150 | void ParserWidget::updateEnablements() | ||
124 | { | 151 | { | ||
125 | if (m_ui->languageStandards->currentIndex() == customProfileIdx) { | 152 | if (m_ui->languageStandardsCpp->currentIndex() == customProfileIdx) { | ||
126 | m_ui->parserOptions->setEnabled(true); | 153 | m_ui->parserOptionsCpp->setEnabled(true); | ||
154 | } else { | ||||
155 | m_ui->parserOptionsCpp->setEnabled(false); | ||||
156 | } | ||||
157 | | ||||
158 | if (m_ui->languageStandardsC->currentIndex() == customProfileIdx) { | ||||
159 | m_ui->parserOptionsC->setEnabled(true); | ||||
127 | } else { | 160 | } else { | ||
128 | m_ui->parserOptions->setEnabled(false); | 161 | m_ui->parserOptionsC->setEnabled(false); | ||
129 | } | 162 | } | ||
130 | } | 163 | } |
using sender() is not so nice, please make this two distinct functions and connect them individually