Merge branch 'print' of github.com:neolit123/subsurface

This commit is contained in:
Dirk Hohndel 2013-11-30 07:55:58 -08:00
commit a268311a0b
3 changed files with 95 additions and 147 deletions

View file

@ -329,14 +329,15 @@ void ProfilePrintDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
// grid color
painter->setPen(QPen(QColor(0xff999999)));
// top line
if (row == 2 || row == 3 || row == 10 || col == 3 || col == 4)
// horizontal lines
if (row == 2 || row == 4 || row == 6)
painter->drawLine(rect.topLeft(), rect.topRight());
if (row > 1 && row < 10) {
// left line - draw always for these rows
if (row == 7)
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
// vertical lines
if (row > 1) {
painter->drawLine(rect.topLeft(), rect.bottomLeft());
// "fix" for missing (?) right line after col 5
if (col > 5 || (col > 4 && row == 2))
if (col == 4 || (col == 0 && row > 5))
painter->drawLine(rect.topRight(), rect.bottomRight());
}
QStyledItemDelegate::paint(painter, option, index);

View file

@ -1563,28 +1563,6 @@ ProfilePrintModel::ProfilePrintModel(QObject *parent)
{
}
/* this is just a helper function to truncate C strings near 'maxlen' characters
* by finding word bounderies and adding '...' at the end of the truncated string.
* not really optimal for all languages!
*/
QString ProfilePrintModel::truncateString(char *str, const int maxlen) const
{
if (!str)
return QString("");
QString trunc = QString(str);
const int len = trunc.length();
for (int i = 0; i < len; i++) {
char c = trunc.at(i).toAscii();
if (c == ' ' || c == '\n' || c == '\t') {
if (i > maxlen) {
trunc = trunc.left(i) + QString("...");
break;
}
}
}
return trunc;
}
void ProfilePrintModel::setDive(struct dive *divePtr)
{
dive = divePtr;
@ -1593,12 +1571,12 @@ void ProfilePrintModel::setDive(struct dive *divePtr)
int ProfilePrintModel::rowCount(const QModelIndex &parent) const
{
return 11;
return 12;
}
int ProfilePrintModel::columnCount(const QModelIndex &parent) const
{
return 7;
return 5;
}
QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
@ -1618,91 +1596,87 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
if (row == 0) {
if (col == 0)
return tr("Dive #%1 - %2").arg(dive->number).arg(di.displayDate());
if (col == 5) {
if (col == 4) {
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 truncateString(dive->location, 32);
if (col == 5)
return QString(dive->location);
if (col == 4)
return QString(tr("Duration: %1 min")).arg(di.displayDuration());
}
// cylinder headings
// headings
if (row == 2) {
if (col == 0)
return tr("Cylinder");
if (col == 1)
return tr("Gasmix");
return tr("Gas Used:");
if (col == 2)
return tr("Gas Used");
return tr("SAC:");
if (col == 3)
return tr("Max. CNS:");
if (col == 4)
return tr("Weights:");
}
// cylinder data
if (row > 2 && row < 10 && row - 3 < MAX_CYLINDERS) {
cylinder_t *cyl = &dive->cylinder[row - 3];
if (cyl->type.description) { // how do we check if a cylinder is added?
if (col == 0) {
if (cyl->type.description[0] != '\0')
return QString(cyl->type.description);
return unknown;
}
if (col == 1) {
get_gas_string(cyl->gasmix.o2.permille, cyl->gasmix.he.permille, buf, sizeof(buf));
return QString(buf);
}
if (col == 2) {
return get_cylinder_used_gas_string(cyl, true);
}
}
}
// dive notes
if (row == 10 && col == 0)
return truncateString(dive->notes, 640);
// sac, cns, otu - headings
if (col == 3) {
if (row == 2)
return tr("SAC");
if (row == 4)
return tr("Max. CNS");
// notes
if (col == 0) {
if (row == 6)
return tr("OTU");
return tr("Notes:");
if (row == 7)
return QString(dive->notes);
}
// sac, cns, otu - data
if (col == 4) {
if (row == 2)
return di.displaySac();
if (row == 4)
// 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;
const char *desc;
QString gases;
for (int i = 0; i < MAX_CYLINDERS; i++) {
desc = dive->cylinder[i].type.description;
// if has a description and if such gas is not already present
if (desc && gases.indexOf(QString(desc)) == -1) {
if (added > 0)
gases += QString(" / ");
gases += QString(desc);
added++;
}
}
return gases;
}
if (col == 2)
return QString::number(dive->maxcns);
if (row == 6)
return QString::number(dive->otu);
}
// weights heading
if (row == 2 && col == 5)
return tr("Weights");
// total weight
if (row == 9) {
weight_t tw = { total_weight(dive) };
if (tw.grams) {
if (col == 5)
return tr("Total weight");
if (col == 6)
return get_weight_string(tw, true);
if (col == 3)
return di.displaySac();
if (col == 4) {
weight_t tw = { total_weight(dive) };
return get_weight_string(tw, true);
}
}
// weight data
if (row > 2 && row < 10 && row - 3 < MAX_WEIGHTSYSTEMS) {
weightsystem_t *ws = &dive->weightsystem[row - 3];
if (ws->weight.grams) {
if (col == 5) {
if (ws->description && ws->description[0] != '\0')
return QString(ws->description);
return unknown;
}
if (col == 6) {
return get_weight_string(ws->weight, 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();
}
@ -1715,32 +1689,14 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
font.setPixelSize(baseSize + 1);
return QVariant::fromValue(font);
}
// dive location
if (row == 1 && col == 0) {
font.setPixelSize(baseSize);
font.setBold(true);
return QVariant::fromValue(font);
}
// depth/duration
if ((row == 0 || row == 1) && col == 5) {
font.setPixelSize(baseSize);
return QVariant::fromValue(font);
}
// notes
if (row == 9 && col == 0) {
font.setPixelSize(baseSize + 1);
return QVariant::fromValue(font);
}
font.setPixelSize(baseSize);
return QVariant::fromValue(font);
}
case Qt::TextAlignmentRole: {
unsigned int align = Qt::AlignCenter;
// dive #, location, notes
if ((row < 2 || row == 10) && col == 0)
align = Qt::AlignLeft | Qt::AlignVCenter;
// depth, duration
if (row < 2 && col == 5)
// 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);
}

View file

@ -36,17 +36,17 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op
tablePrintColumnWidths.append(15);
tablePrintColumnWidths.append(33);
// profile print settings
const int dw = 15; // base percentage
const int dw = 20; // base percentage
profilePrintColumnWidths.append(dw);
profilePrintColumnWidths.append(dw);
profilePrintColumnWidths.append(dw);
profilePrintColumnWidths.append(dw);
profilePrintColumnWidths.append(dw - 5);
profilePrintColumnWidths.append(dw + 5);
profilePrintColumnWidths.append(dw - 5); // fit to 100%
const int sr = 9; // smallest row height in pixels
profilePrintRowHeights.append(sr + 2);
profilePrintRowHeights.append(sr + 7);
profilePrintColumnWidths.append(dw - 3);
profilePrintColumnWidths.append(dw - 3);
profilePrintColumnWidths.append(dw + 6); // fit to 100%
const int sr = 12; // smallest row height in pixels
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr + 4);
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr);
@ -55,7 +55,6 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr);
profilePrintRowHeights.append(sr + 12);
}
void PrintLayout::print()
@ -211,23 +210,15 @@ QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int
* changes made here reflect on ProfilePrintModel::data(). */
const int cols = model->columnCount();
const int rows = model->rowCount();
// top section
table->setSpan(0, 0, 1, cols - 2);
table->setSpan(1, 0, 1, cols - 2);
table->setSpan(10, 0, 1, cols);
table->setSpan(0, 5, 1, 2);
table->setSpan(1, 5, 1, 12);
// sac, cns, otu
table->setSpan(2, 3, 2, 1);
table->setSpan(4, 3, 2, 1);
table->setSpan(6, 3, 2, 1);
table->setSpan(8, 3, 2, 1);
table->setSpan(2, 4, 2, 1);
table->setSpan(4, 4, 2, 1);
table->setSpan(6, 4, 2, 1);
table->setSpan(8, 4, 2, 1);
// weights
table->setSpan(2, 5, 1, 2);
// info on top
table->setSpan(0, 0, 1, 4);
table->setSpan(1, 0, 1, 4);
// gas used
table->setSpan(2, 0, 1, 2);
table->setSpan(3, 0, 1, 2);
// notes
table->setSpan(6, 0, 1, 5);
table->setSpan(7, 0, 5, 5);
/* resize row heights to the 'profilePrintRowHeights' indexes.
* profilePrintTableMaxH will then hold the table height. */