diff options
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 141 |
1 files changed, 133 insertions, 8 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 0af5c7019..fc91e0558 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -549,7 +549,7 @@ bool WSInfoModel::insertRows(int row, int count, const QModelIndex& parent) bool WSInfoModel::setData(const QModelIndex& index, const QVariant& value, int role) { - struct ws_info *info = &ws_info[index.row()]; + struct ws_info_t *info = &ws_info[index.row()]; switch(index.column()) { case DESCRIPTION: info->name = strdup(value.toByteArray().data()); @@ -577,7 +577,7 @@ QVariant WSInfoModel::data(const QModelIndex& index, int role) const if (!index.isValid()) { return ret; } - struct ws_info *info = &ws_info[index.row()]; + struct ws_info_t *info = &ws_info[index.row()]; int gr = info->grams; switch(role){ @@ -636,7 +636,26 @@ const QString& WSInfoModel::biggerString() const WSInfoModel::WSInfoModel() : QAbstractTableModel(), rows(-1) { - struct ws_info *info = ws_info; + struct ws_info_t *info = ws_info; + 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::updateInfo() +{ + struct ws_info_t *info = ws_info; + beginRemoveRows(QModelIndex(), 0, this->rows); + endRemoveRows(); + rows = -1; for (info = ws_info; info->name; info++, rows++){ QString wsInfoName(info->name); if( wsInfoName.count() > biggerEntry.count()){ @@ -657,7 +676,7 @@ void WSInfoModel::update() endRemoveRows(); rows = -1; } - struct ws_info *info = ws_info; + struct ws_info_t *info = ws_info; for (info = ws_info; info->name; info++, rows++); if (rows > -1) { @@ -687,7 +706,7 @@ bool TankInfoModel::insertRows(int row, int count, const QModelIndex& parent) bool TankInfoModel::setData(const QModelIndex& index, const QVariant& value, int role) { - struct tank_info *info = &tank_info[index.row()]; + struct tank_info_t *info = &tank_info[index.row()]; switch(index.column()) { case DESCRIPTION: info->name = strdup(value.toByteArray().data()); @@ -722,7 +741,7 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const return defaultModelFont(); } if (role == Qt::DisplayRole || role == Qt::EditRole) { - struct tank_info *info = &tank_info[index.row()]; + struct tank_info_t *info = &tank_info[index.row()]; int ml = info->ml; double bar = (info->psi) ? psi_to_bar(info->psi) : info->bar; @@ -779,7 +798,7 @@ int TankInfoModel::rowCount(const QModelIndex& parent) const TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1) { - struct tank_info *info = tank_info; + struct tank_info_t *info = tank_info; for (info = tank_info; info->name; info++, rows++){ QString infoName(info->name); if (infoName.count() > biggerEntry.count()){ @@ -800,7 +819,7 @@ void TankInfoModel::update() endRemoveRows(); rows = -1; } - struct tank_info *info = tank_info; + struct tank_info_t *info = tank_info; for (info = tank_info; info->name; info++, rows++); if (rows > -1) { @@ -1438,3 +1457,109 @@ void YearlyStatisticsModel::update_yearly_stats() item->parent = rootItem; } } + +/*################################################################# + * # + * # Table Print Model + * # + * ################################################################ + */ +TablePrintModel::TablePrintModel() +{ + columns = 7; + rows = 0; +} + +TablePrintModel::~TablePrintModel() +{ + for (int i = 0; i < list.size(); i++) + delete list.at(i); +} + +void TablePrintModel::insertRow(int index) +{ + struct TablePrintItem *item = new struct TablePrintItem(); + item->colorBackground = 0xffffffff; + if (index == -1) { + beginInsertRows(QModelIndex(), rows, rows); + list.append(item); + } else { + beginInsertRows(QModelIndex(), index, index); + list.insert(index, item); + } + endInsertRows(); + rows++; +} + +void TablePrintModel::callReset() +{ + reset(); +} + +QVariant TablePrintModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + if (role == Qt::BackgroundRole) + return QColor(list.at(index.row())->colorBackground); + if (role == Qt::DisplayRole) + switch (index.column()) { + case 0: + return list.at(index.row())->number; + case 1: + return list.at(index.row())->date; + case 2: + return list.at(index.row())->depth; + case 3: + return list.at(index.row())->duration; + case 4: + return list.at(index.row())->divemaster; + case 5: + return list.at(index.row())->buddy; + case 6: + return list.at(index.row())->location; + } + return QVariant(); +} + +bool TablePrintModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (index.isValid()) { + if (role == Qt::DisplayRole) { + switch (index.column()) { + case 0: + list.at(index.row())->number = value.toString(); + case 1: + list.at(index.row())->date = value.toString(); + case 2: + list.at(index.row())->depth = value.toString(); + case 3: + list.at(index.row())->duration = value.toString(); + case 4: + list.at(index.row())->divemaster = value.toString(); + case 5: + list.at(index.row())->buddy = value.toString(); + case 6: + list.at(index.row())->location = value.toString(); + } + return true; + } + if (role == Qt::BackgroundRole) { + list.at(index.row())->colorBackground = value.value<unsigned int>(); + return true; + } + } + return false; +} + +int TablePrintModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return rows; +} + +int TablePrintModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return columns; +} |