##// 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 #include <Data/IDataSeries.h>
4 #include <Data/IDataSeries.h>
5
5
6 #include <QDateTime>
7 #include <QSize>
8
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
7
10
8 namespace {
11 namespace {
9
12
10 // Column indexes
13 // Column indexes
11 const auto NAME_COLUMN = 0;
14 const auto NAME_COLUMN = 0;
12 const auto UNIT_COLUMN = 1;
15 const auto TSTART_COLUMN = 1;
13 const auto MISSION_COLUMN = 2;
16 const auto TEND_COLUMN = 2;
14 const auto NB_COLUMNS = 3;
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 } // namespace
43 } // namespace
17
44
18 struct VariableModel::VariableModelPrivate {
45 struct VariableModel::VariableModelPrivate {
@@ -75,13 +102,19 QVariant VariableModel::data(const QModelIndex &index, int role) const
75
102
76 if (role == Qt::DisplayRole) {
103 if (role == Qt::DisplayRole) {
77 if (auto variable = impl->m_Variables.at(index.row()).get()) {
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 switch (index.column()) {
111 switch (index.column()) {
79 case NAME_COLUMN:
112 case NAME_COLUMN:
80 return variable->name();
113 return variable->name();
81 case UNIT_COLUMN:
114 case TSTART_COLUMN:
82 return variable->unit();
115 return dateTimeVariant(variable->dateTime().m_TStart);
83 case MISSION_COLUMN:
116 case TEND_COLUMN:
84 return variable->mission();
117 return dateTimeVariant(variable->dateTime().m_TEnd);
85 default:
118 default:
86 // No action
119 // No action
87 break;
120 break;
@@ -100,25 +133,22 QVariant VariableModel::data(const QModelIndex &index, int role) const
100
133
101 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
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 return QVariant{};
137 return QVariant{};
105 }
138 }
106
139
107 if (orientation == Qt::Horizontal) {
140 if (orientation == Qt::Horizontal) {
108 switch (section) {
141 auto propertiesIt = COLUMN_PROPERTIES.find(section);
109 case NAME_COLUMN:
142 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
110 return tr("Name");
143 // Role is either DisplayRole or SizeHintRole
111 case UNIT_COLUMN:
144 return (role == Qt::DisplayRole)
112 return tr("Unit");
145 ? QVariant{propertiesIt->m_Name}
113 case MISSION_COLUMN:
146 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
114 return tr("Mission");
147 }
115 default:
148 else {
116 // No action
149 qWarning(LOG_VariableModel())
117 break;
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 return QVariant{};
154 return QVariant{};
@@ -21,6 +21,14 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
21
21
22 ui->tableView->setModel(sortFilterModel);
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 // Connection to show a menu when right clicking on the tree
32 // Connection to show a menu when right clicking on the tree
25 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
33 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
26 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
34 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
General Comments 0
You need to be logged in to leave comments. Login now