Skip to content

Commit d204b34

Browse files
committed
Refs #130 | dialognodeedit: fix dialog UX issues for custom node attributes
- Fix Remove selected button staying enabled after deselection - Fix getNodeShape() missing nodeShape="circle" for Circle case - Fix getUserChoices() re-inserting stale attributes by rebuilding hash entirely from table contents on OK - Fix Add button silent failure: highlight empty key/value fields with red colorize effect when Add is clicked with missing input - Fix Add button label invisible due to missing color in stylesheet - Fix Remove selected disabled state styling (was too dark) - Set customAttributesTable horizontalHeaderStretchLastSection=true so Value column fills available width
1 parent c25ed09 commit d204b34

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed

src/forms/dialognodeedit.cpp

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ DialogNodeEdit::DialogNodeEdit(QWidget *parent,
146146
this, &DialogNodeEdit::getNodeIconFile);
147147

148148
connect(ui->addPropertyBtn, &QPushButton::clicked, this, &DialogNodeEdit::on_addPropertyButton_clicked);
149-
150-
connect(ui->customAttributesTable, &QTableWidget::itemSelectionChanged, [this]() {
151-
ui->removePropertyBtn->setEnabled(true);
152-
});
149+
150+
connect(ui->customAttributesTable, &QTableWidget::itemSelectionChanged, [this]()
151+
{ ui->removePropertyBtn->setEnabled(
152+
!ui->customAttributesTable->selectedItems().isEmpty()); });
153+
153154
connect(ui->removePropertyBtn, &QPushButton::clicked, this, &DialogNodeEdit::on_removePropertyButton_clicked);
154155
}
155156

@@ -184,6 +185,7 @@ void DialogNodeEdit::getNodeShape(const int &nodeShapeIndex)
184185
nodeShape = "box";
185186
break;
186187
case NodeShape::Circle:
188+
nodeShape = "circle";
187189
break;
188190
case NodeShape::Diamond:
189191
nodeShape = "diamond";
@@ -344,12 +346,14 @@ void DialogNodeEdit::getUserChoices()
344346
break;
345347
}
346348

347-
// ui->customAttributesTable
349+
// Rebuild custom attributes entirely from table contents
350+
m_customAttributes.clear();
348351
for (int i = 0; i < ui->customAttributesTable->rowCount(); ++i)
349352
{
350-
QString key = ui->customAttributesTable->item(i, 0)->text();
351-
QString value = ui->customAttributesTable->item(i, 1)->text();
352-
m_customAttributes.insert(key, value);
353+
QTableWidgetItem *keyItem = ui->customAttributesTable->item(i, 0);
354+
QTableWidgetItem *valueItem = ui->customAttributesTable->item(i, 1);
355+
if (keyItem && valueItem && !keyItem->text().isEmpty())
356+
m_customAttributes.insert(keyItem->text(), valueItem->text());
353357
}
354358
emit userChoices(nodeLabel, nodeSize, nodeColor, nodeShape, iconPath, m_customAttributes);
355359
}
@@ -382,21 +386,42 @@ void DialogNodeEdit::selectColor()
382386
*/
383387
void DialogNodeEdit::on_addPropertyButton_clicked()
384388
{
385-
QString key = ui->keyLineEdit->text();
386-
QString value = ui->valueLineEdit->text();
387-
if (!key.isEmpty() && !value.isEmpty())
389+
QString key = ui->keyLineEdit->text().trimmed();
390+
QString value = ui->valueLineEdit->text().trimmed();
391+
392+
// Highlight empty fields and return
393+
QGraphicsColorizeEffect *effect = nullptr;
394+
if (key.isEmpty())
388395
{
389-
m_customAttributes.insert(key, value);
390-
int row = ui->customAttributesTable->rowCount();
391-
ui->customAttributesTable->insertRow(row);
392-
ui->customAttributesTable->setItem(row, 0, new QTableWidgetItem(key));
393-
ui->customAttributesTable->setItem(row, 1, new QTableWidgetItem(value));
394-
ui->keyLineEdit->clear();
395-
ui->valueLineEdit->clear();
396+
effect = new QGraphicsColorizeEffect;
397+
effect->setColor(QColor("red"));
398+
ui->keyLineEdit->setGraphicsEffect(effect);
399+
}
400+
else
401+
{
402+
ui->keyLineEdit->setGraphicsEffect(nullptr);
396403
}
404+
if (value.isEmpty())
405+
{
406+
effect = new QGraphicsColorizeEffect;
407+
effect->setColor(QColor("red"));
408+
ui->valueLineEdit->setGraphicsEffect(effect);
409+
}
410+
else
411+
{
412+
ui->valueLineEdit->setGraphicsEffect(nullptr);
413+
}
414+
if (key.isEmpty() || value.isEmpty())
415+
return;
416+
417+
m_customAttributes.insert(key, value);
418+
int row = ui->customAttributesTable->rowCount();
419+
ui->customAttributesTable->insertRow(row);
420+
ui->customAttributesTable->setItem(row, 0, new QTableWidgetItem(key));
421+
ui->customAttributesTable->setItem(row, 1, new QTableWidgetItem(value));
422+
ui->keyLineEdit->clear();
423+
ui->valueLineEdit->clear();
397424
}
398-
399-
400425
/**
401426
* @brief Slot function called when the remove property button is clicked.
402427
*

src/forms/dialognodeedit.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
<bool>true</bool>
276276
</attribute>
277277
<attribute name="horizontalHeaderStretchLastSection">
278-
<bool>false</bool>
278+
<bool>true</bool>
279279
</attribute>
280280
<attribute name="verticalHeaderShowSortIndicator" stdset="0">
281281
<bool>true</bool>

src/qss/default.qss

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,20 @@ QPushButton#removePropertyBtn {
279279
margin:0;
280280
}
281281
QPushButton#removePropertyBtn:disabled {
282-
background-color: #32414B;
283-
border: 1px solid #32414B;
284-
color: #787878;
282+
background-color: #aaa;
283+
border: 1px solid #aaa;
284+
color: #eee;
285285
}
286286
QPushButton#removePropertyBtn:hover {
287287
background-color:#ff0000;
288288
}
289-
QPushButton#addPropertyBtn{
290-
background-color:#fff;
289+
QPushButton#addPropertyBtn {
290+
background-color: #fff;
291+
color: #222;
292+
min-width: 60px;
291293
min-height: 1.5ex;
292-
padding: 3px 0px;
293-
margin:0;
294+
padding: 3px 8px;
295+
margin: 0;
294296
}
295297

296298
QToolButton {

0 commit comments

Comments
 (0)