GUI: Try to improve usability for function contracts
This commit is contained in:
parent
2e369cc842
commit
dae009ca01
|
@ -0,0 +1,31 @@
|
|||
#include "functioncontractdialog.h"
|
||||
#include "ui_functioncontractdialog.h"
|
||||
|
||||
static QString formatFunctionName(QString f)
|
||||
{
|
||||
if (f.endsWith("()"))
|
||||
return f;
|
||||
f.replace("(", "(\n ");
|
||||
f.replace(",", ",\n ");
|
||||
return f;
|
||||
}
|
||||
|
||||
FunctionContractDialog::FunctionContractDialog(QWidget *parent, QString name, QString expects) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::FunctionContractDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->functionName->setText(formatFunctionName(name));
|
||||
ui->expects->setPlainText(expects);
|
||||
}
|
||||
|
||||
FunctionContractDialog::~FunctionContractDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString FunctionContractDialog::getExpects() const
|
||||
{
|
||||
return ui->expects->toPlainText();
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef FUNCTIONCONTRACTDIALOG_H
|
||||
#define FUNCTIONCONTRACTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class FunctionContractDialog;
|
||||
}
|
||||
|
||||
class FunctionContractDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FunctionContractDialog(QWidget *parent, QString name, QString expects);
|
||||
~FunctionContractDialog();
|
||||
QString getExpects() const;
|
||||
private:
|
||||
Ui::FunctionContractDialog *ui;
|
||||
};
|
||||
|
||||
#endif // FUNCTIONCONTRACTDIALOG_H
|
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FunctionContractDialog</class>
|
||||
<widget class="QDialog" name="FunctionContractDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>401</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Function contract</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="functionName">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Requirements for parameters</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="expects"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>FunctionContractDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>FunctionContractDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -60,6 +60,7 @@ RESOURCES = gui.qrc
|
|||
FORMS = about.ui \
|
||||
application.ui \
|
||||
file.ui \
|
||||
functioncontractdialog.ui \
|
||||
mainwindow.ui \
|
||||
projectfiledialog.ui \
|
||||
resultsview.ui \
|
||||
|
@ -108,6 +109,7 @@ HEADERS += aboutdialog.h \
|
|||
erroritem.h \
|
||||
filelist.h \
|
||||
fileviewdialog.h \
|
||||
functioncontractdialog.h \
|
||||
mainwindow.h \
|
||||
platforms.h \
|
||||
printablereport.h \
|
||||
|
@ -147,6 +149,7 @@ SOURCES += aboutdialog.cpp \
|
|||
erroritem.cpp \
|
||||
filelist.cpp \
|
||||
fileviewdialog.cpp \
|
||||
functioncontractdialog.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp\
|
||||
platforms.cpp \
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "common.h"
|
||||
#include "threadhandler.h"
|
||||
#include "fileviewdialog.h"
|
||||
#include "functioncontractdialog.h"
|
||||
#include "projectfile.h"
|
||||
#include "projectfiledialog.h"
|
||||
#include "report.h"
|
||||
|
@ -142,7 +143,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
|||
connect(mUI.mResults, &ResultsView::checkSelected, this, &MainWindow::performSelectedFilesCheck);
|
||||
connect(mUI.mResults, &ResultsView::tagged, this, &MainWindow::tagged);
|
||||
connect(mUI.mResults, &ResultsView::suppressIds, this, &MainWindow::suppressIds);
|
||||
connect(mUI.mResults, &ResultsView::addFunctionContract, this, &MainWindow::addFunctionContract);
|
||||
connect(mUI.mResults, &ResultsView::editFunctionContract, this, &MainWindow::editFunctionContract);
|
||||
connect(mUI.mMenuView, &QMenu::aboutToShow, this, &MainWindow::aboutToShowViewMenu);
|
||||
|
||||
// File menu
|
||||
|
@ -1794,19 +1795,22 @@ void MainWindow::suppressIds(QStringList ids)
|
|||
mProjectFile->write();
|
||||
}
|
||||
|
||||
void MainWindow::addFunctionContract(QString function)
|
||||
void MainWindow::editFunctionContract(QString function)
|
||||
{
|
||||
if (!mProjectFile)
|
||||
return;
|
||||
bool ok;
|
||||
const QString expects = QInputDialog::getText(this,
|
||||
tr("Add contract"),
|
||||
"Function:" + function + "\nExpects:",
|
||||
QLineEdit::Normal,
|
||||
QString(),
|
||||
&ok);
|
||||
if (ok) {
|
||||
mProjectFile->setFunctionContract(function, expects);
|
||||
|
||||
QString expects;
|
||||
const auto it = mProjectFile->getFunctionContracts().find(function.toStdString());
|
||||
if (it != mProjectFile->getFunctionContracts().end())
|
||||
expects = QString::fromStdString(it->second);
|
||||
|
||||
FunctionContractDialog dlg(nullptr,
|
||||
function,
|
||||
expects);
|
||||
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
mProjectFile->setFunctionContract(function, dlg.getExpects());
|
||||
mProjectFile->write();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -225,8 +225,8 @@ protected slots:
|
|||
/** Suppress error ids */
|
||||
void suppressIds(QStringList ids);
|
||||
|
||||
/** Add contract for function */
|
||||
void addFunctionContract(QString function);
|
||||
/** Edit contract for function */
|
||||
void editFunctionContract(QString function);
|
||||
private:
|
||||
|
||||
/** Get filename for last results */
|
||||
|
|
|
@ -614,9 +614,9 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
|
|||
const bool bughunting = !multipleSelection && mContextItem->data().toMap().value("id").toString().startsWith("bughunting");
|
||||
|
||||
if (bughunting) {
|
||||
QAction *addContract = new QAction(tr("Add contract.."), &menu);
|
||||
connect(addContract, SIGNAL(triggered()), this, SLOT(addContract()));
|
||||
menu.addAction(addContract);
|
||||
QAction *editContract = new QAction(tr("Edit contract.."), &menu);
|
||||
connect(editContract, &QAction::triggered, this, &ResultsTree::editContract);
|
||||
menu.addAction(editContract);
|
||||
menu.addSeparator();
|
||||
}
|
||||
|
||||
|
@ -1033,10 +1033,10 @@ void ResultsTree::openContainingFolder()
|
|||
}
|
||||
}
|
||||
|
||||
void ResultsTree::addContract()
|
||||
void ResultsTree::editContract()
|
||||
{
|
||||
QString function = mContextItem->data().toMap().value("function").toString();
|
||||
emit addFunctionContract(function);
|
||||
emit editFunctionContract(function);
|
||||
}
|
||||
|
||||
void ResultsTree::tagSelectedItems(const QString &tag)
|
||||
|
|
|
@ -208,8 +208,8 @@ signals:
|
|||
/** Suppress Ids */
|
||||
void suppressIds(QStringList ids);
|
||||
|
||||
/** Add contract for function */
|
||||
void addFunctionContract(QString function);
|
||||
/** Edit contract for function */
|
||||
void editFunctionContract(QString function);
|
||||
public slots:
|
||||
|
||||
/**
|
||||
|
@ -285,9 +285,9 @@ protected slots:
|
|||
void openContainingFolder();
|
||||
|
||||
/**
|
||||
* @brief Allow user to add contract to fix bughunting warning
|
||||
* @brief Allow user to edit contract to fix bughunting warning
|
||||
*/
|
||||
void addContract();
|
||||
void editContract();
|
||||
|
||||
/**
|
||||
* @brief Slot for selection change in the results tree.
|
||||
|
|
|
@ -55,7 +55,7 @@ ResultsView::ResultsView(QWidget * parent) :
|
|||
connect(mUI.mTree, &ResultsTree::treeSelectionChanged, this, &ResultsView::updateDetails);
|
||||
connect(mUI.mTree, &ResultsTree::tagged, this, &ResultsView::tagged);
|
||||
connect(mUI.mTree, &ResultsTree::suppressIds, this, &ResultsView::suppressIds);
|
||||
connect(mUI.mTree, &ResultsTree::addFunctionContract, this, &ResultsView::addFunctionContract);
|
||||
connect(mUI.mTree, &ResultsTree::editFunctionContract, this, &ResultsView::editFunctionContract);
|
||||
connect(this, &ResultsView::showResults, mUI.mTree, &ResultsTree::showResults);
|
||||
connect(this, &ResultsView::showCppcheckResults, mUI.mTree, &ResultsTree::showCppcheckResults);
|
||||
connect(this, &ResultsView::showClangResults, mUI.mTree, &ResultsTree::showClangResults);
|
||||
|
|
|
@ -228,8 +228,8 @@ signals:
|
|||
/** Suppress Ids */
|
||||
void suppressIds(QStringList ids);
|
||||
|
||||
/** Add contract for function */
|
||||
void addFunctionContract(QString function);
|
||||
/** Edit contract for function */
|
||||
void editFunctionContract(QString function);
|
||||
|
||||
/**
|
||||
* @brief Show/hide certain type of errors
|
||||
|
|
Loading…
Reference in New Issue