Try to make the equipment tab more compact

My attempts to actually set the width of the columns with the
SizeHintRole all failed - so I gave up on that and am forcing things to
work by making the texts in the header somewhat longer and then resizing
to that. Definitely not what I wanted to do - but that plus reducing the
font size gives us a much more reasonable / compact look.

I really hope that someone else can explain to me how to get the
SizeHintRole to affect the width (and not just the height - that part
worked just fine) of a the cells in a column. Then we can replace this
hack by a much better solution (that won't fail if the translated strings
look different).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-05-25 20:04:31 -07:00
parent 4409d61f7c
commit 81e27b6db9
2 changed files with 50 additions and 13 deletions

View file

@ -80,7 +80,8 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex))); connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex)));
ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24); ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24);
ui->cylinders->horizontalHeader()->setResizeMode (CylindersModel::REMOVE , QHeaderView::Fixed); ui->cylinders->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate()); ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
ui->weights->setColumnWidth(WeightModel::REMOVE, 24); ui->weights->setColumnWidth(WeightModel::REMOVE, 24);
ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed); ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);

View file

@ -21,10 +21,16 @@ 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;
if (role == Qt::DisplayRole) { switch (role) {
case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.8);
return font;
case Qt::DisplayRole:
switch(section) { switch(section) {
case TYPE: case TYPE:
ret = tr("Type"); ret = tr("Type");
@ -36,16 +42,16 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in
ret = tr("WorkPress"); ret = tr("WorkPress");
break; break;
case START: case START:
ret = tr("Start"); ret = tr("StartPress");
break; break;
case END: case END:
ret = tr("End"); ret = tr("EndPress ");
break; break;
case O2: case O2:
ret = tr("O2%"); ret = tr("O2% ");
break; break;
case HE: case HE:
ret = tr("He%"); ret = tr("He% ");
break; break;
} }
} }
@ -60,12 +66,22 @@ 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;
cylinder_t *cyl = &current->cylinder[index.row()]; cylinder_t *cyl = &current->cylinder[index.row()];
switch (role) {
if (role == Qt::DisplayRole || role==Qt::EditRole) { case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.80);
ret = font;
break;
case Qt::TextAlignmentRole:
ret = Qt::AlignRight;
break;
case Qt::DisplayRole:
case Qt::EditRole:
switch(index.column()) { switch(index.column()) {
case TYPE: case TYPE:
ret = QString(cyl->type.description); ret = QString(cyl->type.description);
@ -101,11 +117,12 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
ret = QString("%1%").arg((cyl->gasmix.he.permille + 5) / 10); ret = QString("%1%").arg((cyl->gasmix.he.permille + 5) / 10);
break; break;
} }
} else if (role == Qt::DecorationRole) { break;
case Qt::DecorationRole:
if (index.column() == REMOVE) if (index.column() == REMOVE)
ret = QIcon(":trash"); ret = QIcon(":trash");
break;
} }
return ret; return ret;
} }
@ -333,12 +350,22 @@ 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;
weightsystem_t *ws = &current->weightsystem[index.row()]; weightsystem_t *ws = &current->weightsystem[index.row()];
if (role == Qt::DisplayRole || role == Qt::EditRole) { switch (role) {
case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.80);
ret = font;
break;
case Qt::TextAlignmentRole:
ret = Qt::AlignRight;
break;
case Qt::DisplayRole:
case Qt::EditRole:
switch(index.column()) { switch(index.column()) {
case TYPE: case TYPE:
ret = QString(ws->description); ret = QString(ws->description);
@ -347,9 +374,11 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
ret = get_weight_string(ws->weight, TRUE); ret = get_weight_string(ws->weight, TRUE);
break; break;
} }
} else if (role == Qt::DecorationRole) { break;
case Qt::DecorationRole:
if (index.column() == REMOVE) if (index.column() == REMOVE)
ret = QIcon(":trash"); ret = QIcon(":trash");
break;
} }
return ret; return ret;
} }
@ -414,10 +443,16 @@ 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;
if (role == Qt::DisplayRole) { switch (role) {
case Qt::FontRole:
font.setPointSizeF(font.pointSizeF() * 0.8);
ret = font;
break;
case Qt::DisplayRole:
switch(section) { switch(section) {
case TYPE: case TYPE:
ret = tr("Type"); ret = tr("Type");
@ -426,6 +461,7 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r
ret = tr("Weight"); ret = tr("Weight");
break; break;
} }
break;
} }
return ret; return ret;
} }