Skip to content

Commit

Permalink
https://github.com/StephaneCouturier/Katalog/issues/340
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneCouturier committed Dec 3, 2024
1 parent 9aa98c8 commit 644ec58
Show file tree
Hide file tree
Showing 12 changed files with 610 additions and 484 deletions.
36 changes: 36 additions & 0 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,42 @@ bool Device::verifyStorageExternalIDExists()
return queryExternalID.value(0).toInt() > 0;
}

bool Device::verifyDeviceHasSourceMapping()
{
QSqlQuery query(QSqlDatabase::database("defaultConnection"));
query.prepare("SELECT COUNT(*) FROM device_mapping WHERE mapping_device_source_id = :deviceId");
query.bindValue(":deviceId", ID);

if (!query.exec()) {
return false;
}

if (query.next()) {
int count = query.value(0).toInt();
return count > 0;
}

return false;
}

bool Device::verifyDeviceHasTargetMapping()
{
QSqlQuery query(QSqlDatabase::database("defaultConnection"));
query.prepare("SELECT COUNT(*) FROM device_mapping WHERE mapping_device_target_id = :deviceId");
query.bindValue(":deviceId", ID);

if (!query.exec()) {
return false;
}

if (query.next()) {
int count = query.value(0).toInt();
return count > 0;
}

return false;
}

void Device::getIDFromDeviceName()
{
QSqlQuery queryIDFromDeviceName(QSqlDatabase::database("defaultConnection"));
Expand Down
2 changes: 2 additions & 0 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class Device
bool verifyDeviceNameExists();
bool verifyParentDeviceExistsInPhysicalGroup();
bool verifyStorageExternalIDExists();
bool verifyDeviceHasSourceMapping();
bool verifyDeviceHasTargetMapping();
void getIDFromDeviceName();
void updateActive(QString connectionName);

Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,9 @@ class MainWindow : public QMainWindow
void on_BackUp_pushButton_SaveMapping_clicked();
void on_BackUp_pushButton_ReloadDeviceMappings_clicked();
void on_BackUp_pushButton_ReloadSourceList_clicked();
void on_BackUp_pushButton_ReloadSourceListWithoutMapping_clicked();
void on_BackUp_pushButton_ReloadTargetList_clicked();
void on_BackUp_pushButton_DeleteSelectedMapping_clicked();
void on_BackUp_pushButton_ReloadTargetListWithoutMapping_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();
Expand Down
32 changes: 32 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7410,6 +7410,22 @@ background: url(:/images/link-h.png) repeat-x center;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="BackUp_pushButton_ReloadSourceListWithoutMapping">
<property name="maximumSize">
<size>
<width>250</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>without mapping</string>
</property>
<property name="icon">
<iconset theme="view-refresh"/>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
Expand Down Expand Up @@ -7437,6 +7453,22 @@ background: url(:/images/link-h.png) repeat-x center;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="BackUp_pushButton_ReloadTargetListWithoutMapping">
<property name="maximumSize">
<size>
<width>250</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>without mapping</string>
</property>
<property name="icon">
<iconset theme="view-refresh"/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
61 changes: 46 additions & 15 deletions src/mainwindow_tab_backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ void MainWindow::on_BackUp_pushButton_ReloadSourceList_clicked()
loadBackUpDeviceLists("Source");
}

void MainWindow::on_BackUp_pushButton_ReloadSourceListWithoutMapping_clicked()
{
loadBackUpDeviceLists("Source_without_mapping");
}

void MainWindow::on_BackUp_pushButton_ReloadTargetList_clicked()
{
loadBackUpDeviceLists("Target");
}

void MainWindow::on_BackUp_pushButton_ReloadTargetListWithoutMapping_clicked()
{
loadBackUpDeviceLists("Target_without_mapping");
}

void MainWindow::on_BackUp_pushButton_ReloadDeviceMappings_clicked()
{
loadBackUpMapping();
Expand Down Expand Up @@ -311,30 +321,51 @@ void MainWindow::loadBackUpDeviceLists(QString list)
tempParentDevice.ID = tempDevice.parentID;
tempParentDevice.loadDevice("defaultConnection");

//Add row
QList<QStandardItem*> row;
row.append(new QStandardItem(tempParentDevice.name));
row.append(new QStandardItem(QString::number(tempDevice.ID)));
row.append(new QStandardItem(tempDevice.name));
model->appendRow(row);
//Add row if valid for the type of list
if (list == "Source_without_mapping") {
// Only add devices that do NOT have a mapping
if (!tempDevice.verifyDeviceHasSourceMapping()) {
QList<QStandardItem*> row;
row.append(new QStandardItem(tempParentDevice.name));
row.append(new QStandardItem(QString::number(tempDevice.ID)));
row.append(new QStandardItem(tempDevice.name));
model->appendRow(row);
}
}
else if (list == "Target_without_mapping") {
// Only add devices that do NOT have a mapping
if (!tempDevice.verifyDeviceHasTargetMapping()) {
QList<QStandardItem*> row;
row.append(new QStandardItem(tempParentDevice.name));
row.append(new QStandardItem(QString::number(tempDevice.ID)));
row.append(new QStandardItem(tempDevice.name));
model->appendRow(row);
}
}
else {
// For other list types, add all devices
QList<QStandardItem*> row;
row.append(new QStandardItem(tempParentDevice.name));
row.append(new QStandardItem(QString::number(tempDevice.ID)));
row.append(new QStandardItem(tempDevice.name));
model->appendRow(row);
}
}
}

//Load model to the Source view
if (list =="Source"){
ui->BackUp_treeView_List1->setModel(model);
ui->BackUp_treeView_List1->resizeColumnToContents(1);
ui->BackUp_treeView_List1->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->BackUp_treeView_List1->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
}

//Load model to the Target view
if (list =="Target"){
if (list.contains("Target")){
ui->BackUp_treeView_List2->setModel(model);
ui->BackUp_treeView_List2->resizeColumnToContents(1);
ui->BackUp_treeView_List2->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->BackUp_treeView_List2->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
else{
ui->BackUp_treeView_List1->setModel(model);
ui->BackUp_treeView_List1->resizeColumnToContents(1);
ui->BackUp_treeView_List1->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->BackUp_treeView_List1->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
}

void MainWindow::saveNewMapping()
Expand Down
Binary file modified src/translations/Katalog_cz_CZ.qm
Binary file not shown.
Loading

0 comments on commit 644ec58

Please sign in to comment.