##// END OF EJS Templates
Merge branch 'feature/DatetimeColumns' into develop
Alexandre Leroux -
r284:8ab9ca5324b3 merge
parent child
Show More
@@ -3,16 +3,43
3 3
4 4 #include <Data/IDataSeries.h>
5 5
6 #include <QDateTime>
7 #include <QSize>
8
6 9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
7 10
8 11 namespace {
9 12
10 13 // Column indexes
11 14 const auto NAME_COLUMN = 0;
12 const auto UNIT_COLUMN = 1;
13 const auto MISSION_COLUMN = 2;
15 const auto TSTART_COLUMN = 1;
16 const auto TEND_COLUMN = 2;
14 17 const auto NB_COLUMNS = 3;
15 18
19 // Column properties
20 const auto DEFAULT_HEIGHT = 25;
21 const auto DEFAULT_WIDTH = 100;
22
23 struct ColumnProperties {
24 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
25 int height = DEFAULT_HEIGHT)
26 : m_Name{name}, m_Width{width}, m_Height{height}
27 {
28 }
29
30 QString m_Name;
31 int m_Width;
32 int m_Height;
33 };
34
35 const auto COLUMN_PROPERTIES
36 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
37 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
38 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
39
40 /// Format for datetimes
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
42
16 43 } // namespace
17 44
18 45 struct VariableModel::VariableModelPrivate {
@@ -75,13 +102,19 QVariant VariableModel::data(const QModelIndex &index, int role) const
75 102
76 103 if (role == Qt::DisplayRole) {
77 104 if (auto variable = impl->m_Variables.at(index.row()).get()) {
105 /// Lambda function that builds the variant to return for a time value
106 auto dateTimeVariant = [](double time) {
107 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
108 return dateTime.toString(DATETIME_FORMAT);
109 };
110
78 111 switch (index.column()) {
79 112 case NAME_COLUMN:
80 113 return variable->name();
81 case UNIT_COLUMN:
82 return variable->unit();
83 case MISSION_COLUMN:
84 return variable->mission();
114 case TSTART_COLUMN:
115 return dateTimeVariant(variable->dateTime().m_TStart);
116 case TEND_COLUMN:
117 return dateTimeVariant(variable->dateTime().m_TEnd);
85 118 default:
86 119 // No action
87 120 break;
@@ -100,25 +133,22 QVariant VariableModel::data(const QModelIndex &index, int role) const
100 133
101 134 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
102 135 {
103 if (role != Qt::DisplayRole) {
136 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
104 137 return QVariant{};
105 138 }
106 139
107 140 if (orientation == Qt::Horizontal) {
108 switch (section) {
109 case NAME_COLUMN:
110 return tr("Name");
111 case UNIT_COLUMN:
112 return tr("Unit");
113 case MISSION_COLUMN:
114 return tr("Mission");
115 default:
116 // No action
117 break;
141 auto propertiesIt = COLUMN_PROPERTIES.find(section);
142 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
143 // Role is either DisplayRole or SizeHintRole
144 return (role == Qt::DisplayRole)
145 ? QVariant{propertiesIt->m_Name}
146 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
147 }
148 else {
149 qWarning(LOG_VariableModel())
150 << tr("Can't get header data (unknown column %1)").arg(section);
118 151 }
119
120 qWarning(LOG_VariableModel())
121 << tr("Can't get header data (unknown column %1)").arg(section);
122 152 }
123 153
124 154 return QVariant{};
@@ -21,6 +21,14 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
21 21
22 22 ui->tableView->setModel(sortFilterModel);
23 23
24 // Fixes column sizes
25 auto model = ui->tableView->model();
26 const auto count = model->columnCount();
27 for (auto i = 0; i < count; ++i) {
28 ui->tableView->setColumnWidth(
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
30 }
31
24 32 // Connection to show a menu when right clicking on the tree
25 33 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
26 34 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
General Comments 0
You need to be logged in to leave comments. Login now