UI: ZonesWindow: Simplify saveZoneEditForm()

This commit is contained in:
Nodir Temirkhodjaev 2023-05-21 13:03:28 +03:00
parent 8e2c84ed20
commit bb4737be14
2 changed files with 30 additions and 10 deletions

View File

@ -423,23 +423,38 @@ bool ZonesWindow::saveZoneEditForm()
// Check custom url
if (zone.customUrl && zone.url.isEmpty()) {
m_editUrl->setText(zoneSource.url());
m_editUrl->selectAll();
m_editUrl->setFocus();
m_editFormData->setText(zoneSource.formData());
return false;
return saveZoneEditFormCustom(zoneSource);
}
// Add new zone
if (m_formZoneIsNew) {
if (confManager()->addZone(zone)) {
m_zoneListView->selectCell(zone.zoneId - 1);
return true;
}
return false;
return saveZoneEditFormNew(zone);
}
// Edit selected zone
return saveZoneEditFormEdit(zone);
}
bool ZonesWindow::saveZoneEditFormCustom(const ZoneSourceWrapper &zoneSource)
{
m_editUrl->setText(zoneSource.url());
m_editUrl->selectAll();
m_editUrl->setFocus();
m_editFormData->setText(zoneSource.formData());
return false;
}
bool ZonesWindow::saveZoneEditFormNew(Zone &zone)
{
if (confManager()->addZone(zone)) {
m_zoneListView->selectCell(zone.zoneId - 1);
return true;
}
return false;
}
bool ZonesWindow::saveZoneEditFormEdit(Zone &zone)
{
const auto zoneRow = zoneListModel()->zoneRowAt(zoneListCurrentIndex());
if (zoneRow.isNull())
return false;

View File

@ -17,7 +17,9 @@ class TableView;
class TaskManager;
class WidgetWindowStateWatcher;
class WindowManager;
class Zone;
class ZoneListModel;
class ZoneSourceWrapper;
class ZonesController;
class ZonesWindow : public WidgetWindow
@ -58,6 +60,9 @@ private:
void updateZoneEditForm(bool editCurrentZone);
bool saveZoneEditForm();
bool saveZoneEditFormCustom(const ZoneSourceWrapper &zoneSource);
bool saveZoneEditFormNew(Zone &zone);
bool saveZoneEditFormEdit(Zone &zone);
void updateZone(int row, bool enabled);
void deleteZone(int row);