mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Create Add Weightsystem dialog
My first attempt to create a Qt dialog and to hook it up with the program. Unsurprisingly this doesn't quite work as expected (i.e., the values I enter aren't populated in the model), but it's a start... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
482bea84c2
commit
f45618f0c7
5 changed files with 190 additions and 3 deletions
2
Makefile
2
Makefile
|
@ -31,6 +31,7 @@ EXTRA_FLAGS = $(QTCXXFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \
|
||||||
|
|
||||||
HEADERS = \
|
HEADERS = \
|
||||||
qt-ui/addcylinderdialog.h \
|
qt-ui/addcylinderdialog.h \
|
||||||
|
qt-ui/addweightsystemdialog.h \
|
||||||
qt-ui/divelistview.h \
|
qt-ui/divelistview.h \
|
||||||
qt-ui/maintab.h \
|
qt-ui/maintab.h \
|
||||||
qt-ui/mainwindow.h \
|
qt-ui/mainwindow.h \
|
||||||
|
@ -70,6 +71,7 @@ SOURCES = \
|
||||||
webservice.c \
|
webservice.c \
|
||||||
qt-gui.cpp \
|
qt-gui.cpp \
|
||||||
qt-ui/addcylinderdialog.cpp \
|
qt-ui/addcylinderdialog.cpp \
|
||||||
|
qt-ui/addweightsystemdialog.cpp \
|
||||||
qt-ui/divelistview.cpp \
|
qt-ui/divelistview.cpp \
|
||||||
qt-ui/maintab.cpp \
|
qt-ui/maintab.cpp \
|
||||||
qt-ui/mainwindow.cpp \
|
qt-ui/mainwindow.cpp \
|
||||||
|
|
38
qt-ui/addweightsystemdialog.cpp
Normal file
38
qt-ui/addweightsystemdialog.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* addweightsystemdialog.cpp
|
||||||
|
*
|
||||||
|
* classes for the add weightsystem dialog of Subsurface
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "addweightsystemdialog.h"
|
||||||
|
#include "ui_addweightsystemdialog.h"
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QDoubleSpinBox>
|
||||||
|
#include "../conversions.h"
|
||||||
|
#include "models.h"
|
||||||
|
|
||||||
|
AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog())
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddWeightsystemDialog::setWeightsystem(weightsystem_t *ws)
|
||||||
|
{
|
||||||
|
currentWeightsystem = ws;
|
||||||
|
|
||||||
|
ui->description->insert(QString(ws->description));
|
||||||
|
if (get_units()->weight == units::KG)
|
||||||
|
ui->weight->setValue(ws->weight.grams / 1000);
|
||||||
|
else
|
||||||
|
ui->weight->setValue(grams_to_lbs(ws->weight.grams));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddWeightsystemDialog::updateWeightsystem()
|
||||||
|
{
|
||||||
|
currentWeightsystem->description = strdup(ui->description->text().toUtf8().data());
|
||||||
|
if (get_units()->weight == units::KG)
|
||||||
|
currentWeightsystem->weight.grams = ui->weight->value() * 1000;
|
||||||
|
else
|
||||||
|
currentWeightsystem->weight.grams = lbs_to_grams(ui->weight->value());
|
||||||
|
}
|
||||||
|
|
30
qt-ui/addweightsystemdialog.h
Normal file
30
qt-ui/addweightsystemdialog.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* addweightsystemdialog.h
|
||||||
|
*
|
||||||
|
* header file for the add weightsystem dialog of Subsurface
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef ADDWEIGHTSYSTEMDIALOG_H
|
||||||
|
#define ADDWEIGHTSYSTEMDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include "../dive.h"
|
||||||
|
|
||||||
|
namespace Ui{
|
||||||
|
class AddWeightsystemDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddWeightsystemDialog : public QDialog{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AddWeightsystemDialog(QWidget* parent = 0);
|
||||||
|
void setWeightsystem(weightsystem_t *ws);
|
||||||
|
void updateWeightsystem();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::AddWeightsystemDialog *ui;
|
||||||
|
weightsystem_t *currentWeightsystem;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
109
qt-ui/addweightsystemdialog.ui
Normal file
109
qt-ui/addweightsystemdialog.ui
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AddWeightsystemDialog</class>
|
||||||
|
<widget class="QDialog" name="AddWeightsystemDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>408</width>
|
||||||
|
<height>186</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0" rowspan="2">
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Weightsystem</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<property name="fieldGrowthPolicy">
|
||||||
|
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||||
|
</property>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Description</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Weight</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QSpinBox" name="weight">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="inputMethodHints">
|
||||||
|
<set>Qt::ImhFormattedNumbersOnly</set>
|
||||||
|
</property>
|
||||||
|
<property name="accelerated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="description"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>AddWeightsystemDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>269</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>AddWeightsystemDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>290</x>
|
||||||
|
<y>269</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -7,6 +7,7 @@
|
||||||
#include "maintab.h"
|
#include "maintab.h"
|
||||||
#include "ui_maintab.h"
|
#include "ui_maintab.h"
|
||||||
#include "addcylinderdialog.h"
|
#include "addcylinderdialog.h"
|
||||||
|
#include "addweightsystemdialog.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
|
@ -91,10 +92,17 @@ void MainTab::on_addWeight_clicked()
|
||||||
if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS)
|
if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* this needs a dialog - right now we just fill in a dummy */
|
AddWeightsystemDialog dialog(this);
|
||||||
weightsystem_t *newWeightsystem = (weightsystem_t *) malloc(sizeof(weightsystem_t));
|
weightsystem_t *newWeightsystem = (weightsystem_t *) malloc(sizeof(weightsystem_t));
|
||||||
newWeightsystem->description = "Just testing";
|
newWeightsystem->description = "";
|
||||||
newWeightsystem->weight.grams = 15000;
|
newWeightsystem->weight.grams = 0;
|
||||||
|
|
||||||
|
dialog.setWeightsystem(newWeightsystem);
|
||||||
|
int result = dialog.exec();
|
||||||
|
if (result == QDialog::Rejected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dialog.updateWeightsystem();
|
||||||
weightModel->add(newWeightsystem);
|
weightModel->add(newWeightsystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue