diff --git a/gui/librarydialog.cpp b/gui/librarydialog.cpp index 5107cf290..3390a4590 100644 --- a/gui/librarydialog.cpp +++ b/gui/librarydialog.cpp @@ -43,6 +43,18 @@ LibraryDialog::~LibraryDialog() delete ui; } +CppcheckLibraryData::Function *LibraryDialog::currentFunction() +{ + QList 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 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) { diff --git a/gui/librarydialog.h b/gui/librarydialog.h index 82a4f5d70..07dfda5ba 100644 --- a/gui/librarydialog.h +++ b/gui/librarydialog.h @@ -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); }; diff --git a/gui/librarydialog.ui b/gui/librarydialog.ui index 1df1ca20a..d9ea2fcbd 100644 --- a/gui/librarydialog.ui +++ b/gui/librarydialog.ui @@ -6,8 +6,8 @@ 0 0 - 547 - 300 + 869 + 588 @@ -56,6 +56,36 @@ + + + + + + AZ + + + true + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -88,6 +118,9 @@ + + + @@ -186,22 +219,6 @@ - - functions - currentRowChanged(int) - LibraryDialog - selectFunction(int) - - - 155 - 218 - - - 327 - 299 - - - buttonOpen clicked() @@ -209,12 +226,12 @@ openCfg() - 61 - 27 + 59 + 18 - 72 - 21 + 66 + 34 @@ -225,12 +242,12 @@ changeFunction() - 372 - 69 + 739 + 74 - 475 - 5 + 750 + 74 @@ -241,12 +258,12 @@ changeFunction() - 419 - 99 + 735 + 103 - 319 - 3 + 744 + 102 @@ -257,12 +274,12 @@ saveCfg() - 102 - 9 + 118 + 16 - 115 - 1 + 130 + 32 @@ -273,12 +290,12 @@ addFunction() - 48 - 282 + 53 + 564 - 65 - 298 + 63 + 582 @@ -289,28 +306,12 @@ editArg() - 317 - 278 + 488 + 580 - 349 - 281 - - - - - noreturn - currentIndexChanged(int) - LibraryDialog - changeFunction(int) - - - 504 - 45 - - - 543 - 32 + 497 + 580 @@ -321,24 +322,89 @@ editArg() - 525 - 146 + 685 + 149 - 545 - 145 + 693 + 148 + + + + + sortFunctions + toggled(bool) + LibraryDialog + sortFunctions(bool) + + + 45 + 66 + + + 58 + 66 + + + + + filter + textChanged(QString) + LibraryDialog + filterFunctions(QString) + + + 257 + 565 + + + 273 + 582 + + + + + functions + itemSelectionChanged() + LibraryDialog + selectFunction() + + + 190 + 141 + + + 203 + 140 + + + + + noreturn + currentIndexChanged(int) + LibraryDialog + changeFunction() + + + 696 + 46 + + + 703 + 46 - selectFunction(int) - openCfg() - changeFunction() - saveCfg() - argumentChanged(QListWidgetItem*) addFunction() + argumentChanged(QListWidgetItem*) + changeFunction() editArg() - changeFunction(int) + filterFunctions(QString) + openCfg() + saveCfg() + selectFunction() + sortFunctions(bool)