summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp171
1 files changed, 109 insertions, 62 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 868cba952..03300a8d6 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -16,6 +16,13 @@
#include <QFont>
#include <QIcon>
+QFont defaultModelFont()
+{
+ QFont font;
+ font.setPointSizeF( font.pointSizeF() * 0.8);
+ return font;
+}
+
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), current(0), rows(0)
{
}
@@ -23,15 +30,14 @@ CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), cu
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant ret;
- QFont font;
if (orientation == Qt::Vertical)
return ret;
switch (role) {
case Qt::FontRole:
- font.setPointSizeF(font.pointSizeF() * 0.8);
- return font;
+ ret = defaultModelFont();
+ break;
case Qt::DisplayRole:
switch(section) {
case TYPE: ret = tr("Type"); break;
@@ -54,7 +60,6 @@ int CylindersModel::columnCount(const QModelIndex& parent) const
QVariant CylindersModel::data(const QModelIndex& index, int role) const
{
QVariant ret;
- QFont font;
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
return ret;
@@ -62,11 +67,10 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
cylinder_t *cyl = &current->cylinder[index.row()];
switch (role) {
case Qt::FontRole:
- font.setPointSizeF(font.pointSizeF() * 0.80);
- ret = font;
+ ret = defaultModelFont();
break;
case Qt::TextAlignmentRole:
- ret = Qt::AlignRight;
+ ret = Qt::AlignHCenter;
break;
case Qt::DisplayRole:
case Qt::EditRole:
@@ -338,7 +342,6 @@ int WeightModel::columnCount(const QModelIndex& parent) const
QVariant WeightModel::data(const QModelIndex& index, int role) const
{
QVariant ret;
- QFont font;
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS)
return ret;
@@ -346,8 +349,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
switch (role) {
case Qt::FontRole:
- font.setPointSizeF(font.pointSizeF() * 0.80);
- ret = font;
+ ret = defaultModelFont();
break;
case Qt::TextAlignmentRole:
ret = Qt::AlignRight;
@@ -431,14 +433,12 @@ int WeightModel::rowCount(const QModelIndex& parent) const
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant ret;
- QFont font;
if (orientation == Qt::Vertical)
return ret;
switch (role) {
case Qt::FontRole:
- font.setPointSizeF(font.pointSizeF() * 0.8);
- ret = font;
+ ret = defaultModelFont();
break;
case Qt::DisplayRole:
switch(section) {
@@ -536,16 +536,21 @@ QVariant WSInfoModel::data(const QModelIndex& index, int role) const
struct ws_info *info = &ws_info[index.row()];
int gr = info->grams;
-
- if (role == Qt::DisplayRole || role == Qt::EditRole) {
- switch(index.column()) {
- case GR:
- ret = gr;
- break;
- case DESCRIPTION:
- ret = QString(info->name);
- break;
- }
+ switch(role){
+ case Qt::FontRole :
+ ret = defaultModelFont();
+ break;
+ case Qt::DisplayRole :
+ case Qt::EditRole :
+ switch(index.column()) {
+ case GR:
+ ret = gr;
+ break;
+ case DESCRIPTION:
+ ret = QString(info->name);
+ break;
+ }
+ break;
}
return ret;
}
@@ -557,15 +562,20 @@ QVariant WSInfoModel::headerData(int section, Qt::Orientation orientation, int r
if (orientation != Qt::Horizontal)
return ret;
- if (role == Qt::DisplayRole) {
- switch(section) {
- case GR:
- ret = tr("kg");
- break;
- case DESCRIPTION:
- ret = tr("Description");
- break;
- }
+ switch(role){
+ case Qt::FontRole :
+ ret = defaultModelFont();
+ break;
+ case Qt::DisplayRole :
+ switch(section) {
+ case GR:
+ ret = tr("kg");
+ break;
+ case DESCRIPTION:
+ ret = tr("Description");
+ break;
+ }
+ break;
}
return ret;
}
@@ -575,10 +585,20 @@ int WSInfoModel::rowCount(const QModelIndex& parent) const
return rows+1;
}
+const QString& WSInfoModel::biggerString() const
+{
+ return biggerEntry;
+}
+
WSInfoModel::WSInfoModel() : QAbstractTableModel(), rows(-1)
{
struct ws_info *info = ws_info;
- for (info = ws_info; info->name; info++, rows++);
+ for (info = ws_info; info->name; info++, rows++){
+ QString wsInfoName(info->name);
+ if( wsInfoName.count() > biggerEntry.count()){
+ biggerEntry = wsInfoName;
+ }
+ }
if (rows > -1) {
beginInsertRows(QModelIndex(), 0, rows);
@@ -608,6 +628,11 @@ TankInfoModel* TankInfoModel::instance()
return self;
}
+const QString& TankInfoModel::biggerString() const
+{
+ return biggerEntry;
+}
+
bool TankInfoModel::insertRows(int row, int count, const QModelIndex& parent)
{
beginInsertRows(parent, rowCount(), rowCount());
@@ -648,6 +673,10 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const
if (!index.isValid()) {
return ret;
}
+ if (role == Qt::FontRole){
+ return defaultModelFont();
+ }
+
struct tank_info *info = &tank_info[index.row()];
int ml = info->ml;
@@ -682,8 +711,12 @@ QVariant TankInfoModel::headerData(int section, Qt::Orientation orientation, int
if (orientation != Qt::Horizontal)
return ret;
- if (role == Qt::DisplayRole) {
- switch(section) {
+ switch(role){
+ case Qt::FontRole:
+ ret = defaultModelFont();
+ break;
+ case Qt::DisplayRole:
+ switch(section) {
case BAR:
ret = tr("Bar");
break;
@@ -693,7 +726,8 @@ QVariant TankInfoModel::headerData(int section, Qt::Orientation orientation, int
case DESCRIPTION:
ret = tr("Description");
break;
- }
+ }
+ break;
}
return ret;
}
@@ -706,7 +740,13 @@ int TankInfoModel::rowCount(const QModelIndex& parent) const
TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1)
{
struct tank_info *info = tank_info;
- for (info = tank_info; info->name; info++, rows++);
+ for (info = tank_info; info->name; info++, rows++){
+ QString infoName(info->name);
+ if (infoName.count() > biggerEntry.count()){
+ biggerEntry = infoName;
+ }
+ }
+
if (rows > -1) {
beginInsertRows(QModelIndex(), 0, rows);
endInsertRows();
@@ -754,21 +794,25 @@ int TreeItemDT::row() const
QVariant TreeItemDT::data(int column, int role) const
{
QVariant ret;
- switch (column) {
- case NR: ret = tr("#"); break;
- case DATE: ret = tr("Date"); break;
- case RATING: ret = UTF8_BLACKSTAR; break;
- case DEPTH: ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft"); break;
- case DURATION: ret = tr("min"); break;
- case TEMPERATURE: ret = QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break;
- case TOTALWEIGHT: ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs"); break;
- case SUIT: ret = tr("Suit"); break;
- case CYLINDER: ret = tr("Cyl"); break;
- case NITROX: ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2); break;
- case SAC: ret = tr("SAC"); break;
- case OTU: ret = tr("OTU"); break;
- case MAXCNS: ret = tr("maxCNS"); break;
- case LOCATION: ret = tr("Location"); break;
+ switch(role){
+ case Qt::DisplayRole :
+ switch (column) {
+ case NR: ret = tr("#"); break;
+ case DATE: ret = tr("Date"); break;
+ case RATING: ret = UTF8_BLACKSTAR; break;
+ case DEPTH: ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft"); break;
+ case DURATION: ret = tr("min"); break;
+ case TEMPERATURE: ret = QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break;
+ case TOTALWEIGHT: ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs"); break;
+ case SUIT: ret = tr("Suit"); break;
+ case CYLINDER: ret = tr("Cyl"); break;
+ case NITROX: ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2); break;
+ case SAC: ret = tr("SAC"); break;
+ case OTU: ret = tr("OTU"); break;
+ case MAXCNS: ret = tr("maxCNS"); break;
+ case LOCATION: ret = tr("Location"); break;
+ }
+ break;
}
return ret;
}
@@ -787,11 +831,8 @@ QVariant TripItem::data(int column, int role) const
if (role == Qt::DisplayRole) {
switch (column) {
- case LOCATION:
- ret = QString(trip->location);
- break;
- case DATE:
- ret = QString(get_trip_date_string(trip->when, trip->nrdives));
+ case NR:
+ ret = QString(trip->location) + ", " + QString(get_trip_date_string(trip->when, trip->nrdives));
break;
}
}
@@ -837,7 +878,7 @@ QVariant DiveItem::data(int column, int role) const
break;
case SORT_ROLE:
switch (column) {
- case NR: retVal = dive->number; break;
+ case NR: retVal = (qulonglong) dive->when; break;
case DATE: retVal = (qulonglong) dive->when; break;
case RATING: retVal = dive->rating; break;
case DEPTH: retVal = dive->maxdepth.mm; break;
@@ -932,7 +973,7 @@ QString DiveItem::displaySac() const
QString str;
if (get_units()->volume == units::LITER)
- str = QString::number(dive->sac / 1000, 'f', 1);
+ str = QString::number(dive->sac / 1000.0, 'f', 1);
else
str = QString::number(ml_to_cuft(dive->sac), 'f', 2);
@@ -986,9 +1027,7 @@ QVariant DiveTripModel::data(const QModelIndex& index, int role) const
return QVariant();
if (role == Qt::FontRole) {
- QFont font;
- font.setPointSizeF(font.pointSizeF() * 0.7);
- return font;
+ return defaultModelFont();
}
TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer());
@@ -1009,6 +1048,11 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation,
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section, role);
+ switch(role){
+ case Qt::FontRole :
+ return defaultModelFont();
+ }
+
return QVariant();
}
@@ -1062,6 +1106,9 @@ void DiveTripModel::setupModelData()
endRemoveRows();
}
+ if (autogroup)
+ autogroup_dives();
+ dive_table.preexisting = dive_table.nr;
while (--i >= 0) {
struct dive* dive = get_dive(i);
update_cylinder_related_info(dive);