1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "WarningMessagesDialog.h"
4 
WarningMessagesDialog(QWidget * prnt,QCMake * instance)5 WarningMessagesDialog::WarningMessagesDialog(QWidget* prnt, QCMake* instance)
6   : QDialog(prnt)
7   , cmakeInstance(instance)
8 {
9   this->setupUi(this);
10   this->setInitialValues();
11   this->setupSignals();
12 }
13 
setInitialValues()14 void WarningMessagesDialog::setInitialValues()
15 {
16   this->suppressDeveloperWarnings->setChecked(
17     this->cmakeInstance->getSuppressDevWarnings());
18   this->suppressDeprecatedWarnings->setChecked(
19     this->cmakeInstance->getSuppressDeprecatedWarnings());
20 
21   this->developerWarningsAsErrors->setChecked(
22     this->cmakeInstance->getDevWarningsAsErrors());
23   this->deprecatedWarningsAsErrors->setChecked(
24     this->cmakeInstance->getDeprecatedWarningsAsErrors());
25 }
26 
setupSignals()27 void WarningMessagesDialog::setupSignals()
28 {
29   QObject::connect(this->buttonBox, &QDialogButtonBox::accepted, this,
30                    &WarningMessagesDialog::doAccept);
31 
32   QObject::connect(this->suppressDeveloperWarnings, &QCheckBox::stateChanged,
33                    this,
34                    &WarningMessagesDialog::doSuppressDeveloperWarningsChanged);
35   QObject::connect(
36     this->suppressDeprecatedWarnings, &QCheckBox::stateChanged, this,
37     &WarningMessagesDialog::doSuppressDeprecatedWarningsChanged);
38 
39   QObject::connect(this->developerWarningsAsErrors, &QCheckBox::stateChanged,
40                    this,
41                    &WarningMessagesDialog::doDeveloperWarningsAsErrorsChanged);
42   QObject::connect(
43     this->deprecatedWarningsAsErrors, &QCheckBox::stateChanged, this,
44     &WarningMessagesDialog::doDeprecatedWarningsAsErrorsChanged);
45 }
46 
doAccept()47 void WarningMessagesDialog::doAccept()
48 {
49   this->cmakeInstance->setSuppressDevWarnings(
50     this->suppressDeveloperWarnings->isChecked());
51   this->cmakeInstance->setSuppressDeprecatedWarnings(
52     this->suppressDeprecatedWarnings->isChecked());
53 
54   this->cmakeInstance->setDevWarningsAsErrors(
55     this->developerWarningsAsErrors->isChecked());
56   this->cmakeInstance->setDeprecatedWarningsAsErrors(
57     this->deprecatedWarningsAsErrors->isChecked());
58 }
59 
doSuppressDeveloperWarningsChanged(int state)60 void WarningMessagesDialog::doSuppressDeveloperWarningsChanged(int state)
61 {
62   // no warnings implies no errors either
63   if (state) {
64     this->developerWarningsAsErrors->setChecked(false);
65   }
66 }
67 
doSuppressDeprecatedWarningsChanged(int state)68 void WarningMessagesDialog::doSuppressDeprecatedWarningsChanged(int state)
69 {
70   // no warnings implies no errors either
71   if (state) {
72     this->deprecatedWarningsAsErrors->setChecked(false);
73   }
74 }
75 
doDeveloperWarningsAsErrorsChanged(int state)76 void WarningMessagesDialog::doDeveloperWarningsAsErrorsChanged(int state)
77 {
78   // warnings as errors implies warnings are not suppressed
79   if (state) {
80     this->suppressDeveloperWarnings->setChecked(false);
81   }
82 }
83 
doDeprecatedWarningsAsErrorsChanged(int state)84 void WarningMessagesDialog::doDeprecatedWarningsAsErrorsChanged(int state)
85 {
86   // warnings as errors implies warnings are not suppressed
87   if (state) {
88     this->suppressDeprecatedWarnings->setChecked(false);
89   }
90 }
91