File indexing completed on 2024-04-28 15:54:11
0001 /* 0002 SPDX-FileCopyrightText: 2013-2016 Sven Brauch <svenbrauch@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kcm_pep8.h" 0008 0009 #include <KLocalizedString> 0010 #include <KSharedConfig> 0011 #include <QDebug> 0012 0013 namespace { 0014 QString pep8DefaultIgnoreErrors() { 0015 return QStringLiteral("E121,E123,E126,E226,E24,E704,W503"); 0016 } 0017 } 0018 0019 PEP8KCModule::PEP8KCModule(KDevelop::IPlugin* plugin, QWidget* parent) 0020 : KDevelop::ConfigPage(plugin, nullptr, parent) 0021 { 0022 auto config = KSharedConfig::openConfig("kdevpythonsupportrc"); 0023 configGroup = config->group("pep8"); 0024 m_ui.setupUi(this); 0025 0026 connect(m_ui.disableErrors, &QLineEdit::textChanged, this, &PEP8KCModule::changed); 0027 connect(m_ui.enableErrors, &QLineEdit::textChanged, this, &PEP8KCModule::changed); 0028 connect(m_ui.maxLineLength, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &PEP8KCModule::changed); 0029 connect(m_ui.enableChecking, &QGroupBox::toggled, this, &PEP8KCModule::changed); 0030 } 0031 0032 void PEP8KCModule::apply() 0033 { 0034 configGroup.writeEntry("enableErrors", m_ui.enableErrors->text()); 0035 configGroup.writeEntry("disableErrors", m_ui.disableErrors->text()); 0036 configGroup.writeEntry("maxLineLength", m_ui.maxLineLength->text()); 0037 configGroup.writeEntry("pep8enabled", m_ui.enableChecking->isChecked()); 0038 configGroup.sync(); 0039 } 0040 0041 bool PEP8KCModule::isPep8Enabled(const KConfigGroup& group) 0042 { 0043 return group.readEntry<bool>("pep8enabled", false); 0044 } 0045 void PEP8KCModule::reset() 0046 { 0047 m_ui.enableErrors->setText(configGroup.readEntry("enableErrors", QString())); 0048 m_ui.disableErrors->setText(configGroup.readEntry("disableErrors", pep8DefaultIgnoreErrors())); 0049 m_ui.maxLineLength->setValue(configGroup.readEntry("maxLineLength", 79)); 0050 m_ui.enableChecking->setChecked(configGroup.readEntry("pep8enabled", false)); 0051 } 0052 0053 void PEP8KCModule::defaults() 0054 { 0055 m_ui.enableErrors->setText(""); 0056 m_ui.disableErrors->setText(pep8DefaultIgnoreErrors()); 0057 m_ui.maxLineLength->setValue(79); 0058 m_ui.enableChecking->setChecked(false); 0059 } 0060 0061 QString PEP8KCModule::fullName() const 0062 { 0063 return i18n("Configure Python Style Checking"); 0064 } 0065 0066 QIcon PEP8KCModule::icon() const 0067 { 0068 return QIcon::fromTheme(QStringLiteral("text-x-python")); 0069 } 0070 0071 QString PEP8KCModule::name() const 0072 { 0073 return i18n("Python Style Checking"); 0074 } 0075 0076 PEP8KCModule::~PEP8KCModule() 0077 { 0078 } 0079 0080 KDevelop::ConfigPage::ConfigPageType PEP8KCModule::configPageType() const 0081 { 0082 return KDevelop::ConfigPage::AnalyzerConfigPage; 0083 } 0084 0085 #include "moc_kcm_pep8.cpp"