2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-05-10 15:35:30 +00:00
|
|
|
#include "qt-models/weightsysteminfomodel.h"
|
2024-04-17 09:31:50 +00:00
|
|
|
#include "core/equipment.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/metrics.h"
|
|
|
|
#include "core/gettextfromc.h"
|
2015-05-28 19:52:13 +00:00
|
|
|
|
|
|
|
QVariant WSInfoModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2024-04-17 09:31:50 +00:00
|
|
|
if (index.row() < 0 || index.row() >= static_cast<int>(ws_info_table.size()))
|
2024-03-30 12:40:00 +00:00
|
|
|
return QVariant();
|
2024-04-17 09:31:50 +00:00
|
|
|
const ws_info &info = ws_info_table[index.row()];
|
2015-05-28 19:52:13 +00:00
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::FontRole:
|
2024-03-30 12:40:00 +00:00
|
|
|
return defaultModelFont();
|
2015-05-28 19:52:13 +00:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
case Qt::EditRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case GR:
|
2024-04-17 09:31:50 +00:00
|
|
|
return info.weight.grams;
|
2015-05-28 19:52:13 +00:00
|
|
|
case DESCRIPTION:
|
2024-04-17 09:31:50 +00:00
|
|
|
// TODO: don't translate user supplied names
|
|
|
|
return gettextFromC::tr(info.name.c_str());
|
2015-05-28 19:52:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-03-30 12:40:00 +00:00
|
|
|
return QVariant();
|
2015-05-28 19:52:13 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 15:53:42 +00:00
|
|
|
int WSInfoModel::rowCount(const QModelIndex&) const
|
2015-05-28 19:52:13 +00:00
|
|
|
{
|
2024-04-17 09:31:50 +00:00
|
|
|
return static_cast<int>(ws_info_table.size());
|
2015-05-28 19:52:13 +00:00
|
|
|
}
|