mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Move Locationinformation to its own file.
The SimpleWidgets file was getting too big, and location information will also need a new model - a good way to do not mix everything is to put things in a new file. [Dirk Hohndel: added missing include of stdint.h] Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
d9ad829173
commit
5eb572b9c6
7 changed files with 227 additions and 212 deletions
|
@ -272,6 +272,7 @@ set(SUBSURFACE_INTERFACE
|
|||
qt-ui/configuredivecomputerdialog.cpp
|
||||
qt-ui/filtermodels.cpp
|
||||
qt-ui/undocommands.cpp
|
||||
qt-ui/locationinformation.cpp
|
||||
${SOCIALNETWORKS}
|
||||
)
|
||||
|
||||
|
|
185
qt-ui/locationinformation.cpp
Normal file
185
qt-ui/locationinformation.cpp
Normal file
|
@ -0,0 +1,185 @@
|
|||
#include "locationinformation.h"
|
||||
#include "dive.h"
|
||||
#include "mainwindow.h"
|
||||
#include "divelistview.h"
|
||||
#include "qthelper.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QShowEvent>
|
||||
|
||||
LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), modified(false)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
ui.diveSiteMessage->show();
|
||||
|
||||
// create the three buttons and only show the close button for now
|
||||
closeAction = new QAction(tr("Close"), this);
|
||||
connect(closeAction, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
|
||||
|
||||
acceptAction = new QAction(tr("Apply changes"), this);
|
||||
connect(acceptAction, SIGNAL(triggered(bool)), this, SLOT(acceptChanges()));
|
||||
|
||||
rejectAction = new QAction(tr("Discard changes"), this);
|
||||
connect(rejectAction, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
|
||||
|
||||
ui.diveSiteMessage->setText(tr("Dive site management"));
|
||||
ui.diveSiteMessage->addAction(closeAction);
|
||||
|
||||
}
|
||||
|
||||
void LocationInformationWidget::setLocationId(uint32_t uuid)
|
||||
{
|
||||
currentDs = get_dive_site_by_uuid(uuid);
|
||||
|
||||
if (!currentDs) {
|
||||
currentDs = get_dive_site_by_uuid(create_dive_site(""));
|
||||
displayed_dive.dive_site_uuid = currentDs->uuid;
|
||||
ui.diveSiteName->clear();
|
||||
ui.diveSiteDescription->clear();
|
||||
ui.diveSiteNotes->clear();
|
||||
ui.diveSiteCoordinates->clear();
|
||||
}
|
||||
displayed_dive_site = *currentDs;
|
||||
if (displayed_dive_site.name)
|
||||
ui.diveSiteName->setText(displayed_dive_site.name);
|
||||
else
|
||||
ui.diveSiteName->clear();
|
||||
if (displayed_dive_site.description)
|
||||
ui.diveSiteDescription->setText(displayed_dive_site.description);
|
||||
else
|
||||
ui.diveSiteDescription->clear();
|
||||
if (displayed_dive_site.notes)
|
||||
ui.diveSiteNotes->setPlainText(displayed_dive_site.notes);
|
||||
else
|
||||
ui.diveSiteNotes->clear();
|
||||
if (displayed_dive_site.latitude.udeg || displayed_dive_site.longitude.udeg)
|
||||
ui.diveSiteCoordinates->setText(printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg));
|
||||
else
|
||||
ui.diveSiteCoordinates->clear();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::updateGpsCoordinates()
|
||||
{
|
||||
ui.diveSiteCoordinates->setText(printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg));
|
||||
MainWindow::instance()->setApplicationState("EditDiveSite");
|
||||
}
|
||||
|
||||
void LocationInformationWidget::acceptChanges()
|
||||
{
|
||||
char *uiString;
|
||||
currentDs->latitude = displayed_dive_site.latitude;
|
||||
currentDs->longitude = displayed_dive_site.longitude;
|
||||
uiString = ui.diveSiteName->text().toUtf8().data();
|
||||
if (!same_string(uiString, currentDs->name)) {
|
||||
free(currentDs->name);
|
||||
currentDs->name = copy_string(uiString);
|
||||
}
|
||||
uiString = ui.diveSiteDescription->text().toUtf8().data();
|
||||
if (!same_string(uiString, currentDs->description)) {
|
||||
free(currentDs->description);
|
||||
currentDs->description = copy_string(uiString);
|
||||
}
|
||||
uiString = ui.diveSiteNotes->document()->toPlainText().toUtf8().data();
|
||||
if (!same_string(uiString, currentDs->notes)) {
|
||||
free(currentDs->notes);
|
||||
currentDs->notes = copy_string(uiString);
|
||||
}
|
||||
if (dive_site_is_empty(currentDs)) {
|
||||
delete_dive_site(currentDs->uuid);
|
||||
displayed_dive.dive_site_uuid = 0;
|
||||
setLocationId(0);
|
||||
} else {
|
||||
setLocationId(currentDs->uuid);
|
||||
}
|
||||
mark_divelist_changed(true);
|
||||
resetState();
|
||||
emit informationManagementEnded();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::rejectChanges()
|
||||
{
|
||||
Q_ASSERT(currentDs != NULL);
|
||||
if (dive_site_is_empty(currentDs)) {
|
||||
delete_dive_site(currentDs->uuid);
|
||||
displayed_dive.dive_site_uuid = 0;
|
||||
setLocationId(0);
|
||||
} else {
|
||||
setLocationId(currentDs->uuid);
|
||||
}
|
||||
resetState();
|
||||
emit informationManagementEnded();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::showEvent(QShowEvent *ev) {
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::markChangedWidget(QWidget *w)
|
||||
{
|
||||
QPalette p;
|
||||
qreal h, s, l, a;
|
||||
if (!modified)
|
||||
enableEdition();
|
||||
qApp->palette().color(QPalette::Text).getHslF(&h, &s, &l, &a);
|
||||
p.setBrush(QPalette::Base, (l <= 0.3) ? QColor(Qt::yellow).lighter() : (l <= 0.6) ? QColor(Qt::yellow).light() : /* else */ QColor(Qt::yellow).darker(300));
|
||||
w->setPalette(p);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
void LocationInformationWidget::resetState()
|
||||
{
|
||||
modified = false;
|
||||
resetPallete();
|
||||
MainWindow::instance()->dive_list()->setEnabled(true);
|
||||
MainWindow::instance()->setEnabledToolbar(true);
|
||||
ui.diveSiteMessage->setText(tr("Dive site management"));
|
||||
ui.diveSiteMessage->addAction(closeAction);
|
||||
ui.diveSiteMessage->removeAction(acceptAction);
|
||||
ui.diveSiteMessage->removeAction(rejectAction);
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::enableEdition()
|
||||
{
|
||||
MainWindow::instance()->dive_list()->setEnabled(false);
|
||||
MainWindow::instance()->setEnabledToolbar(false);
|
||||
ui.diveSiteMessage->setText(tr("You are editing a dive site"));
|
||||
ui.diveSiteMessage->removeAction(closeAction);
|
||||
ui.diveSiteMessage->addAction(acceptAction);
|
||||
ui.diveSiteMessage->addAction(rejectAction);
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString& text)
|
||||
{
|
||||
if (!same_string(qPrintable(text), printGPSCoords(currentDs->latitude.udeg, currentDs->longitude.udeg)))
|
||||
markChangedWidget(ui.diveSiteCoordinates);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteDescription_textChanged(const QString& text)
|
||||
{
|
||||
if (!same_string(qPrintable(text), currentDs->description))
|
||||
markChangedWidget(ui.diveSiteDescription);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteName_textChanged(const QString& text)
|
||||
{
|
||||
if (!same_string(qPrintable(text), currentDs->name))
|
||||
markChangedWidget(ui.diveSiteName);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteNotes_textChanged()
|
||||
{
|
||||
if (!same_string(qPrintable(ui.diveSiteNotes->toPlainText()), currentDs->notes))
|
||||
markChangedWidget(ui.diveSiteNotes);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::resetPallete()
|
||||
{
|
||||
QPalette p;
|
||||
ui.diveSiteCoordinates->setPalette(p);
|
||||
ui.diveSiteDescription->setPalette(p);
|
||||
ui.diveSiteName->setPalette(p);
|
||||
ui.diveSiteNotes->setPalette(p);
|
||||
}
|
39
qt-ui/locationinformation.h
Normal file
39
qt-ui/locationinformation.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef LOCATIONINFORMATION_H
|
||||
#define LOCATIONINFORMATION_H
|
||||
|
||||
#include "ui_locationInformation.h"
|
||||
#include <stdint.h>
|
||||
|
||||
class LocationInformationWidget : public QGroupBox {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocationInformationWidget(QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void acceptChanges();
|
||||
void rejectChanges();
|
||||
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
void setLocationId(uint32_t uuid);
|
||||
void updateGpsCoordinates(void);
|
||||
void markChangedWidget(QWidget *w);
|
||||
void enableEdition();
|
||||
void resetState();
|
||||
void resetPallete();
|
||||
|
||||
void on_diveSiteCoordinates_textChanged(const QString& text);
|
||||
void on_diveSiteDescription_textChanged(const QString& text);
|
||||
void on_diveSiteName_textChanged(const QString& text);
|
||||
void on_diveSiteNotes_textChanged();
|
||||
signals:
|
||||
void informationManagementEnded();
|
||||
|
||||
private:
|
||||
struct dive_site *currentDs;
|
||||
Ui::LocationInformation ui;
|
||||
bool modified;
|
||||
QAction *closeAction, *acceptAction, *rejectAction;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -33,6 +33,7 @@
|
|||
#include "divelogexportdialog.h"
|
||||
#include "usersurvey.h"
|
||||
#include "divesitehelpers.h"
|
||||
#include "locationinformation.h"
|
||||
#ifndef NO_USERMANUAL
|
||||
#include "usermanual.h"
|
||||
#endif
|
||||
|
|
|
@ -37,6 +37,7 @@ class ProfileWidget2;
|
|||
class PlannerDetails;
|
||||
class PlannerSettingsWidget;
|
||||
class QUndoStack;
|
||||
class LocationInformationWidget;
|
||||
|
||||
enum MainWindowTitleFormat {
|
||||
MWTF_DEFAULT,
|
||||
|
|
|
@ -706,181 +706,3 @@ void MultiFilter::closeFilter()
|
|||
MultiFilterSortModel::instance()->clearFilter();
|
||||
hide();
|
||||
}
|
||||
#include <QDebug>
|
||||
#include <QShowEvent>
|
||||
|
||||
LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), modified(false)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
ui.diveSiteMessage->show();
|
||||
|
||||
// create the three buttons and only show the close button for now
|
||||
closeAction = new QAction(tr("Close"), this);
|
||||
connect(closeAction, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
|
||||
|
||||
acceptAction = new QAction(tr("Apply changes"), this);
|
||||
connect(acceptAction, SIGNAL(triggered(bool)), this, SLOT(acceptChanges()));
|
||||
|
||||
rejectAction = new QAction(tr("Discard changes"), this);
|
||||
connect(rejectAction, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
|
||||
|
||||
ui.diveSiteMessage->setText(tr("Dive site management"));
|
||||
ui.diveSiteMessage->addAction(closeAction);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::setLocationId(uint32_t uuid)
|
||||
{
|
||||
currentDs = get_dive_site_by_uuid(uuid);
|
||||
|
||||
if (!currentDs) {
|
||||
currentDs = get_dive_site_by_uuid(create_dive_site(""));
|
||||
displayed_dive.dive_site_uuid = currentDs->uuid;
|
||||
ui.diveSiteName->clear();
|
||||
ui.diveSiteDescription->clear();
|
||||
ui.diveSiteNotes->clear();
|
||||
ui.diveSiteCoordinates->clear();
|
||||
}
|
||||
displayed_dive_site = *currentDs;
|
||||
if (displayed_dive_site.name)
|
||||
ui.diveSiteName->setText(displayed_dive_site.name);
|
||||
else
|
||||
ui.diveSiteName->clear();
|
||||
if (displayed_dive_site.description)
|
||||
ui.diveSiteDescription->setText(displayed_dive_site.description);
|
||||
else
|
||||
ui.diveSiteDescription->clear();
|
||||
if (displayed_dive_site.notes)
|
||||
ui.diveSiteNotes->setPlainText(displayed_dive_site.notes);
|
||||
else
|
||||
ui.diveSiteNotes->clear();
|
||||
if (displayed_dive_site.latitude.udeg || displayed_dive_site.longitude.udeg)
|
||||
ui.diveSiteCoordinates->setText(printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg));
|
||||
else
|
||||
ui.diveSiteCoordinates->clear();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::updateGpsCoordinates()
|
||||
{
|
||||
ui.diveSiteCoordinates->setText(printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg));
|
||||
MainWindow::instance()->setApplicationState("EditDiveSite");
|
||||
}
|
||||
|
||||
void LocationInformationWidget::acceptChanges()
|
||||
{
|
||||
char *uiString;
|
||||
currentDs->latitude = displayed_dive_site.latitude;
|
||||
currentDs->longitude = displayed_dive_site.longitude;
|
||||
uiString = ui.diveSiteName->text().toUtf8().data();
|
||||
if (!same_string(uiString, currentDs->name)) {
|
||||
free(currentDs->name);
|
||||
currentDs->name = copy_string(uiString);
|
||||
}
|
||||
uiString = ui.diveSiteDescription->text().toUtf8().data();
|
||||
if (!same_string(uiString, currentDs->description)) {
|
||||
free(currentDs->description);
|
||||
currentDs->description = copy_string(uiString);
|
||||
}
|
||||
uiString = ui.diveSiteNotes->document()->toPlainText().toUtf8().data();
|
||||
if (!same_string(uiString, currentDs->notes)) {
|
||||
free(currentDs->notes);
|
||||
currentDs->notes = copy_string(uiString);
|
||||
}
|
||||
if (dive_site_is_empty(currentDs)) {
|
||||
delete_dive_site(currentDs->uuid);
|
||||
displayed_dive.dive_site_uuid = 0;
|
||||
setLocationId(0);
|
||||
} else {
|
||||
setLocationId(currentDs->uuid);
|
||||
}
|
||||
mark_divelist_changed(true);
|
||||
resetState();
|
||||
emit informationManagementEnded();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::rejectChanges()
|
||||
{
|
||||
Q_ASSERT(currentDs != NULL);
|
||||
if (dive_site_is_empty(currentDs)) {
|
||||
delete_dive_site(currentDs->uuid);
|
||||
displayed_dive.dive_site_uuid = 0;
|
||||
setLocationId(0);
|
||||
} else {
|
||||
setLocationId(currentDs->uuid);
|
||||
}
|
||||
resetState();
|
||||
emit informationManagementEnded();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::showEvent(QShowEvent *ev) {
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::markChangedWidget(QWidget *w)
|
||||
{
|
||||
QPalette p;
|
||||
qreal h, s, l, a;
|
||||
if (!modified)
|
||||
enableEdition();
|
||||
qApp->palette().color(QPalette::Text).getHslF(&h, &s, &l, &a);
|
||||
p.setBrush(QPalette::Base, (l <= 0.3) ? QColor(Qt::yellow).lighter() : (l <= 0.6) ? QColor(Qt::yellow).light() : /* else */ QColor(Qt::yellow).darker(300));
|
||||
w->setPalette(p);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
void LocationInformationWidget::resetState()
|
||||
{
|
||||
modified = false;
|
||||
resetPallete();
|
||||
MainWindow::instance()->dive_list()->setEnabled(true);
|
||||
MainWindow::instance()->setEnabledToolbar(true);
|
||||
ui.diveSiteMessage->setText(tr("Dive site management"));
|
||||
ui.diveSiteMessage->addAction(closeAction);
|
||||
ui.diveSiteMessage->removeAction(acceptAction);
|
||||
ui.diveSiteMessage->removeAction(rejectAction);
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::enableEdition()
|
||||
{
|
||||
MainWindow::instance()->dive_list()->setEnabled(false);
|
||||
MainWindow::instance()->setEnabledToolbar(false);
|
||||
ui.diveSiteMessage->setText(tr("You are editing a dive site"));
|
||||
ui.diveSiteMessage->removeAction(closeAction);
|
||||
ui.diveSiteMessage->addAction(acceptAction);
|
||||
ui.diveSiteMessage->addAction(rejectAction);
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString& text)
|
||||
{
|
||||
if (!same_string(qPrintable(text), printGPSCoords(currentDs->latitude.udeg, currentDs->longitude.udeg)))
|
||||
markChangedWidget(ui.diveSiteCoordinates);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteDescription_textChanged(const QString& text)
|
||||
{
|
||||
if (!same_string(qPrintable(text), currentDs->description))
|
||||
markChangedWidget(ui.diveSiteDescription);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteName_textChanged(const QString& text)
|
||||
{
|
||||
if (!same_string(qPrintable(text), currentDs->name))
|
||||
markChangedWidget(ui.diveSiteName);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::on_diveSiteNotes_textChanged()
|
||||
{
|
||||
if (!same_string(qPrintable(ui.diveSiteNotes->toPlainText()), currentDs->notes))
|
||||
markChangedWidget(ui.diveSiteNotes);
|
||||
}
|
||||
|
||||
void LocationInformationWidget::resetPallete()
|
||||
{
|
||||
QPalette p;
|
||||
ui.diveSiteCoordinates->setPalette(p);
|
||||
ui.diveSiteDescription->setPalette(p);
|
||||
ui.diveSiteName->setPalette(p);
|
||||
ui.diveSiteNotes->setPalette(p);
|
||||
}
|
||||
|
|
|
@ -228,40 +228,6 @@ private:
|
|||
Ui::FilterWidget ui;
|
||||
};
|
||||
|
||||
#include "ui_locationInformation.h"
|
||||
|
||||
class LocationInformationWidget : public QGroupBox {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocationInformationWidget(QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void acceptChanges();
|
||||
void rejectChanges();
|
||||
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
void setLocationId(uint32_t uuid);
|
||||
void updateGpsCoordinates(void);
|
||||
void markChangedWidget(QWidget *w);
|
||||
void enableEdition();
|
||||
void resetState();
|
||||
void resetPallete();
|
||||
|
||||
void on_diveSiteCoordinates_textChanged(const QString& text);
|
||||
void on_diveSiteDescription_textChanged(const QString& text);
|
||||
void on_diveSiteName_textChanged(const QString& text);
|
||||
void on_diveSiteNotes_textChanged();
|
||||
signals:
|
||||
void informationManagementEnded();
|
||||
|
||||
private:
|
||||
struct dive_site *currentDs;
|
||||
Ui::LocationInformation ui;
|
||||
bool modified;
|
||||
QAction *closeAction, *acceptAction, *rejectAction;
|
||||
};
|
||||
|
||||
bool isGnome3Session();
|
||||
QImage grayImage(const QImage &coloredImg);
|
||||
|
||||
|
|
Loading…
Reference in a new issue