diff options
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/CMakeLists.txt | 3 | ||||
-rw-r--r-- | desktop-widgets/divesiteimportdialog.cpp | 80 | ||||
-rw-r--r-- | desktop-widgets/divesiteimportdialog.h | 40 | ||||
-rw-r--r-- | desktop-widgets/divesiteimportdialog.ui | 119 |
4 files changed, 242 insertions, 0 deletions
diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt index fbaff1d6c..53aef5dbf 100644 --- a/desktop-widgets/CMakeLists.txt +++ b/desktop-widgets/CMakeLists.txt @@ -22,6 +22,7 @@ set (SUBSURFACE_UI divecomputermanagementdialog.ui divelogexportdialog.ui divelogimportdialog.ui + divesiteimportdialog.ui diveplanner.ui diveshareexportdialog.ui downloadfromdivecomputer.ui @@ -87,6 +88,8 @@ set(SUBSURFACE_INTERFACE diveplanner.h diveshareexportdialog.cpp diveshareexportdialog.h + divesiteimportdialog.cpp + divesiteimportdialog.h downloadfromdivecomputer.cpp downloadfromdivecomputer.h filterwidget2.cpp diff --git a/desktop-widgets/divesiteimportdialog.cpp b/desktop-widgets/divesiteimportdialog.cpp new file mode 100644 index 000000000..ad45d97a5 --- /dev/null +++ b/desktop-widgets/divesiteimportdialog.cpp @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "desktop-widgets/divesiteimportdialog.h" +#include "desktop-widgets/command.h" +#include "core/display.h" +#include "core/qthelper.h" +#include "core/metrics.h" +#include "core/subsurface-string.h" +#include "desktop-widgets/mainwindow.h" +#include "qt-models/divesiteimportmodel.h" +#include "qt-models/models.h" + +#include <QShortcut> + +// Caller keeps ownership of "imported". The contents of "imported" will be consumed on execution of the dialog. +// On return, it will be empty. +DivesiteImportDialog::DivesiteImportDialog(struct dive_site_table &imported, QString source, QWidget *parent) : QDialog(parent), + importedSource(source) +{ + QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); + QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); + + divesiteImportedModel = new DivesiteImportedModel(this); + + int startingWidth = defaultModelFont().pointSize(); + + ui.setupUi(this); + ui.importedDivesitesView->setModel(divesiteImportedModel); + ui.importedDivesitesView->setSelectionBehavior(QAbstractItemView::SelectRows); + ui.importedDivesitesView->setSelectionMode(QAbstractItemView::SingleSelection); + ui.importedDivesitesView->horizontalHeader()->setStretchLastSection(true); + ui.importedDivesitesView->verticalHeader()->setVisible(false); + ui.importedDivesitesView->setColumnWidth(0, startingWidth * 14); + ui.importedDivesitesView->setColumnWidth(1, startingWidth * 12); + ui.importedDivesitesView->setColumnWidth(2, startingWidth * 8); + ui.importedDivesitesView->setColumnWidth(3, startingWidth * 14); + ui.selectAllButton->setEnabled(true); + ui.unselectAllButton->setEnabled(true); + + connect(ui.importedDivesitesView, &QTableView::clicked, divesiteImportedModel, &DivesiteImportedModel::changeSelected); + connect(ui.selectAllButton, &QPushButton::clicked, divesiteImportedModel, &DivesiteImportedModel::selectAll); + connect(ui.unselectAllButton, &QPushButton::clicked, divesiteImportedModel, &DivesiteImportedModel::selectNone); + connect(close, SIGNAL(activated()), this, SLOT(close())); + connect(quit, SIGNAL(activated()), parent, SLOT(close())); + + ui.ok->setEnabled(true); + + importedSites = imported; + imported.nr = imported.allocated = 0; + imported.dive_sites = nullptr; + + divesiteImportedModel->repopulate(&importedSites); +} + +DivesiteImportDialog::~DivesiteImportDialog() +{ + clear_dive_site_table(&importedSites); +} + +void DivesiteImportDialog::on_cancel_clicked() +{ + clear_dive_site_table(&importedSites); + done(-1); +} + +void DivesiteImportDialog::on_ok_clicked() +{ + // delete non-selected dive sites + struct dive_site_table selectedSites = { 0 }; + for (int i = 0; i < importedSites.nr; i++) + if (divesiteImportedModel->data(divesiteImportedModel->index(i, 0), Qt::CheckStateRole) == Qt::Checked) { + struct dive_site *newSite = alloc_dive_site(); + copy_dive_site(importedSites.dive_sites[i], newSite); + add_dive_site_to_table(newSite, &selectedSites); + } + + Command::importDiveSites(&selectedSites, importedSource); + clear_dive_site_table(&selectedSites); + clear_dive_site_table(&importedSites); + accept(); +} diff --git a/desktop-widgets/divesiteimportdialog.h b/desktop-widgets/divesiteimportdialog.h new file mode 100644 index 000000000..b137234e0 --- /dev/null +++ b/desktop-widgets/divesiteimportdialog.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef DIVESITEIMPORTDIALOG_H +#define DIVESITEIMPORTDIALOG_H + +#include <QDialog> +#include <QThread> +#include <QHash> +#include <QMap> +#include <QAbstractTableModel> +#include <memory> + +#include "ui_divesiteimportdialog.h" +#include "core/divesite.h" + +namespace Ui { + class DivesiteImportDialog; +} + +class DivesiteImportedModel; + +class DivesiteImportDialog : public QDialog { + Q_OBJECT +public: + DivesiteImportDialog(struct dive_site_table &imported, QString source, QWidget *parent = 0 ); + ~DivesiteImportDialog(); + +public +slots: + void on_ok_clicked(); + void on_cancel_clicked(); + +private: + Ui::DivesiteImportDialog ui; + struct dive_site_table importedSites; + QString importedSource; + + DivesiteImportedModel *divesiteImportedModel; +}; + +#endif // DIVESITEIMPORTDIALOG_H diff --git a/desktop-widgets/divesiteimportdialog.ui b/desktop-widgets/divesiteimportdialog.ui new file mode 100644 index 000000000..8ee80ba22 --- /dev/null +++ b/desktop-widgets/divesiteimportdialog.ui @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>DivesiteImportDialog</class> + <widget class="QDialog" name="DivesiteImportDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>747</width> + <height>535</height> + </rect> + </property> + <property name="windowTitle"> + <string>Select dive sites to import</string> + </property> + <property name="windowIcon"> + <iconset> + <normalon>:subsurface-icon</normalon> + </iconset> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="spacing"> + <number>5</number> + </property> + <property name="leftMargin"> + <number>5</number> + </property> + <property name="topMargin"> + <number>5</number> + </property> + <property name="rightMargin"> + <number>5</number> + </property> + <property name="bottomMargin"> + <number>5</number> + </property> + <item> + <layout class="QHBoxLayout" name="labelSelectAllNoneLayout"> + <property name="spacing"> + <number>5</number> + </property> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="selectAllButton"> + <property name="text"> + <string>Select all</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="unselectAllButton"> + <property name="text"> + <string>Unselect all</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QTableView" name="importedDivesitesView"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="buttonBoxLayout"> + <property name="spacing"> + <number>0</number> + </property> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="ok"> + <property name="text"> + <string>OK</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cancel"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |