qt-models: remove obsolete printer related classes

The profileprintmodel.cpp/.h and the
tableprintmode.cpp/.h pairs are obsolete.

The print layouting is now handled via the Grantlee library
and HTML.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2015-11-09 20:42:11 +02:00 committed by Dirk Hohndel
parent b8c71ef6cd
commit 36314a86f8
5 changed files with 1 additions and 358 deletions

View file

@ -11,12 +11,10 @@ set(SUBSURFACE_MODELS_LIB_SRCS
weightmodel.cpp
divecomputermodel.cpp
treemodel.cpp
tableprintmodel.cpp
yearlystatisticsmodel.cpp
divetripmodel.cpp
divecomputerextradatamodel.cpp
completionmodels.cpp
profileprintmodel.cpp
divepicturemodel.cpp
diveplotdatamodel.cpp
divelocationmodel.cpp
@ -26,4 +24,4 @@ set(SUBSURFACE_MODELS_LIB_SRCS
source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS})
add_library(subsurface_models STATIC ${SUBSURFACE_MODELS_LIB_SRCS})
target_link_libraries(subsurface_models ${QT_LIBRARIES})
target_link_libraries(subsurface_models ${QT_LIBRARIES})

View file

@ -1,157 +0,0 @@
#include "profileprintmodel.h"
#include "metrics.h"
#include "dive.h"
#include "divetripmodel.h"
#include "helpers.h"
ProfilePrintModel::ProfilePrintModel(QObject *parent)
{
fontSize = 12.0;
}
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();
}

View file

@ -1,26 +0,0 @@
#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

View file

@ -1,127 +0,0 @@
#include "tableprintmodel.h"
#include "metrics.h"
#include "color.h"
TablePrintModel::TablePrintModel()
{
columns = 7;
rows = 0;
}
TablePrintModel::~TablePrintModel()
{
for (int i = 0; i < list.size(); i++)
delete list.at(i);
}
void TablePrintModel::insertRow(int index)
{
struct TablePrintItem *item = new struct TablePrintItem();
item->colorBackground = 0xffffffff;
if (index == -1) {
beginInsertRows(QModelIndex(), rows, rows);
list.append(item);
} else {
beginInsertRows(QModelIndex(), index, index);
list.insert(index, item);
}
endInsertRows();
rows++;
}
void TablePrintModel::callReset()
{
beginResetModel();
endResetModel();
}
QVariant TablePrintModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::BackgroundRole)
return QColor(list.at(index.row())->colorBackground);
if (role == Qt::DisplayRole)
switch (index.column()) {
case 0:
return list.at(index.row())->number;
case 1:
return list.at(index.row())->date;
case 2:
return list.at(index.row())->depth;
case 3:
return list.at(index.row())->duration;
case 4:
return list.at(index.row())->divemaster;
case 5:
return list.at(index.row())->buddy;
case 6:
return list.at(index.row())->location;
}
if (role == Qt::FontRole) {
QFont font;
font.setPointSizeF(7.5);
if (index.row() == 0 && index.column() == 0) {
font.setBold(true);
}
return QVariant::fromValue(font);
}
return QVariant();
}
bool TablePrintModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid()) {
if (role == Qt::DisplayRole) {
switch (index.column()) {
case 0:
list.at(index.row())->number = value.toString();
case 1:
list.at(index.row())->date = value.toString();
case 2:
list.at(index.row())->depth = value.toString();
case 3:
list.at(index.row())->duration = value.toString();
case 4:
list.at(index.row())->divemaster = value.toString();
case 5:
list.at(index.row())->buddy = value.toString();
case 6: {
/* truncate if there are more than N lines of text,
* we don't want a row to be larger that a single page! */
QString s = value.toString();
const int maxLines = 15;
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.at(i) != QChar('\n'))
continue;
count++;
if (count > maxLines) {
s = s.left(i - 1);
break;
}
}
list.at(index.row())->location = s;
}
}
return true;
}
if (role == Qt::BackgroundRole) {
list.at(index.row())->colorBackground = value.value<unsigned int>();
return true;
}
}
return false;
}
int TablePrintModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return rows;
}
int TablePrintModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return columns;
}

View file

@ -1,45 +0,0 @@
#ifndef TABLEPRINTMODEL_H
#define TABLEPRINTMODEL_H
#include <QAbstractTableModel>
/* TablePrintModel:
* for now we use a blank table model with row items TablePrintItem.
* these are pretty much the same as DiveItem, but have color
* properties, as well. perhaps later one a more unified model has to be
* considered, but the current TablePrintModel idea has to be extended
* to support variadic column lists and column list orders that can
* be controlled by the user.
*/
struct TablePrintItem {
QString number;
QString date;
QString depth;
QString duration;
QString divemaster;
QString buddy;
QString location;
unsigned int colorBackground;
};
class TablePrintModel : public QAbstractTableModel {
Q_OBJECT
private:
QList<TablePrintItem *> list;
public:
~TablePrintModel();
TablePrintModel();
int rows, columns;
void insertRow(int index = -1);
void callReset();
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
};
#endif