GUI: Library editor - added sort button and filter edit box

This commit is contained in:
Daniel Marjamäki 2015-09-06 14:20:27 +02:00
parent 65d246aea2
commit 9f31414179
3 changed files with 197 additions and 90 deletions

View File

@ -43,6 +43,18 @@ LibraryDialog::~LibraryDialog()
delete ui;
}
CppcheckLibraryData::Function *LibraryDialog::currentFunction()
{
QList<QListWidgetItem *> selitems = ui->functions->selectedItems();
if (selitems.count() != 1)
return nullptr;
for (int row = 0; row < data.functions.size(); ++row) {
if (data.functions[row].name == selitems.front()->text())
return &data.functions[row];
}
return nullptr;
}
void LibraryDialog::openCfg()
{
const QSettings settings;
@ -64,6 +76,7 @@ void LibraryDialog::openCfg()
data.open(file);
mFileName = selectedFile;
ui->buttonSave->setEnabled(false);
ui->filter->clear();
ui->functions->clear();
foreach(const struct CppcheckLibraryData::Function &function, data.functions) {
ui->functions->addItem(function.name);
@ -106,9 +119,11 @@ void LibraryDialog::addFunction()
delete d;
}
void LibraryDialog::selectFunction(int row)
void LibraryDialog::selectFunction()
{
if (row == -1) {
const CppcheckLibraryData::Function * const function = currentFunction();
if (function == nullptr) {
ui->noreturn->setCurrentIndex(0);
ui->useretval->setChecked(false);
ui->leakignore->setChecked(false);
@ -117,41 +132,65 @@ void LibraryDialog::selectFunction(int row)
}
ignoreChanges = true;
const CppcheckLibraryData::Function &function = data.functions[row];
ui->noreturn->setCurrentIndex(function.noreturn);
ui->useretval->setChecked(function.useretval);
ui->leakignore->setChecked(function.leakignore);
updateArguments(function);
ui->noreturn->setCurrentIndex(function->noreturn);
ui->useretval->setChecked(function->useretval);
ui->leakignore->setChecked(function->leakignore);
updateArguments(*function);
ignoreChanges = false;
}
void LibraryDialog::changeFunction(int)
void LibraryDialog::sortFunctions(bool sort)
{
changeFunction();
if (sort)
ui->functions->sortItems();
else {
ignoreChanges = true;
ui->functions->clear();
foreach(const struct CppcheckLibraryData::Function &function, data.functions)
ui->functions->addItem(function.name);
if (!ui->filter->text().isEmpty())
filterFunctions(ui->filter->text());
ignoreChanges = false;
}
}
void LibraryDialog::filterFunctions(QString filter)
{
QList<QListWidgetItem *> allItems = ui->functions->findItems(QString(), Qt::MatchContains);
if (filter.isEmpty()) {
foreach(QListWidgetItem *item, allItems) {
item->setHidden(false);
}
} else {
foreach(QListWidgetItem *item, allItems) {
item->setHidden(!item->text().startsWith(filter));
}
}
}
void LibraryDialog::changeFunction()
{
if (ignoreChanges)
return;
foreach(const QListWidgetItem *item, ui->functions->selectedItems()) {
CppcheckLibraryData::Function &function = data.functions[ui->functions->row(item)];
function.noreturn = (CppcheckLibraryData::Function::TrueFalseUnknown)ui->noreturn->currentIndex();
function.useretval = ui->useretval->isChecked();
function.leakignore = ui->leakignore->isChecked();
}
CppcheckLibraryData::Function *function = currentFunction();
function->noreturn = (CppcheckLibraryData::Function::TrueFalseUnknown)ui->noreturn->currentIndex();
function->useretval = ui->useretval->isChecked();
function->leakignore = ui->leakignore->isChecked();
ui->buttonSave->setEnabled(true);
}
void LibraryDialog::editArg()
{
if (ui->functions->selectedItems().count() != 1)
return;
if (ui->arguments->selectedItems().count() != 1)
CppcheckLibraryData::Function *function = currentFunction();
if (!function)
return;
CppcheckLibraryData::Function &function = data.functions[ui->functions->row(ui->functions->selectedItems().first())];
CppcheckLibraryData::Function::Arg &arg = function.args[ui->arguments->row(ui->arguments->selectedItems().first())];
if (ui->arguments->selectedItems().count() != 1)
return;
CppcheckLibraryData::Function::Arg &arg = function->args[ui->arguments->row(ui->arguments->selectedItems().first())];
LibraryEditArgDialog *d = new LibraryEditArgDialog(0, arg);
if (d->exec() == QDialog::Accepted) {

View File

@ -41,10 +41,11 @@ private slots:
void openCfg();
void saveCfg();
void addFunction();
void selectFunction(int row);
void changeFunction();
void changeFunction(int);
void editArg();
void filterFunctions(QString);
void selectFunction();
void sortFunctions(bool);
private:
Ui::LibraryDialog *ui;
@ -53,6 +54,7 @@ private:
bool ignoreChanges;
static QString getArgText(const CppcheckLibraryData::Function::Arg &arg);
CppcheckLibraryData::Function *currentFunction();
void updateArguments(const CppcheckLibraryData::Function &function);
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>547</width>
<height>300</height>
<width>869</width>
<height>588</height>
</rect>
</property>
<property name="windowTitle">
@ -56,6 +56,36 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="sortFunctions">
<property name="text">
<string>AZ</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="functions">
<property name="editTriggers">
@ -88,6 +118,9 @@
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="filter"/>
</item>
</layout>
</item>
</layout>
@ -186,22 +219,6 @@
</widget>
<resources/>
<connections>
<connection>
<sender>functions</sender>
<signal>currentRowChanged(int)</signal>
<receiver>LibraryDialog</receiver>
<slot>selectFunction(int)</slot>
<hints>
<hint type="sourcelabel">
<x>155</x>
<y>218</y>
</hint>
<hint type="destinationlabel">
<x>327</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonOpen</sender>
<signal>clicked()</signal>
@ -209,12 +226,12 @@
<slot>openCfg()</slot>
<hints>
<hint type="sourcelabel">
<x>61</x>
<y>27</y>
<x>59</x>
<y>18</y>
</hint>
<hint type="destinationlabel">
<x>72</x>
<y>21</y>
<x>66</x>
<y>34</y>
</hint>
</hints>
</connection>
@ -225,12 +242,12 @@
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>372</x>
<y>69</y>
<x>739</x>
<y>74</y>
</hint>
<hint type="destinationlabel">
<x>475</x>
<y>5</y>
<x>750</x>
<y>74</y>
</hint>
</hints>
</connection>
@ -241,12 +258,12 @@
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>419</x>
<y>99</y>
<x>735</x>
<y>103</y>
</hint>
<hint type="destinationlabel">
<x>319</x>
<y>3</y>
<x>744</x>
<y>102</y>
</hint>
</hints>
</connection>
@ -257,12 +274,12 @@
<slot>saveCfg()</slot>
<hints>
<hint type="sourcelabel">
<x>102</x>
<y>9</y>
<x>118</x>
<y>16</y>
</hint>
<hint type="destinationlabel">
<x>115</x>
<y>1</y>
<x>130</x>
<y>32</y>
</hint>
</hints>
</connection>
@ -273,12 +290,12 @@
<slot>addFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>48</x>
<y>282</y>
<x>53</x>
<y>564</y>
</hint>
<hint type="destinationlabel">
<x>65</x>
<y>298</y>
<x>63</x>
<y>582</y>
</hint>
</hints>
</connection>
@ -289,28 +306,12 @@
<slot>editArg()</slot>
<hints>
<hint type="sourcelabel">
<x>317</x>
<y>278</y>
<x>488</x>
<y>580</y>
</hint>
<hint type="destinationlabel">
<x>349</x>
<y>281</y>
</hint>
</hints>
</connection>
<connection>
<sender>noreturn</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>LibraryDialog</receiver>
<slot>changeFunction(int)</slot>
<hints>
<hint type="sourcelabel">
<x>504</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>543</x>
<y>32</y>
<x>497</x>
<y>580</y>
</hint>
</hints>
</connection>
@ -321,24 +322,89 @@
<slot>editArg()</slot>
<hints>
<hint type="sourcelabel">
<x>525</x>
<y>146</y>
<x>685</x>
<y>149</y>
</hint>
<hint type="destinationlabel">
<x>545</x>
<y>145</y>
<x>693</x>
<y>148</y>
</hint>
</hints>
</connection>
<connection>
<sender>sortFunctions</sender>
<signal>toggled(bool)</signal>
<receiver>LibraryDialog</receiver>
<slot>sortFunctions(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>45</x>
<y>66</y>
</hint>
<hint type="destinationlabel">
<x>58</x>
<y>66</y>
</hint>
</hints>
</connection>
<connection>
<sender>filter</sender>
<signal>textChanged(QString)</signal>
<receiver>LibraryDialog</receiver>
<slot>filterFunctions(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>565</y>
</hint>
<hint type="destinationlabel">
<x>273</x>
<y>582</y>
</hint>
</hints>
</connection>
<connection>
<sender>functions</sender>
<signal>itemSelectionChanged()</signal>
<receiver>LibraryDialog</receiver>
<slot>selectFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>190</x>
<y>141</y>
</hint>
<hint type="destinationlabel">
<x>203</x>
<y>140</y>
</hint>
</hints>
</connection>
<connection>
<sender>noreturn</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>LibraryDialog</receiver>
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>696</x>
<y>46</y>
</hint>
<hint type="destinationlabel">
<x>703</x>
<y>46</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>selectFunction(int)</slot>
<slot>openCfg()</slot>
<slot>changeFunction()</slot>
<slot>saveCfg()</slot>
<slot>argumentChanged(QListWidgetItem*)</slot>
<slot>addFunction()</slot>
<slot>argumentChanged(QListWidgetItem*)</slot>
<slot>changeFunction()</slot>
<slot>editArg()</slot>
<slot>changeFunction(int)</slot>
<slot>filterFunctions(QString)</slot>
<slot>openCfg()</slot>
<slot>saveCfg()</slot>
<slot>selectFunction()</slot>
<slot>sortFunctions(bool)</slot>
</slots>
</ui>