summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-05-29 13:59:16 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-29 14:13:32 -0700
commit33918e686765ac97da006c751c8919ef59cfa65a (patch)
tree2066dda5dbf86a8dff8989be3ca52e0db941e71c
parent60dc9f4ab36acf83ed599a7909ca164af3c9c227 (diff)
downloadsubsurface-33918e686765ac97da006c751c8919ef59cfa65a.tar.gz
Move ProfilePrintModel to qt-models
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--CMakeLists.txt1
-rw-r--r--qt-models/models.cpp177
-rw-r--r--qt-models/models.h20
-rw-r--r--qt-models/profileprintmodel.cpp156
-rw-r--r--qt-models/profileprintmodel.h26
-rw-r--r--qt-ui/printlayout.cpp1
6 files changed, 184 insertions, 197 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b9a0277e..cfa156d17 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -262,6 +262,7 @@ set(SUBSURFACE_MODELS_LIB_SRCS
qt-models/divetripmodel.cpp
qt-models/divecomputerextradatamodel.cpp
qt-models/completionmodels.cpp
+ qt-models/profileprintmodel.cpp
)
source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS})
diff --git a/qt-models/models.cpp b/qt-models/models.cpp
index bca8032eb..5fa45c4f0 100644
--- a/qt-models/models.cpp
+++ b/qt-models/models.cpp
@@ -38,183 +38,6 @@ const QPixmap &trashIcon()
return trash;
}
-/*################################################################
- *
- * Implementation of the Dive List.
- *
- * ############################################################### */
-
-
-/*#################################################################
- * #
- * # Yearly Statistics Model
- * #
- * ################################################################
- */
-
-/*#################################################################
- * #
- * # Table Print Model
- * #
- * ################################################################
- */
-/*#################################################################
- * #
- * # Profile Print Model
- * #
- * ################################################################
- */
-
-ProfilePrintModel::ProfilePrintModel(QObject *parent)
-{
-}
-
-void ProfilePrintModel::setDive(struct dive *divePtr)
-{
- diveId = divePtr->id;
- // reset();
-}
-
-void ProfilePrintModel::setFontsize(double size)
-{
- fontSize = size;
-}
-
-int ProfilePrintModel::rowCount(const QModelIndex &parent) const
-{
- return 12;
-}
-
-int ProfilePrintModel::columnCount(const QModelIndex &parent) const
-{
- return 5;
-}
-
-QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
-{
- const int row = index.row();
- const int col = index.column();
-
- switch (role) {
- case Qt::DisplayRole: {
- struct dive *dive = get_dive_by_uniq_id(diveId);
- struct DiveItem di;
- di.diveId = diveId;
-
- const QString unknown = tr("unknown");
-
- // dive# + date, depth, location, duration
- if (row == 0) {
- if (col == 0)
- return tr("Dive #%1 - %2").arg(dive->number).arg(di.displayDate());
- if (col == 3) {
- QString unit = (get_units()->length == units::METERS) ? "m" : "ft";
- return tr("Max depth: %1 %2").arg(di.displayDepth()).arg(unit);
- }
- }
- if (row == 1) {
- if (col == 0)
- return QString(get_dive_location(dive));
- if (col == 3)
- return QString(tr("Duration: %1 min")).arg(di.displayDuration());
- }
- // headings
- if (row == 2) {
- if (col == 0)
- return tr("Gas used:");
- if (col == 2)
- return tr("Tags:");
- if (col == 3)
- return tr("SAC:");
- if (col == 4)
- return tr("Weights:");
- }
- // notes
- if (col == 0) {
- if (row == 6)
- return tr("Notes:");
- if (row == 7)
- return QString(dive->notes);
- }
- // more headings
- if (row == 4) {
- if (col == 0)
- return tr("Divemaster:");
- if (col == 1)
- return tr("Buddy:");
- if (col == 2)
- return tr("Suit:");
- if (col == 3)
- return tr("Viz:");
- if (col == 4)
- return tr("Rating:");
- }
- // values for gas, sac, etc...
- if (row == 3) {
- if (col == 0) {
- int added = 0;
- QString gas, gases;
- for (int i = 0; i < MAX_CYLINDERS; i++) {
- if (!is_cylinder_used(dive, i))
- continue;
- gas = dive->cylinder[i].type.description;
- gas += QString(!gas.isEmpty() ? " " : "") + gasname(&dive->cylinder[i].gasmix);
- // if has a description and if such gas is not already present
- if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
- if (added > 0)
- gases += QString(" / ");
- gases += gas;
- added++;
- }
- }
- return gases;
- }
- if (col == 2) {
- char buffer[256];
- taglist_get_tagstring(dive->tag_list, buffer, 256);
- return QString(buffer);
- }
- if (col == 3)
- return di.displaySac();
- if (col == 4) {
- weight_t tw = { total_weight(dive) };
- return get_weight_string(tw, true);
- }
- }
- // values for DM, buddy, suit, etc...
- if (row == 5) {
- if (col == 0)
- return QString(dive->divemaster);
- if (col == 1)
- return QString(dive->buddy);
- if (col == 2)
- return QString(dive->suit);
- if (col == 3)
- return (dive->visibility) ? QString::number(dive->visibility).append(" / 5") : QString();
- if (col == 4)
- return (dive->rating) ? QString::number(dive->rating).append(" / 5") : QString();
- }
- return QString();
- }
- case Qt::FontRole: {
- QFont font;
- font.setPointSizeF(fontSize);
- if (row == 0 && col == 0) {
- font.setBold(true);
- }
- return QVariant::fromValue(font);
- }
- case Qt::TextAlignmentRole: {
- // everything is aligned to the left
- unsigned int align = Qt::AlignLeft;
- // align depth and duration right
- if (row < 2 && col == 4)
- align = Qt::AlignRight | Qt::AlignVCenter;
- return QVariant::fromValue(align);
- }
- } // switch (role)
- return QVariant();
-}
Qt::ItemFlags GasSelectionModel::flags(const QModelIndex &index) const
{
diff --git a/qt-models/models.h b/qt-models/models.h
index 94fcc5129..df5906a18 100644
--- a/qt-models/models.h
+++ b/qt-models/models.h
@@ -22,26 +22,6 @@
#include "cleanertablemodel.h"
#include "treemodel.h"
-/* ProfilePrintModel:
- * this model is used when printing a data table under a profile. it requires
- * some exact usage of setSpan(..) on the target QTableView widget.
- */
-class ProfilePrintModel : public QAbstractTableModel {
- Q_OBJECT
-
-private:
- int diveId;
- double fontSize;
-
-public:
- ProfilePrintModel(QObject *parent = 0);
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- void setDive(struct dive *divePtr);
- void setFontsize(double size);
-};
-
class GasSelectionModel : public QStringListModel {
Q_OBJECT
public:
diff --git a/qt-models/profileprintmodel.cpp b/qt-models/profileprintmodel.cpp
new file mode 100644
index 000000000..1f8d918ed
--- /dev/null
+++ b/qt-models/profileprintmodel.cpp
@@ -0,0 +1,156 @@
+#include "profileprintmodel.h"
+#include "metrics.h"
+#include "dive.h"
+#include "divetripmodel.h"
+#include "helpers.h"
+
+ProfilePrintModel::ProfilePrintModel(QObject *parent)
+{
+}
+
+void ProfilePrintModel::setDive(struct dive *divePtr)
+{
+ diveId = divePtr->id;
+ // reset();
+}
+
+void ProfilePrintModel::setFontsize(double size)
+{
+ fontSize = size;
+}
+
+int ProfilePrintModel::rowCount(const QModelIndex &parent) const
+{
+ return 12;
+}
+
+int ProfilePrintModel::columnCount(const QModelIndex &parent) const
+{
+ return 5;
+}
+
+QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
+{
+ const int row = index.row();
+ const int col = index.column();
+
+ switch (role) {
+ case Qt::DisplayRole: {
+ struct dive *dive = get_dive_by_uniq_id(diveId);
+ struct DiveItem di;
+ di.diveId = diveId;
+
+ const QString unknown = tr("unknown");
+
+ // dive# + date, depth, location, duration
+ if (row == 0) {
+ if (col == 0)
+ return tr("Dive #%1 - %2").arg(dive->number).arg(di.displayDate());
+ if (col == 3) {
+ QString unit = (get_units()->length == units::METERS) ? "m" : "ft";
+ return tr("Max depth: %1 %2").arg(di.displayDepth()).arg(unit);
+ }
+ }
+ if (row == 1) {
+ if (col == 0)
+ return QString(get_dive_location(dive));
+ if (col == 3)
+ return QString(tr("Duration: %1 min")).arg(di.displayDuration());
+ }
+ // headings
+ if (row == 2) {
+ if (col == 0)
+ return tr("Gas used:");
+ if (col == 2)
+ return tr("Tags:");
+ if (col == 3)
+ return tr("SAC:");
+ if (col == 4)
+ return tr("Weights:");
+ }
+ // notes
+ if (col == 0) {
+ if (row == 6)
+ return tr("Notes:");
+ if (row == 7)
+ return QString(dive->notes);
+ }
+ // more headings
+ if (row == 4) {
+ if (col == 0)
+ return tr("Divemaster:");
+ if (col == 1)
+ return tr("Buddy:");
+ if (col == 2)
+ return tr("Suit:");
+ if (col == 3)
+ return tr("Viz:");
+ if (col == 4)
+ return tr("Rating:");
+ }
+ // values for gas, sac, etc...
+ if (row == 3) {
+ if (col == 0) {
+ int added = 0;
+ QString gas, gases;
+ for (int i = 0; i < MAX_CYLINDERS; i++) {
+ if (!is_cylinder_used(dive, i))
+ continue;
+ gas = dive->cylinder[i].type.description;
+ gas += QString(!gas.isEmpty() ? " " : "") + gasname(&dive->cylinder[i].gasmix);
+ // if has a description and if such gas is not already present
+ if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
+ if (added > 0)
+ gases += QString(" / ");
+ gases += gas;
+ added++;
+ }
+ }
+ return gases;
+ }
+ if (col == 2) {
+ char buffer[256];
+ taglist_get_tagstring(dive->tag_list, buffer, 256);
+ return QString(buffer);
+ }
+ if (col == 3)
+ return di.displaySac();
+ if (col == 4) {
+ weight_t tw = { total_weight(dive) };
+ return get_weight_string(tw, true);
+ }
+ }
+ // values for DM, buddy, suit, etc...
+ if (row == 5) {
+ if (col == 0)
+ return QString(dive->divemaster);
+ if (col == 1)
+ return QString(dive->buddy);
+ if (col == 2)
+ return QString(dive->suit);
+ if (col == 3)
+ return (dive->visibility) ? QString::number(dive->visibility).append(" / 5") : QString();
+ if (col == 4)
+ return (dive->rating) ? QString::number(dive->rating).append(" / 5") : QString();
+ }
+ return QString();
+ }
+ case Qt::FontRole: {
+ QFont font;
+ font.setPointSizeF(fontSize);
+ if (row == 0 && col == 0) {
+ font.setBold(true);
+ }
+ return QVariant::fromValue(font);
+ }
+ case Qt::TextAlignmentRole: {
+ // everything is aligned to the left
+ unsigned int align = Qt::AlignLeft;
+ // align depth and duration right
+ if (row < 2 && col == 4)
+ align = Qt::AlignRight | Qt::AlignVCenter;
+ return QVariant::fromValue(align);
+ }
+ } // switch (role)
+ return QVariant();
+}
diff --git a/qt-models/profileprintmodel.h b/qt-models/profileprintmodel.h
new file mode 100644
index 000000000..b15f2df61
--- /dev/null
+++ b/qt-models/profileprintmodel.h
@@ -0,0 +1,26 @@
+#ifndef PROFILEPRINTMODEL_H
+#define PROFILEPRINTMODEL_H
+
+#include <QAbstractTableModel>
+
+/* ProfilePrintModel:
+ * this model is used when printing a data table under a profile. it requires
+ * some exact usage of setSpan(..) on the target QTableView widget.
+ */
+class ProfilePrintModel : public QAbstractTableModel {
+ Q_OBJECT
+
+private:
+ int diveId;
+ double fontSize;
+
+public:
+ ProfilePrintModel(QObject *parent = 0);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ void setDive(struct dive *divePtr);
+ void setFontsize(double size);
+};
+
+#endif \ No newline at end of file
diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp
index 487f87e86..87f5f7c30 100644
--- a/qt-ui/printlayout.cpp
+++ b/qt-ui/printlayout.cpp
@@ -13,6 +13,7 @@
#include "profile/profilewidget2.h"
#include "divetripmodel.h"
#include "tableprintmodel.h"
+#include "profileprintmodel.h"
PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct print_options *optionsPtr)
{