Skip to content

Commit

Permalink
id_dialog: (Edit Subckt) cannot add new parameters
Browse files Browse the repository at this point in the history
* The operation is locked in a mutual update:
  - selection on the table update the edit fields
  - change on the edit fiels update/select the table
  - user never get clean input fields for a new set of parameters.

* Fix: Remove the mutual update, add Apply button to copy
  data from edit fields to table and clear the input fields.
  • Loading branch information
guitorri committed Jan 24, 2015
1 parent d983fc5 commit 9028169
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 78 deletions.
122 changes: 50 additions & 72 deletions qucs/qucs/paintings/id_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ ID_Dialog::ID_Dialog(ID_Text *idText_)

showCheck = new QCheckBox(tr("display in schematic"));
showCheck->setChecked(true);
connect(showCheck, SIGNAL(toggled(bool)), SLOT(slotToggleShow(bool)));

vbox_param->addWidget(showCheck);

Expand All @@ -109,29 +108,21 @@ ID_Dialog::ID_Dialog(ID_Text *idText_)
NameVal = new QRegExpValidator(Expr, this);
ParamNameEdit = new QLineEdit;
ParamNameEdit->setValidator(NameVal);
connect(ParamNameEdit, SIGNAL(textChanged(const QString&)),
SLOT(slotNameChanged(const QString&)));

Expr.setPattern("[^\"=]*");
ValueVal = new QRegExpValidator(Expr, this);
ValueEdit = new QLineEdit;
ValueEdit->setValidator(ValueVal);
connect(ValueEdit, SIGNAL(textChanged(const QString&)),
SLOT(slotValueChanged(const QString&)));

Expr.setPattern("[^\"=\\x005B\\x005D]*");
DescrVal = new QRegExpValidator(Expr, this);
DescriptionEdit = new QLineEdit;
DescriptionEdit->setValidator(DescrVal);
connect(DescriptionEdit, SIGNAL(textChanged(const QString&)),
SLOT(slotDescrChanged(const QString&)));

Expr.setPattern("[\\w_]+");
TypeVal = new QRegExpValidator(Expr, this);
TypeEdit = new QLineEdit;
TypeEdit->setValidator(TypeVal);
connect(TypeEdit, SIGNAL(textChanged(const QString&)),
SLOT(slotTypeChanged(const QString&)));

paramEditLayout->addWidget(ParamNameEdit, 0, 1);
paramEditLayout->addWidget(ValueEdit, 1, 1);
Expand All @@ -151,17 +142,19 @@ ID_Dialog::ID_Dialog(ID_Text *idText_)

QPushButton *ButtOK = new QPushButton(tr("OK"));
connect(ButtOK, SIGNAL(clicked()), SLOT(slotOk()));
QPushButton *ButtApply = new QPushButton(tr("Apply"));
connect(ButtApply, SIGNAL(clicked()), SLOT(slotApply()));
QPushButton *ButtCancel = new QPushButton(tr("Cancel"));
connect(ButtCancel, SIGNAL(clicked()), SLOT(reject()));

QHBoxLayout *hbox_bottom = new QHBoxLayout;
hbox_bottom->setSpacing(5);
all->addLayout(hbox_bottom);
hbox_bottom->addWidget(ButtOK);
hbox_bottom->addWidget(ButtApply);
hbox_bottom->addWidget(ButtCancel);

this->setLayout(all);
resize(320, 400);
}

ID_Dialog::~ID_Dialog()
Expand All @@ -174,17 +167,15 @@ ID_Dialog::~ID_Dialog()
delete TypeVal;
}

// -----------------------------------------------------------

/*!
* \brief ID_Dialog::slotEditParameter
* Place data from selected table row in the edit fields.
*/
void ID_Dialog::slotEditParameter()
{
int row = ParamTable->currentRow();
if (row < 0 || row >= ParamTable->rowCount()) {
ParamTable->clearSelection();
ParamNameEdit->clear();
showCheck->setChecked(true);
ValueEdit->clear();
DescriptionEdit->clear();
TypeEdit->clear();
return;
}

Expand All @@ -195,7 +186,12 @@ void ID_Dialog::slotEditParameter()
TypeEdit->setText(ParamTable->item(row, 4)->text());
}

// -----------------------------------------------------------

