mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Print: remove the helper function to truncate strings
ProfilePrintPmode::truncateString() was not really needed, because long text *should* be trunctated by the table itself. Also we now are going to have multiple lines for notes, so the auto-trim should work. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
a60475d336
commit
89ba9b113d
1 changed files with 4 additions and 26 deletions
|
@ -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)
|
void ProfilePrintModel::setDive(struct dive *divePtr)
|
||||||
{
|
{
|
||||||
dive = divePtr;
|
dive = divePtr;
|
||||||
|
@ -1618,15 +1596,15 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
|
||||||
if (row == 0) {
|
if (row == 0) {
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
return tr("Dive #%1 - %2").arg(dive->number).arg(di.displayDate());
|
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";
|
QString unit = (get_units()->length == units::METERS) ? "m" : "ft";
|
||||||
return tr("Max depth: %1 %2").arg(di.displayDepth()).arg(unit);
|
return tr("Max depth: %1 %2").arg(di.displayDepth()).arg(unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (row == 1) {
|
if (row == 1) {
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
return truncateString(dive->location, 32);
|
return QString(dive->location);
|
||||||
if (col == 5)
|
if (col == 4)
|
||||||
return QString(tr("Duration: %1 min")).arg(di.displayDuration());
|
return QString(tr("Duration: %1 min")).arg(di.displayDuration());
|
||||||
}
|
}
|
||||||
// cylinder headings
|
// cylinder headings
|
||||||
|
@ -1658,7 +1636,7 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
// dive notes
|
// dive notes
|
||||||
if (row == 10 && col == 0)
|
if (row == 10 && col == 0)
|
||||||
return truncateString(dive->notes, 640);
|
return QString(dive->notes);
|
||||||
// sac, cns, otu - headings
|
// sac, cns, otu - headings
|
||||||
if (col == 3) {
|
if (col == 3) {
|
||||||
if (row == 2)
|
if (row == 2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue