File indexing completed on 2024-05-05 04:39:18
0001 /* 0002 SPDX-FileCopyrightText: 2018 Anton Anikin <anton@anikin.xyz> 0003 SPDX-FileCopyrightText: 2020 Friedrich W. H. Kossebau <kossebau@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "projectconfigpage.h" 0009 0010 // plugin 0011 #include "checksdb.h" 0012 #include "plugin.h" 0013 #include "globalsettings.h" 0014 #include "projectsettings.h" 0015 #include "checksetselectionmanager.h" 0016 // KDevPlatform 0017 #include <interfaces/iproject.h> 0018 // KF 0019 #include <KLocalizedString> 0020 #include <KShell> 0021 0022 namespace Clazy 0023 { 0024 0025 ProjectConfigPage::ProjectConfigPage(Plugin* plugin, KDevelop::IProject* project, 0026 CheckSetSelectionManager* checkSetSelectionManager, 0027 QWidget* parent) 0028 : ConfigPage(plugin, nullptr, parent) 0029 , m_checkSetSelections(checkSetSelectionManager->checkSetSelections()) 0030 , m_defaultCheckSetSelectionId(checkSetSelectionManager->defaultCheckSetSelectionId()) 0031 { 0032 Q_ASSERT(plugin); 0033 0034 m_settings = new ProjectSettings; 0035 m_settings->setSharedConfig(project->projectConfiguration()); 0036 m_settings->load(); 0037 setConfigSkeleton(m_settings); 0038 0039 m_ui.setupUi(this); 0040 0041 if (plugin->checksDB()->isValid()) { 0042 m_ui.dbError->setVisible(false); 0043 } else { 0044 m_ui.dbError->setText(plugin->checksDB()->error()); 0045 m_ui.dbError->setVisible(true); 0046 0047 m_ui.tabWidget->setVisible(false); 0048 m_ui.commandLineWidget->setVisible(false); 0049 return; 0050 } 0051 0052 configSkeleton()->setSharedConfig(project->projectConfiguration()); 0053 configSkeleton()->load(); 0054 0055 // ============================================================================================= 0056 0057 m_ui.kcfg_checkSetSelection->setCheckSetSelections(m_checkSetSelections, m_defaultCheckSetSelectionId); 0058 m_ui.checks->setChecksDb(plugin->checksDB()); 0059 connect(m_ui.checks, &ChecksWidget::checksChanged, 0060 this, &ProjectConfigPage::updateCommandLine); 0061 0062 connect(m_ui.kcfg_checkSetSelection, &CheckSetSelectionComboBox::selectionChanged, 0063 this, &ProjectConfigPage::onSelectionChanged); 0064 connect(m_ui.checks, &ChecksWidget::checksChanged, 0065 this, &ProjectConfigPage::onChecksChanged); 0066 0067 // ============================================================================================= 0068 0069 QCheckBox* const commandLineCheckBoxes[] = { 0070 m_ui.kcfg_onlyQt, 0071 m_ui.kcfg_qtDeveloper, 0072 m_ui.kcfg_qt4Compat, 0073 m_ui.kcfg_visitImplicitCode, 0074 m_ui.kcfg_ignoreIncludedFiles, 0075 m_ui.kcfg_enableAllFixits, 0076 m_ui.kcfg_noInplaceFixits, 0077 }; 0078 for (auto* checkBox : commandLineCheckBoxes) { 0079 connect(checkBox, &QCheckBox::stateChanged, 0080 this, &ProjectConfigPage::updateCommandLine); 0081 } 0082 QLineEdit* const commandLineLineEdits[] = { 0083 m_ui.kcfg_headerFilter, 0084 m_ui.kcfg_extraAppend, 0085 m_ui.kcfg_extraPrepend, 0086 m_ui.kcfg_extraClazy, 0087 }; 0088 for (auto* lineEdit : commandLineLineEdits) { 0089 lineEdit->setPlaceholderText(lineEdit->toolTip()); 0090 connect(lineEdit, &QLineEdit::textChanged, 0091 this, &ProjectConfigPage::updateCommandLine); 0092 } 0093 0094 updateCommandLine(); 0095 } 0096 0097 ProjectConfigPage::~ProjectConfigPage() = default; 0098 0099 QIcon ProjectConfigPage::icon() const 0100 { 0101 return QIcon::fromTheme(QStringLiteral("clazy")); 0102 } 0103 0104 QString ProjectConfigPage::name() const 0105 { 0106 return i18nc("@title:tab", "Clazy"); 0107 } 0108 0109 void ProjectConfigPage::updateCommandLine() 0110 { 0111 QStringList arguments; 0112 0113 arguments << GlobalSettings::executablePath().toLocalFile(); 0114 0115 const auto checks = m_ui.checks->checks(); 0116 if (!checks.isEmpty()) { 0117 arguments << QLatin1String("-checks=") + checks; 0118 } 0119 0120 if (m_ui.kcfg_onlyQt->isChecked()) { 0121 arguments << QStringLiteral("-only-qt"); 0122 } 0123 0124 if (m_ui.kcfg_qtDeveloper->isChecked()) { 0125 arguments << QStringLiteral("-qt-developer"); 0126 } 0127 0128 if (m_ui.kcfg_qt4Compat->isChecked()) { 0129 arguments << QStringLiteral("-qt4-compat"); 0130 } 0131 0132 if (m_ui.kcfg_visitImplicitCode->isChecked()) { 0133 arguments << QStringLiteral("-visit-implicit-code"); 0134 } 0135 0136 if (m_ui.kcfg_ignoreIncludedFiles->isChecked()) { 0137 arguments << QStringLiteral("-ignore-included-files"); 0138 } 0139 0140 const auto headerFilter = m_ui.kcfg_headerFilter->text(); 0141 if (!headerFilter.isEmpty()) { 0142 arguments << QLatin1String("-header-filter=") + headerFilter; 0143 } 0144 0145 if (m_ui.kcfg_enableAllFixits->isChecked()) { 0146 arguments << QStringLiteral("-enable-all-fixits"); 0147 } 0148 0149 if (m_ui.kcfg_noInplaceFixits->isChecked()) { 0150 arguments << QStringLiteral("-no-inplace-fixits"); 0151 } 0152 0153 const auto extraAppend = m_ui.kcfg_extraAppend->text(); 0154 if (!extraAppend.isEmpty()) { 0155 arguments << QLatin1String("-extra-arg=") + extraAppend; 0156 } 0157 0158 const auto extraPrepend = m_ui.kcfg_extraPrepend->text(); 0159 if (!extraPrepend.isEmpty()) { 0160 arguments << QLatin1String("-extra-arg-before1") + extraPrepend; 0161 } 0162 0163 const auto extraClazy = m_ui.kcfg_extraClazy->text(); 0164 if (!extraClazy.isEmpty()) { 0165 arguments << KShell::splitArgs(extraClazy); 0166 } 0167 0168 arguments << QStringLiteral("-p <build directory>"); 0169 0170 m_ui.commandLineWidget->setText(arguments.join(QLatin1Char(' '))); 0171 } 0172 0173 void ProjectConfigPage::defaults() 0174 { 0175 ConfigPage::defaults(); 0176 onSelectionChanged(m_ui.kcfg_checkSetSelection->selection()); 0177 } 0178 0179 void ProjectConfigPage::reset() 0180 { 0181 ConfigPage::reset(); 0182 0183 onSelectionChanged(m_ui.kcfg_checkSetSelection->selection()); 0184 } 0185 0186 void ProjectConfigPage::apply() 0187 { 0188 ConfigPage::apply(); 0189 } 0190 0191 void ProjectConfigPage::onSelectionChanged(const QString& selectionId) 0192 { 0193 QString checks; 0194 bool editable = false; 0195 if (selectionId.isEmpty()) { 0196 checks = m_ui.kcfg_checks->checks(); 0197 editable = true; 0198 } else { 0199 const QString effectiveSelectionId = (selectionId == QLatin1String("Default")) ? m_defaultCheckSetSelectionId : selectionId; 0200 for (auto& selection : m_checkSetSelections) { 0201 if (selection.id() == effectiveSelectionId) { 0202 checks = selection.selectionAsString(); 0203 break; 0204 } 0205 } 0206 } 0207 0208 m_ui.checks->setEditable(editable); 0209 m_ui.checks->setChecks(checks); 0210 } 0211 0212 void ProjectConfigPage::onChecksChanged(const QString& checks) 0213 { 0214 const bool isCustomSelected = m_ui.kcfg_checkSetSelection->selection().isEmpty(); 0215 if (!isCustomSelected) { 0216 return; 0217 } 0218 0219 m_ui.kcfg_checks->setChecks(checks); 0220 } 0221 0222 } 0223 0224 #include "moc_projectconfigpage.cpp"