mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Create DivesiteImportDialog to select sites to import
Creates the dialog box to select which sites to import from the file selected in mainwindow.cpp. The DivesiteImportModel is created as a table to display and select which sites are to be imported. Once the sites are selected, the Command::importDiveSites command is called to add the sites to the core dive site table with undo/redo functions. Signed-off-by: Doug Junkins <junkins@foghead.com>
This commit is contained in:
parent
98b3a326bd
commit
00ec824129
7 changed files with 421 additions and 0 deletions
|
@ -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
|
||||
|
|
80
desktop-widgets/divesiteimportdialog.cpp
Normal file
80
desktop-widgets/divesiteimportdialog.cpp
Normal file
|
@ -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();
|
||||
}
|
40
desktop-widgets/divesiteimportdialog.h
Normal file
40
desktop-widgets/divesiteimportdialog.h
Normal file
|
@ -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
|
119
desktop-widgets/divesiteimportdialog.ui
Normal file
119
desktop-widgets/divesiteimportdialog.ui
Normal file
|
@ -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>
|
Loading…
Add table
Add a link
Reference in a new issue