GUI: Library editor - rename function
This commit is contained in:
parent
7d229f082c
commit
a32aa03035
|
@ -4,10 +4,6 @@
|
|||
#include <QRegExp>
|
||||
#include <QValidator>
|
||||
|
||||
#define SIMPLENAME "[_a-zA-Z][_a-zA-Z0-9]*" // just a name
|
||||
#define SCOPENAME SIMPLENAME "(::" SIMPLENAME ")*" // names with optional scope
|
||||
#define NAMES SCOPENAME "(," SCOPENAME ")*" // names can be separated by comma
|
||||
|
||||
LibraryAddFunctionDialog::LibraryAddFunctionDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::LibraryAddFunctionDialog)
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
#include <QDialog>
|
||||
|
||||
#define SIMPLENAME "[_a-zA-Z][_a-zA-Z0-9]*" // just a name
|
||||
#define SCOPENAME SIMPLENAME "(::" SIMPLENAME ")*" // names with optional scope
|
||||
#define NAMES SCOPENAME "(," SCOPENAME ")*" // names can be separated by comma
|
||||
|
||||
namespace Ui {
|
||||
class LibraryAddFunctionDialog;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,20 @@
|
|||
|
||||
// TODO: get/compare functions from header
|
||||
|
||||
class FunctionListItem : public QListWidgetItem {
|
||||
public:
|
||||
FunctionListItem(QListWidget *view,
|
||||
CppcheckLibraryData::Function *function,
|
||||
bool selected)
|
||||
: QListWidgetItem(view), function(function)
|
||||
{
|
||||
setText(function->name);
|
||||
setFlags(flags() | Qt::ItemIsEditable);
|
||||
setSelected(selected);
|
||||
}
|
||||
CppcheckLibraryData::Function *function;
|
||||
};
|
||||
|
||||
LibraryDialog::LibraryDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::LibraryDialog),
|
||||
|
@ -50,11 +64,7 @@ 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;
|
||||
return dynamic_cast<FunctionListItem *>(selitems.first())->function;
|
||||
}
|
||||
|
||||
void LibraryDialog::openCfg()
|
||||
|
@ -80,8 +90,10 @@ void LibraryDialog::openCfg()
|
|||
ui->buttonSave->setEnabled(false);
|
||||
ui->filter->clear();
|
||||
ui->functions->clear();
|
||||
foreach(const struct CppcheckLibraryData::Function &function, data.functions) {
|
||||
ui->functions->addItem(function.name);
|
||||
for (struct CppcheckLibraryData::Function &function : data.functions) {
|
||||
ui->functions->addItem(new FunctionListItem(ui->functions,
|
||||
&function,
|
||||
false));
|
||||
}
|
||||
ui->sortFunctions->setEnabled(!data.functions.empty());
|
||||
ui->filter->setEnabled(!data.functions.empty());
|
||||
|
@ -117,7 +129,7 @@ void LibraryDialog::addFunction()
|
|||
f.args.append(arg);
|
||||
}
|
||||
data.functions.append(f);
|
||||
ui->functions->addItem(f.name);
|
||||
ui->functions->addItem(new FunctionListItem(ui->functions, &data.functions.back(), false));
|
||||
ui->buttonSave->setEnabled(true);
|
||||
ui->sortFunctions->setEnabled(!data.functions.empty());
|
||||
ui->filter->setEnabled(!data.functions.empty());
|
||||
|
@ -125,6 +137,24 @@ void LibraryDialog::addFunction()
|
|||
delete d;
|
||||
}
|
||||
|
||||
void LibraryDialog::editFunctionName(QListWidgetItem* item)
|
||||
{
|
||||
if (ignoreChanges)
|
||||
return;
|
||||
QString functionName = item->text();
|
||||
CppcheckLibraryData::Function * const function = dynamic_cast<FunctionListItem*>(item)->function;
|
||||
if (functionName != function->name) {
|
||||
if (QRegExp(NAMES).exactMatch(functionName)) {
|
||||
function->name = functionName;
|
||||
ui->buttonSave->setEnabled(true);
|
||||
} else {
|
||||
ignoreChanges = true;
|
||||
item->setText(function->name);
|
||||
ignoreChanges = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryDialog::selectFunction()
|
||||
{
|
||||
const CppcheckLibraryData::Function * const function = currentFunction();
|
||||
|
@ -147,17 +177,16 @@ void LibraryDialog::selectFunction()
|
|||
|
||||
void LibraryDialog::sortFunctions(bool sort)
|
||||
{
|
||||
if (sort)
|
||||
if (sort) {
|
||||
ui->functions->sortItems();
|
||||
else {
|
||||
} else {
|
||||
ignoreChanges = true;
|
||||
CppcheckLibraryData::Function *selfunction = currentFunction();
|
||||
ui->functions->clear();
|
||||
foreach(const struct CppcheckLibraryData::Function &function, data.functions) {
|
||||
QListWidgetItem *item = new QListWidgetItem(ui->functions);
|
||||
item->setText(function.name);
|
||||
item->setSelected(selfunction == &function);
|
||||
ui->functions->addItem(item);
|
||||
for (struct CppcheckLibraryData::Function &function : data.functions) {
|
||||
ui->functions->addItem(new FunctionListItem(ui->functions,
|
||||
&function,
|
||||
selfunction == &function));
|
||||
}
|
||||
if (!ui->filter->text().isEmpty())
|
||||
filterFunctions(ui->filter->text());
|
||||
|
|
|
@ -43,6 +43,7 @@ private slots:
|
|||
void addFunction();
|
||||
void changeFunction();
|
||||
void editArg();
|
||||
void editFunctionName(QListWidgetItem*);
|
||||
void filterFunctions(QString);
|
||||
void selectFunction();
|
||||
void sortFunctions(bool);
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
<item>
|
||||
<widget class="QListWidget" name="functions">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
<set>QAbstractItemView::DoubleClicked</set>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
|
@ -313,8 +313,8 @@
|
|||
<slot>editArg()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>488</x>
|
||||
<y>580</y>
|
||||
<x>519</x>
|
||||
<y>575</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>497</x>
|
||||
|
@ -361,8 +361,8 @@
|
|||
<slot>filterFunctions(QString)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>257</x>
|
||||
<y>565</y>
|
||||
<x>429</x>
|
||||
<y>575</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>273</x>
|
||||
|
@ -402,6 +402,22 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>functions</sender>
|
||||
<signal>itemChanged(QListWidgetItem*)</signal>
|
||||
<receiver>LibraryDialog</receiver>
|
||||
<slot>editFunctionName(QListWidgetItem*)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>217</x>
|
||||
<y>104</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>235</x>
|
||||
<y>104</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>addFunction()</slot>
|
||||
|
@ -413,5 +429,6 @@
|
|||
<slot>saveCfg()</slot>
|
||||
<slot>selectFunction()</slot>
|
||||
<slot>sortFunctions(bool)</slot>
|
||||
<slot>editFunctionName(QListWidgetItem*)</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue