Fill ws_info structure and use it when entering weight systems

The code to initialize the weight systems from the last datafile loaded
had not been brought over from the Gtk version.

We now correctly update the data structure when loading file (but not yet
when editing values).

Most likely the same needs to be done for the tanks as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-09-10 11:42:26 -07:00
parent 923b4cd9b1
commit e91ac60f49
5 changed files with 34 additions and 2 deletions

View file

@ -473,11 +473,21 @@ void add_cylinder_description(cylinder_type_t *type)
void add_weightsystem_description(weightsystem_t *weightsystem)
{
const char *desc;
int i;
desc = weightsystem->description;
if (!desc)
return;
/* now do something with it... */
for (i = 0; i < 100 && ws_info[i].name != NULL; i++) {
if (strcmp(ws_info[i].name, desc) == 0) {
ws_info[i].grams = weightsystem->weight.grams;
return;
}
}
if (i < 100) {
ws_info[i].name = desc;
ws_info[i].grams = weightsystem->weight.grams;
}
}
#endif /* USE_GTK_UI */

View file

@ -744,6 +744,8 @@ void MainWindow::importFiles(const QStringList fileNames)
ui->globe->reload();
ui->ListWidget->reload(DiveTripModel::TREE);
ui->ListWidget->setFocus();
WSInfoModel *wsim = WSInfoModel::instance();
wsim->updateInfo();
}
void MainWindow::loadFiles(const QStringList fileNames)
@ -769,4 +771,6 @@ void MainWindow::loadFiles(const QStringList fileNames)
ui->globe->reload();
ui->ListWidget->reload(DiveTripModel::TREE);
ui->ListWidget->setFocus();
WSInfoModel *wsim = WSInfoModel::instance();
wsim->updateInfo();
}

View file

@ -238,7 +238,6 @@ void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, co
}
mymodel->setData(IDX(WeightModel::TYPE), v, Qt::EditRole);
mymodel->passInData(IDX(WeightModel::WEIGHT), grams);
qDebug() << "Fixme, every weight is 0.0 grams. see:" << grams;
}
WSInfoDelegate::WSInfoDelegate(QObject* parent): ComboBoxDelegate(WSInfoModel::instance(), parent)

View file

@ -650,6 +650,24 @@ WSInfoModel::WSInfoModel() : QAbstractTableModel(), rows(-1)
}
}
void WSInfoModel::updateInfo()
{
struct ws_info *info = ws_info;
beginRemoveRows(QModelIndex(), 0, this->rows);
endRemoveRows();
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);
endInsertRows();
}
}
void WSInfoModel::update()
{
if (rows > -1) {

View file

@ -59,6 +59,7 @@ public:
const QString& biggerString() const;
void clear();
void update();
void updateInfo();
private:
int rows;
QString biggerEntry;