GUI: Let user add function in the library editor

This commit is contained in:
Daniel Marjamäki 2015-08-29 18:50:08 +02:00
parent 6aeb3ff5e3
commit f5d131671c
4 changed files with 69 additions and 2 deletions

View File

@ -132,6 +132,8 @@ bool LibraryData::open(QIODevice &file)
if (!doc.setContent(&file))
return false;
clear();
QDomElement rootElement = doc.firstChildElement("def");
QStringList comments;
for (QDomNode n = rootElement.firstChild(); !n.isNull(); n = n.nextSibling()) {

View File

@ -23,6 +23,7 @@
#include <QSettings>
#include <QFileDialog>
#include <QTextStream>
#include <QInputDialog>
// TODO: get/compare functions from header
@ -57,13 +58,16 @@ void LibraryDialog::openCfg()
mFileName.clear();
QFile file(selectedFile);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
ignoreChanges = true;
data.open(file);
mFileName = selectedFile;
ui->buttonSave->setEnabled(false);
ui->functions->clear();
foreach(const struct LibraryData::Function &function, data.functions)
foreach(const struct LibraryData::Function &function, data.functions) {
ui->functions->addItem(function.name);
}
ignoreChanges = false;
}
}
}
@ -79,6 +83,25 @@ void LibraryDialog::saveCfg()
}
}
void LibraryDialog::addFunction()
{
LibraryData::Function f;
bool ok;
f.name = QInputDialog::getText(this, tr("Add function"), tr("Function name"), QLineEdit::Normal, "doStuff", &ok);
if (!ok)
return;
int args = QInputDialog::getInt(this, tr("Add function"), tr("Number of arguments"), 0, 0, 20, 1, &ok);
if (!ok)
return;
for (int i = 1; i <= args; i++) {
LibraryData::Function::Arg arg;
arg.nr = i;
f.args.append(arg);
}
data.functions.append(f);
ui->functions->addItem(f.name);
}
void LibraryDialog::selectFunction(int row)
{
ignoreChanges = true;

View File

@ -40,6 +40,7 @@ public:
private slots:
void openCfg();
void saveCfg();
void addFunction();
void selectFunction(int row);
void changeFunction();
void argumentChanged(QListWidgetItem *);

View File

@ -66,6 +66,30 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="addFunction">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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>
</layout>
</item>
<item>
@ -234,6 +258,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>addFunction</sender>
<signal>clicked()</signal>
<receiver>LibraryDialog</receiver>
<slot>addFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>48</x>
<y>282</y>
</hint>
<hint type="destinationlabel">
<x>65</x>
<y>298</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>selectFunction(int)</slot>
@ -241,5 +281,6 @@
<slot>changeFunction()</slot>
<slot>saveCfg()</slot>
<slot>argumentChanged(QListWidgetItem*)</slot>
<slot>addFunction()</slot>
</slots>
</ui>