From f7ffa0b942a71f397ea882c3167537e5eb975783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Couturier?= Date: Mon, 2 Dec 2024 23:19:02 +0100 Subject: [PATCH] https://github.com/StephaneCouturier/Katalog/issues/340 --- src/mainwindow.cpp | 14 +++--- src/mainwindow.h | 2 + src/mainwindow.ui | 17 ++++++++ src/mainwindow_setup.cpp | 6 +++ src/mainwindow_tab_backup.cpp | 80 ++++++++++++++++++++++++++--------- 5 files changed, 93 insertions(+), 26 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6e25e3e..4554ef7 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -48,7 +48,7 @@ MainWindow::MainWindow(QWidget *parent) : //Set current version, release date, and development mode currentVersion = "2.3"; collection->appVersion = currentVersion; - releaseDate = "2024-11-30"; + releaseDate = "2024-12-02"; developmentMode = false; themeID = 1; //default value for the theme = Katalog Colors (light). selectedTab = 3; //default value for the first launch = Create screen. @@ -85,10 +85,14 @@ MainWindow::MainWindow(QWidget *parent) : hideDevelopmentUIItems(); } - QButtonGroup buttonGroup; - buttonGroup.addButton(ui->Devices_radioButton_DeviceTree); - buttonGroup.addButton(ui->Devices_radioButton_StorageList); - buttonGroup.addButton(ui->Devices_radioButton_CatalogList); + QButtonGroup buttonGroupDevices; + buttonGroupDevices.addButton(ui->Devices_radioButton_DeviceTree); + buttonGroupDevices.addButton(ui->Devices_radioButton_StorageList); + buttonGroupDevices.addButton(ui->Devices_radioButton_CatalogList); + + QButtonGroup buttonGroupBackUp; + buttonGroupBackUp.addButton(ui->BackUp_radioButton_Source); + buttonGroupBackUp.addButton(ui->BackUp_radioButton_Target); //Settings screen ui->Settings_lineEdit_DatabaseFilePath->setText(collection->databaseFilePath); diff --git a/src/mainwindow.h b/src/mainwindow.h index 4649396..ab29b85 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -544,6 +544,8 @@ class MainWindow : public QMainWindow void on_BackUp_pushButton_ReloadTargetList_clicked(); void on_BackUp_pushButton_DeleteSelectedMapping_clicked(); void on_BackUp_checkBox_DisplayFullTable_checkStateChanged(const Qt::CheckState &arg1); + void on_BackUp_radioButton_Source_clicked(); + void on_BackUp_radioButton_Target_clicked(); //Statistics void on_Statistics_pushButton_EditDeviceStatisticsFile_clicked(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 7beb51e..6f13936 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -7466,6 +7466,23 @@ background: url(:/images/link-h.png) repeat-x center; + + + + based on Sources + + + true + + + + + + + based on Targets + + + diff --git a/src/mainwindow_setup.cpp b/src/mainwindow_setup.cpp index 0cedccd..6e3e0ae 100755 --- a/src/mainwindow_setup.cpp +++ b/src/mainwindow_setup.cpp @@ -472,6 +472,12 @@ fileSortCaseSensitive = settings.value("Settings/FileCaseSensitiveSort").toBool(); ui->Settings_checkBox_SettingsFileCaseSensitiveSort->setChecked(fileSortCaseSensitive); + //BackUp Tab + QString filterMappingTable = settings.value("BackUp/FilterMappingTable", "Source").toString(); + if(filterMappingTable=="Target"){ + ui->BackUp_radioButton_Target->setChecked(true); + } + //Restore DEV Settings if(developmentMode==true){ ui->Settings_comboBox_DatabaseMode->setCurrentText(tr(collection->databaseMode.toStdString().c_str())); diff --git a/src/mainwindow_tab_backup.cpp b/src/mainwindow_tab_backup.cpp index 5ad9ccc..fb79733 100644 --- a/src/mainwindow_tab_backup.cpp +++ b/src/mainwindow_tab_backup.cpp @@ -89,6 +89,17 @@ void MainWindow::on_BackUp_checkBox_DisplayFullTable_checkStateChanged(const Qt: loadBackUpMapping(); } +void MainWindow::on_BackUp_radioButton_Source_clicked() +{ + QSettings settings(collection->settingsFilePath, QSettings:: IniFormat); + settings.setValue("BackUp/FilterMappingTable", "Source"); +} + +void MainWindow::on_BackUp_radioButton_Target_clicked() +{ + QSettings settings(collection->settingsFilePath, QSettings:: IniFormat); + settings.setValue("BackUp/FilterMappingTable", "Target"); +} //Methods----------------------------------------------------------------------- @@ -149,28 +160,55 @@ void MainWindow::loadBackUpMapping() AND dm.mapping_device_target_id = d2.device_id )"); - if ( selectedDevice->type == "Storage" ){ - querySQL += " AND d1.device_parent_id =:device_parent_id "; - } - else if ( selectedDevice->type == "Catalog" ){ - querySQL += " AND d1.device_id =:device_id "; + if(ui->BackUp_radioButton_Target->isChecked()==true){ + if ( selectedDevice->type == "Storage" ){ + querySQL += " AND d2.device_parent_id =:device_parent_id "; + } + else if ( selectedDevice->type == "Catalog" ){ + querySQL += " AND d2.device_id =:device_id "; + } + else if ( selectedDevice->type == "Virtual" ){ + QString prepareSQL = QLatin1String(R"( + AND d2.device_id IN ( + WITH RECURSIVE hierarchy AS ( + SELECT device_id, device_parent_id, device_name + FROM device + WHERE device_id = :device_id + UNION ALL + SELECT t.device_id, t.device_parent_id, t.device_name + FROM device t + JOIN hierarchy h ON t.device_parent_id = h.device_id + ) + SELECT device_id + FROM hierarchy) + )"); + querySQL += prepareSQL; + } } - else if ( selectedDevice->type == "Virtual" ){ - QString prepareSQL = QLatin1String(R"( - AND d1.device_id IN ( - WITH RECURSIVE hierarchy AS ( - SELECT device_id, device_parent_id, device_name - FROM device - WHERE device_id = :device_id - UNION ALL - SELECT t.device_id, t.device_parent_id, t.device_name - FROM device t - JOIN hierarchy h ON t.device_parent_id = h.device_id - ) - SELECT device_id - FROM hierarchy) - )"); - querySQL += prepareSQL; + else{ + if ( selectedDevice->type == "Storage" ){ + querySQL += " AND d1.device_parent_id =:device_parent_id "; + } + else if ( selectedDevice->type == "Catalog" ){ + querySQL += " AND d1.device_id =:device_id "; + } + else if ( selectedDevice->type == "Virtual" ){ + QString prepareSQL = QLatin1String(R"( + AND d1.device_id IN ( + WITH RECURSIVE hierarchy AS ( + SELECT device_id, device_parent_id, device_name + FROM device + WHERE device_id = :device_id + UNION ALL + SELECT t.device_id, t.device_parent_id, t.device_name + FROM device t + JOIN hierarchy h ON t.device_parent_id = h.device_id + ) + SELECT device_id + FROM hierarchy) + )"); + querySQL += prepareSQL; + } } querySQL +=" ORDER BY dm.mapping_name ASC ";