Made all models have the same font.

The models were a bit messy - some of them got the correct font,
other didnt. This patch creates a new function 'defaultModelFont()'
that is being used to return the font in all cases now.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-06-16 11:13:32 -03:00
parent 10ea572f5a
commit 349a084496

View file

@ -14,6 +14,13 @@
#include <QFont> #include <QFont>
#include <QIcon> #include <QIcon>
QFont defaultModelFont()
{
QFont font;
font.setPointSizeF( font.pointSizeF() * 0.8);
return font;
}
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), current(0), rows(0) CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), current(0), rows(0)
{ {
} }
@ -21,15 +28,14 @@ CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), cu
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
QVariant ret; QVariant ret;
QFont font;
if (orientation == Qt::Vertical) if (orientation == Qt::Vertical)
return ret; return ret;
switch (role) { switch (role) {
case Qt::FontRole: case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.8); ret = defaultModelFont();
return font; break;
case Qt::DisplayRole: case Qt::DisplayRole:
switch(section) { switch(section) {
case TYPE: ret = tr("Type"); break; case TYPE: ret = tr("Type"); break;
@ -52,7 +58,6 @@ int CylindersModel::columnCount(const QModelIndex& parent) const
QVariant CylindersModel::data(const QModelIndex& index, int role) const QVariant CylindersModel::data(const QModelIndex& index, int role) const
{ {
QVariant ret; QVariant ret;
QFont font;
if (!index.isValid() || index.row() >= MAX_CYLINDERS) if (!index.isValid() || index.row() >= MAX_CYLINDERS)
return ret; return ret;
@ -60,8 +65,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
cylinder_t *cyl = &current->cylinder[index.row()]; cylinder_t *cyl = &current->cylinder[index.row()];
switch (role) { switch (role) {
case Qt::FontRole: case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.80); ret = defaultModelFont();
ret = font;
break; break;
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
ret = Qt::AlignRight; ret = Qt::AlignRight;
@ -336,7 +340,6 @@ int WeightModel::columnCount(const QModelIndex& parent) const
QVariant WeightModel::data(const QModelIndex& index, int role) const QVariant WeightModel::data(const QModelIndex& index, int role) const
{ {
QVariant ret; QVariant ret;
QFont font;
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS) if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS)
return ret; return ret;
@ -344,8 +347,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
switch (role) { switch (role) {
case Qt::FontRole: case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.80); ret = defaultModelFont();
ret = font;
break; break;
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
ret = Qt::AlignRight; ret = Qt::AlignRight;
@ -429,14 +431,12 @@ int WeightModel::rowCount(const QModelIndex& parent) const
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
QVariant ret; QVariant ret;
QFont font;
if (orientation == Qt::Vertical) if (orientation == Qt::Vertical)
return ret; return ret;
switch (role) { switch (role) {
case Qt::FontRole: case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.8); ret = defaultModelFont();
ret = font;
break; break;
case Qt::DisplayRole: case Qt::DisplayRole:
switch(section) { switch(section) {
@ -534,16 +534,21 @@ QVariant WSInfoModel::data(const QModelIndex& index, int role) const
struct ws_info *info = &ws_info[index.row()]; struct ws_info *info = &ws_info[index.row()];
int gr = info->grams; int gr = info->grams;
switch(role){
if (role == Qt::DisplayRole || role == Qt::EditRole) { case Qt::FontRole :
switch(index.column()) { ret = defaultModelFont();
case GR: break;
ret = gr; case Qt::DisplayRole :
break; case Qt::EditRole :
case DESCRIPTION: switch(index.column()) {
ret = QString(info->name); case GR:
break; ret = gr;
} break;
case DESCRIPTION:
ret = QString(info->name);
break;
}
break;
} }
return ret; return ret;
} }
@ -555,15 +560,20 @@ QVariant WSInfoModel::headerData(int section, Qt::Orientation orientation, int r
if (orientation != Qt::Horizontal) if (orientation != Qt::Horizontal)
return ret; return ret;
if (role == Qt::DisplayRole) { switch(role){
switch(section) { case Qt::FontRole :
case GR: ret = defaultModelFont();
ret = tr("kg"); break;
break; case Qt::DisplayRole :
case DESCRIPTION: switch(section) {
ret = tr("Description"); case GR:
break; ret = tr("kg");
} break;
case DESCRIPTION:
ret = tr("Description");
break;
}
break;
} }
return ret; return ret;
} }
@ -680,8 +690,12 @@ QVariant TankInfoModel::headerData(int section, Qt::Orientation orientation, int
if (orientation != Qt::Horizontal) if (orientation != Qt::Horizontal)
return ret; return ret;
if (role == Qt::DisplayRole) { switch(role){
switch(section) { case Qt::FontRole:
ret = defaultModelFont();
break;
case Qt::DisplayRole:
switch(section) {
case BAR: case BAR:
ret = tr("Bar"); ret = tr("Bar");
break; break;
@ -691,7 +705,8 @@ QVariant TankInfoModel::headerData(int section, Qt::Orientation orientation, int
case DESCRIPTION: case DESCRIPTION:
ret = tr("Description"); ret = tr("Description");
break; break;
} }
break;
} }
return ret; return ret;
} }
@ -752,21 +767,25 @@ int TreeItemDT::row() const
QVariant TreeItemDT::data(int column, int role) const QVariant TreeItemDT::data(int column, int role) const
{ {
QVariant ret; QVariant ret;
switch (column) { switch(role){
case NR: ret = tr("#"); break; case Qt::DisplayRole :
case DATE: ret = tr("Date"); break; switch (column) {
case RATING: ret = UTF8_BLACKSTAR; break; case NR: ret = tr("#"); break;
case DEPTH: ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft"); break; case DATE: ret = tr("Date"); break;
case DURATION: ret = tr("min"); break; case RATING: ret = UTF8_BLACKSTAR; break;
case TEMPERATURE: ret = QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break; case DEPTH: ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft"); break;
case TOTALWEIGHT: ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs"); break; case DURATION: ret = tr("min"); break;
case SUIT: ret = tr("Suit"); break; case TEMPERATURE: ret = QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break;
case CYLINDER: ret = tr("Cyl"); break; case TOTALWEIGHT: ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs"); break;
case NITROX: ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2); break; case SUIT: ret = tr("Suit"); break;
case SAC: ret = tr("SAC"); break; case CYLINDER: ret = tr("Cyl"); break;
case OTU: ret = tr("OTU"); break; case NITROX: ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2); break;
case MAXCNS: ret = tr("maxCNS"); break; case SAC: ret = tr("SAC"); break;
case LOCATION: ret = tr("Location"); break; case OTU: ret = tr("OTU"); break;
case MAXCNS: ret = tr("maxCNS"); break;
case LOCATION: ret = tr("Location"); break;
}
break;
} }
return ret; return ret;
} }
@ -981,9 +1000,7 @@ QVariant DiveTripModel::data(const QModelIndex& index, int role) const
return QVariant(); return QVariant();
if (role == Qt::FontRole) { if (role == Qt::FontRole) {
QFont font; return defaultModelFont();
font.setPointSizeF(font.pointSizeF() * 0.7);
return font;
} }
TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer()); TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer());
@ -1004,6 +1021,11 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation,
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section, role); return rootItem->data(section, role);
switch(role){
case Qt::FontRole :
return defaultModelFont();
}
return QVariant(); return QVariant();
} }