/*!
* \brief ID_Dialog::slotAddParameter
* Add new set of parameters from edit fields into table.
* Select added row.
*/
void ID_Dialog::slotAddParameter()
{
if(ParamNameEdit->text().isEmpty())
Expand Down Expand Up @@ -237,71 +233,26 @@ void ID_Dialog::slotAddParameter()
ParamTable->setItem(row, 4, item);

ParamTable->setCurrentCell(row, 0);
slotEditParameter(); // clear entry fields
ParamTable->clearSelection();
}

// -----------------------------------------------------------

/*!
* \brief ID_Dialog::slotRemoveParameter
* Remove selected row from table.
*/
void ID_Dialog::slotRemoveParameter()
{
int selectedrow = ParamTable->currentRow();
ParamTable->removeRow(selectedrow);
int nextRow = (selectedrow == ParamTable->rowCount())? selectedrow-1 : selectedrow;
ParamTable->setCurrentCell(nextRow, 0);
slotEditParameter();
}

// -----------------------------------------------------------
void ID_Dialog::slotToggleShow(bool On)
{
int selectedrow = ParamTable->currentRow();
QTableWidgetItem *item = ParamTable->item(selectedrow, 0);
if (item) {
item->setText(On ? tr("yes") : tr("no"));
}
}

// -----------------------------------------------------------
void ID_Dialog::slotNameChanged(const QString& text)
{
int selectedrow = ParamTable->currentRow();
QTableWidgetItem *item = ParamTable->item(selectedrow, 1);
if (item) {
item->setText(text);
}
}

// -----------------------------------------------------------
void ID_Dialog::slotValueChanged(const QString& text)
{
int selectedrow = ParamTable->currentRow();
QTableWidgetItem *item = ParamTable->item(selectedrow, 2);
if (item) {
item->setText(text);
}
}

// -----------------------------------------------------------
void ID_Dialog::slotDescrChanged(const QString& text)
{
int selectedrow = ParamTable->currentRow();
QTableWidgetItem *item = ParamTable->item(selectedrow, 3);
if (item) {
item->setText(text);
}
}

// -----------------------------------------------------------
void ID_Dialog::slotTypeChanged(const QString& text)
{
int selectedrow = ParamTable->currentRow();
QTableWidgetItem *item = ParamTable->item(selectedrow, 4);
if (item) {
item->setText(text);
}
}

// -----------------------------------------------------------
/*!
* \brief ID_Dialog::slotOk
* Commit changes from dialog table to component properties.
*/
void ID_Dialog::slotOk()
{
bool changed = false;
Expand Down Expand Up @@ -348,3 +299,30 @@ void ID_Dialog::slotOk()
if(changed) accept();
else reject();
}


/*!
* \brief ID_Dialog::slotApply
* Apply data from edit fields to table. Clear edit fields.
*/
void ID_Dialog::slotApply()
{
int selectedrow = ParamTable->currentRow();
QTableWidgetItem *item;
item = ParamTable->item(selectedrow, 0);
item->setText(showCheck->isChecked() ? tr("yes") : tr("no"));
item = ParamTable->item(selectedrow, 1);
item->setText(ParamNameEdit->text());
item = ParamTable->item(selectedrow, 2);
item->setText(ValueEdit->text());
item = ParamTable->item(selectedrow, 3);
item->setText(DescriptionEdit->text());
item = ParamTable->item(selectedrow, 4);
item->setText(TypeEdit->text());

ParamTable->setCurrentCell(selectedrow,0);
ParamNameEdit->clear();
ValueEdit->clear();
DescriptionEdit->clear();
TypeEdit->clear();
}
14 changes: 8 additions & 6 deletions qucs/qucs/paintings/id_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* *
***************************************************************************/

/*! \file id_dialog.h
* \brief Dialog to edit parameters in a subcircuit symbol.
*/

#ifndef ID_DIALOG_H
#define ID_DIALOG_H

Expand All @@ -28,7 +32,9 @@ class QCheckBox;
class QVBoxLayout;
class QRegExpValidator;


/*!
* \brief The ID_Dialog class, edit subcircuit symbol properties.
*/
class ID_Dialog : public QDialog {
Q_OBJECT
public:
Expand All @@ -50,14 +56,10 @@ Q_OBJECT

private slots:
void slotOk();
void slotApply();
void slotAddParameter();
void slotRemoveParameter();
void slotEditParameter();
void slotToggleShow(bool);
void slotNameChanged(const QString&);
void slotValueChanged(const QString&);
void slotDescrChanged(const QString&);
void slotTypeChanged(const QString&);
};

#endif

0 comments on commit 9028169

Please sign in to comment.