mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Make the columns have a sane default width for 'type'
Make the columns on Cylinders edit and Wheight Edit to have sane values for 'type', this is needed because the old behavior was to set it fixed size, and the default fixed size was silly. this calculates a good predefined value taking the font size in consideration. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
f9b4c6b889
commit
20849f014e
3 changed files with 31 additions and 3 deletions
|
@ -80,12 +80,16 @@ 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)));
|
||||||
|
|
||||||
QFontMetrics metrics(defaultModelFont());
|
QFontMetrics metrics(defaultModelFont());
|
||||||
|
QFontMetrics metrics2(font());
|
||||||
|
|
||||||
ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24);
|
ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24);
|
||||||
|
ui->cylinders->setColumnWidth(CylindersModel::TYPE, metrics2.width(TankInfoModel::instance()->biggerString()) + 20);
|
||||||
ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
|
ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
|
||||||
ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
|
ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
|
||||||
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->setColumnWidth(WeightModel::TYPE, metrics2.width(WSInfoModel::instance()->biggerString()) + 20);
|
||||||
ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
|
ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
|
||||||
ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
|
ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
|
||||||
ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
|
ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
|
||||||
|
|
|
@ -583,10 +583,20 @@ int WSInfoModel::rowCount(const QModelIndex& parent) const
|
||||||
return rows+1;
|
return rows+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString& WSInfoModel::biggerString() const
|
||||||
|
{
|
||||||
|
return biggerEntry;
|
||||||
|
}
|
||||||
|
|
||||||
WSInfoModel::WSInfoModel() : QAbstractTableModel(), rows(-1)
|
WSInfoModel::WSInfoModel() : QAbstractTableModel(), rows(-1)
|
||||||
{
|
{
|
||||||
struct ws_info *info = ws_info;
|
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) {
|
if (rows > -1) {
|
||||||
beginInsertRows(QModelIndex(), 0, rows);
|
beginInsertRows(QModelIndex(), 0, rows);
|
||||||
|
@ -616,6 +626,11 @@ TankInfoModel* TankInfoModel::instance()
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString& TankInfoModel::biggerString() const
|
||||||
|
{
|
||||||
|
return biggerEntry;
|
||||||
|
}
|
||||||
|
|
||||||
bool TankInfoModel::insertRows(int row, int count, const QModelIndex& parent)
|
bool TankInfoModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||||
{
|
{
|
||||||
beginInsertRows(parent, rowCount(), rowCount());
|
beginInsertRows(parent, rowCount(), rowCount());
|
||||||
|
@ -723,7 +738,13 @@ int TankInfoModel::rowCount(const QModelIndex& parent) const
|
||||||
TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1)
|
TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1)
|
||||||
{
|
{
|
||||||
struct tank_info *info = tank_info;
|
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) {
|
if (rows > -1) {
|
||||||
beginInsertRows(QModelIndex(), 0, rows);
|
beginInsertRows(QModelIndex(), 0, rows);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
|
@ -32,10 +32,12 @@ public:
|
||||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
/*reimp*/ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
/*reimp*/ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
||||||
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
|
const QString& biggerString() const;
|
||||||
void clear();
|
void clear();
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
int rows;
|
int rows;
|
||||||
|
QString biggerEntry;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Encapsulate ws_info */
|
/* Encapsulate ws_info */
|
||||||
|
@ -53,11 +55,12 @@ public:
|
||||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
/*reimp*/ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
/*reimp*/ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
||||||
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
|
const QString& biggerString() const;
|
||||||
void clear();
|
void clear();
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
int rows;
|
int rows;
|
||||||
|
QString biggerEntry;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Encapsulation of the Cylinder Model, that presents the
|
/* Encapsulation of the Cylinder Model, that presents the
|
||||||
|
|
Loading…
Add table
Reference in a new issue