File indexing completed on 2024-03-24 04:38:33
0001 /* This file is part of KDevelop 0002 0003 Copyright 2016 Anton Anikin <anton.anikin@htower.ru> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; see the file COPYING. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "projectconfigpage.h" 0022 #include "ui_projectconfigpage.h" 0023 0024 #include "parameters.h" 0025 #include "projectsettings.h" 0026 #include "rules.h" 0027 0028 #include <interfaces/iproject.h> 0029 0030 namespace verapp 0031 { 0032 0033 ProjectConfigPage::ProjectConfigPage(KDevelop::IPlugin* plugin, KDevelop::IProject* project, QWidget* parent) 0034 : ConfigPage(plugin, new ProjectSettings, parent) 0035 , ui(new Ui::ProjectConfigPage) 0036 , m_parameters(new Parameters(project)) 0037 { 0038 configSkeleton()->setSharedConfig(project->projectConfiguration()); 0039 configSkeleton()->load(); 0040 0041 ui->setupUi(this); 0042 0043 ui->commandLine->setFontFamily("Monospace"); 0044 0045 connect(this, &ProjectConfigPage::changed, this, &ProjectConfigPage::updateCommandLine); 0046 connect(ui->commandLineFilter, &QLineEdit::textChanged, this, &ProjectConfigPage::updateCommandLine); 0047 connect(ui->commandLineBreaks, &QCheckBox::stateChanged, this, &ProjectConfigPage::updateCommandLine); 0048 0049 addRules(ui->tabF, rules::F001, rules::F002); 0050 addRules(ui->tabL, rules::L001, rules::L006); 0051 addRules(ui->tabT1, rules::T001, rules::T007); 0052 addRules(ui->tabT2, rules::T008, rules::T014); 0053 addRules(ui->tabT3, rules::T015, rules::T019); 0054 } 0055 0056 ProjectConfigPage::~ProjectConfigPage() 0057 { 0058 } 0059 0060 QIcon ProjectConfigPage::icon() const 0061 { 0062 return QIcon::fromTheme(QStringLiteral("dialog-ok")); 0063 } 0064 0065 void ProjectConfigPage::defaults() 0066 { 0067 ConfigPage::defaults(); 0068 updateCommandLine(); 0069 } 0070 0071 void ProjectConfigPage::reset() 0072 { 0073 ConfigPage::reset(); 0074 updateCommandLine(); 0075 } 0076 0077 QString ProjectConfigPage::name() const 0078 { 0079 return i18n("Vera++"); 0080 } 0081 0082 void ProjectConfigPage::updateCommandLine() 0083 { 0084 for (int intType = rules::Type::FIRST; intType <= rules::Type::LAST; ++intType) { 0085 rules::Type ruleType = static_cast<rules::Type>(intType); 0086 0087 m_parameters->setRuleEnabled(ruleType, m_rulesCheckBox[ruleType]->isChecked()); 0088 } 0089 0090 m_parameters->extraParameters = ui->kcfg_extraParameters->text().trimmed(); 0091 0092 QString text = m_parameters->commandLine().join(' '); 0093 if (!ui->commandLineBreaks->isChecked()) { 0094 ui->commandLine->setText(text); 0095 return; 0096 } 0097 0098 text.replace(" -", "\n-"); 0099 if (ui->commandLineFilter->text().isEmpty()) { 0100 ui->commandLine->setText(text); 0101 ui->commandLineBreaks->setEnabled(true); 0102 return; 0103 } 0104 0105 QStringList lines = text.split('\n'); 0106 QMutableStringListIterator i(lines); 0107 0108 while (i.hasNext()) { 0109 if (!i.next().contains(ui->commandLineFilter->text())) { 0110 i.remove(); 0111 } 0112 } 0113 0114 ui->commandLine->setText(lines.join('\n')); 0115 ui->commandLineBreaks->setEnabled(false); 0116 } 0117 0118 void ProjectConfigPage::addRules(QWidget* tab, rules::Type first, rules::Type last) 0119 { 0120 QVBoxLayout* layout = new QVBoxLayout(tab); 0121 0122 for (int intType = first; intType <= last; ++intType) { 0123 rules::Type type = static_cast<rules::Type>(intType); 0124 QCheckBox* checkBox = new QCheckBox(tab); 0125 0126 checkBox->setObjectName(QString("kcfg_rule%1").arg(intType)); 0127 checkBox->setText(QString("%1: %2").arg(rules::name(type)).arg(rules::title(type))); 0128 checkBox->setToolTip(rules::explanation(type)); 0129 0130 layout->addWidget(checkBox); 0131 0132 m_rulesCheckBox[type] = checkBox; 0133 } 0134 layout->addStretch(); 0135 } 0136 0137 }