4949#include " threadhandler.h"
5050#include " threadresult.h"
5151#include " translationhandler.h"
52+ #include " variablecontractsdialog.h"
5253
5354static const QString OnlineHelpURL (" http://cppcheck.net/manual.html" );
5455static const QString compile_commands_json (" compile_commands.json" );
@@ -144,6 +145,9 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
144145 connect (mUI .mResults , &ResultsView::checkSelected, this , &MainWindow::performSelectedFilesCheck);
145146 connect (mUI .mResults , &ResultsView::suppressIds, this , &MainWindow::suppressIds);
146147 connect (mUI .mResults , &ResultsView::editFunctionContract, this , &MainWindow::editFunctionContract);
148+ connect (mUI .mResults , &ResultsView::editVariableContract, this , &MainWindow::editVariableContract);
149+ connect (mUI .mResults , &ResultsView::deleteFunctionContract, this , &MainWindow::deleteFunctionContract);
150+ connect (mUI .mResults , &ResultsView::deleteVariableContract, this , &MainWindow::deleteVariableContract);
147151 connect (mUI .mMenuView , &QMenu::aboutToShow, this , &MainWindow::aboutToShowViewMenu);
148152
149153 // File menu
@@ -351,7 +355,8 @@ void MainWindow::loadSettings()
351355 }
352356 }
353357
354- updateContractsTab ();
358+ updateFunctionContractsTab ();
359+ updateVariableContractsTab ();
355360}
356361
357362void MainWindow::saveSettings () const
@@ -611,15 +616,31 @@ QStringList MainWindow::selectFilesToAnalyze(QFileDialog::FileMode mode)
611616 return selected;
612617}
613618
614- void MainWindow::updateContractsTab ()
619+ void MainWindow::updateFunctionContractsTab ()
615620{
616621 QStringList addedContracts;
617622 if (mProjectFile ) {
618623 for (const auto it: mProjectFile ->getFunctionContracts ()) {
619624 addedContracts << QString::fromStdString (it.first );
620625 }
621626 }
622- mUI .mResults ->setAddedContracts (addedContracts);
627+ mUI .mResults ->setAddedFunctionContracts (addedContracts);
628+ }
629+
630+ void MainWindow::updateVariableContractsTab ()
631+ {
632+ QStringList added;
633+ if (mProjectFile ) {
634+ for (auto vc: mProjectFile ->getVariableContracts ()) {
635+ QString line = vc.first ;
636+ if (!vc.second .minValue .empty ())
637+ line += " min:" + QString::fromStdString (vc.second .minValue );
638+ if (!vc.second .maxValue .empty ())
639+ line += " max:" + QString::fromStdString (vc.second .maxValue );
640+ added << line;
641+ }
642+ }
643+ mUI .mResults ->setAddedVariableContracts (added);
623644}
624645
625646void MainWindow::analyzeFiles ()
@@ -865,6 +886,9 @@ Settings MainWindow::getCppcheckSettings()
865886
866887 result.functionContracts = mProjectFile ->getFunctionContracts ();
867888
889+ for (const auto vc: mProjectFile ->getVariableContracts ())
890+ result.variableContracts [vc.first .toStdString ()] = vc.second ;
891+
868892 const QStringList undefines = mProjectFile ->getUndefines ();
869893 foreach (QString undefine, undefines)
870894 result.userUndefs .insert (undefine.toStdString ());
@@ -1513,7 +1537,9 @@ void MainWindow::loadProjectFile(const QString &filePath)
15131537 delete mProjectFile ;
15141538 mProjectFile = new ProjectFile (filePath, this );
15151539 mProjectFile ->setActiveProject ();
1516- updateContractsTab ();
1540+ mUI .mResults ->showContracts (mProjectFile ->bugHunting );
1541+ updateFunctionContractsTab ();
1542+ updateVariableContractsTab ();
15171543 if (!loadLastResults ())
15181544 analyzeProject (mProjectFile );
15191545}
@@ -1639,19 +1665,23 @@ void MainWindow::newProjectFile()
16391665 ProjectFileDialog dlg (mProjectFile , this );
16401666 if (dlg.exec () == QDialog::Accepted) {
16411667 addProjectMRU (filepath);
1668+ mUI .mResults ->showContracts (mProjectFile ->bugHunting );
16421669 analyzeProject (mProjectFile );
16431670 } else {
16441671 closeProjectFile ();
16451672 }
16461673
1647- updateContractsTab ();
1674+ updateFunctionContractsTab ();
1675+ updateVariableContractsTab ();
16481676}
16491677
16501678void MainWindow::closeProjectFile ()
16511679{
16521680 delete mProjectFile ;
16531681 mProjectFile = nullptr ;
16541682 mUI .mResults ->clear (true );
1683+ mUI .mResults ->clearContracts ();
1684+ mUI .mResults ->showContracts (false );
16551685 enableProjectActions (false );
16561686 enableProjectOpenActions (true );
16571687 formatAndSetTitle ();
@@ -1672,6 +1702,7 @@ void MainWindow::editProjectFile()
16721702 ProjectFileDialog dlg (mProjectFile , this );
16731703 if (dlg.exec () == QDialog::Accepted) {
16741704 mProjectFile ->write ();
1705+ mUI .mResults ->showContracts (mProjectFile ->bugHunting );
16751706 analyzeProject (mProjectFile );
16761707 }
16771708}
@@ -1858,5 +1889,35 @@ void MainWindow::editFunctionContract(QString function)
18581889 mProjectFile ->write ();
18591890 }
18601891
1861- updateContractsTab ();
1892+ updateFunctionContractsTab ();
1893+ }
1894+
1895+ void MainWindow::editVariableContract (QString var)
1896+ {
1897+ if (!mProjectFile )
1898+ return ;
1899+
1900+ VariableContractsDialog dlg (nullptr , var);
1901+ if (dlg.exec () == QDialog::Accepted) {
1902+ mProjectFile ->setVariableContracts (dlg.getVarname (), dlg.getMin (), dlg.getMax ());
1903+ mProjectFile ->write ();
1904+ }
1905+
1906+ updateVariableContractsTab ();
1907+ }
1908+
1909+ void MainWindow::deleteFunctionContract (QString function)
1910+ {
1911+ if (mProjectFile ) {
1912+ mProjectFile ->deleteFunctionContract (function);
1913+ mProjectFile ->write ();
1914+ }
1915+ }
1916+
1917+ void MainWindow::deleteVariableContract (QString var)
1918+ {
1919+ if (mProjectFile ) {
1920+ mProjectFile ->deleteVariableContract (var);
1921+ mProjectFile ->write ();
1922+ }
18621923}
0 commit comments