Skip to content

Commit 3789777

Browse files
committed
Review remarks
1 parent c57dd21 commit 3789777

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/dialogs/adaptersettings.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void AdapterSettings::buildSection(const QJsonObject& propSchema, const QJsonVal
5454
auto* form = new SchemaFormWidget(_pItemTabs);
5555
form->setSchema(_itemSchema, itemsArray.at(i).toObject());
5656
pages.append(form);
57-
names.append(QString("%1 %2").arg(_propertyKey[0].toUpper() + _propertyKey.mid(1)).arg(i + 1));
57+
names.append(formatTabName(i + 1));
5858
}
5959

6060
if (!pages.isEmpty())
@@ -77,19 +77,26 @@ void AdapterSettings::buildSection(const QJsonObject& propSchema, const QJsonVal
7777
}
7878
}
7979

80+
QString AdapterSettings::formatTabName(int index) const
81+
{
82+
if (_propertyKey.isEmpty())
83+
{
84+
return QString("Item %1").arg(index);
85+
}
86+
return QString("%1 %2").arg(_propertyKey[0].toUpper() + _propertyKey.mid(1)).arg(index);
87+
}
88+
8089
void AdapterSettings::addItemTab()
8190
{
8291
auto* form = new SchemaFormWidget(_pItemTabs);
8392
QJsonObject defaultValues;
84-
const QJsonArray defaultItems =
85-
_pSettingsModel->adapterData(_adapterId)->defaults().value(_propertyKey).toArray();
93+
const QJsonArray defaultItems = _pSettingsModel->adapterData(_adapterId)->defaults().value(_propertyKey).toArray();
8694
if (!defaultItems.isEmpty())
8795
{
8896
defaultValues = defaultItems.first().toObject();
8997
}
9098
form->setSchema(_itemSchema, defaultValues);
91-
const QString name =
92-
QString("%1 %2").arg(_propertyKey[0].toUpper() + _propertyKey.mid(1)).arg(_nextItemTabIndex);
99+
const QString name = formatTabName(_nextItemTabIndex);
93100
_nextItemTabIndex++;
94101
_pItemTabs->addNewTab(name, form);
95102
}

src/dialogs/adaptersettings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class AdapterSettings : public QWidget
4848
void buildSection(const QJsonObject& propSchema, const QJsonValue& configValue, QVBoxLayout* layout);
4949
void addItemTab();
5050

51+
//! \brief Returns a display name for a tab at the given 1-based \a index.
52+
QString formatTabName(int index) const;
53+
5154
SettingsModel* _pSettingsModel;
5255
QString _adapterId;
5356
QString _propertyKey;

tests/customwidgets/tst_schemaformwidget.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ void TestSchemaFormWidget::conditionalSwitchShowsSerialHidesTcp()
344344
}
345345
}
346346
QVERIFY(typeCombo != nullptr);
347-
if (typeCombo == nullptr)
348-
{
349-
return;
350-
}
351347
typeCombo->setCurrentIndex(typeCombo->findData(QStringLiteral("serial")));
352348

353349
const QJsonObject result = w.values();

0 commit comments

Comments
 (0)