Skip to content

Commit 4bc9856

Browse files
committed
Make some GUI improvemments
1 parent 1ad5dc6 commit 4bc9856

File tree

5 files changed

+106
-26
lines changed

5 files changed

+106
-26
lines changed

src/client/gui/dataview/client_dataviewmodel.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
#include "client_dataviewmodel.h"
2424

25+
#include <QBrush>
26+
2527
#include <core.h>
2628
#include <project/client_project.h>
2729
#include <project/client_device.h>
@@ -70,21 +72,44 @@ int mbClientDataViewModel::columnCount(const QModelIndex & /*parent*/) const
7072
QVariant mbClientDataViewModel::data(const QModelIndex &index, int role) const
7173
{
7274
mbClientDataViewItem* d = dataView()->item(index.row());
73-
if (d && ((role == Qt::DisplayRole) || (role == Qt::EditRole)))
75+
if (d)
7476
{
75-
switch(index.column())
77+
if ((role == Qt::DisplayRole) || (role == Qt::EditRole))
7678
{
77-
case Column_Device:
78-
if (mbClientDevice *dev = d->device())
79-
return dev->name();
79+
switch(index.column())
80+
{
81+
case Column_Device:
82+
if (mbClientDevice *dev = d->device())
83+
return dev->name();
84+
break;
85+
case Column_Address : return d->addressStr();
86+
case Column_Format : return d->formatStr();
87+
case Column_Period : return d->period();
88+
case Column_Comment : return d->comment();
89+
case Column_Status : return mb::toString(d->status());
90+
case Column_Timestamp: return mb::toString(d->timestamp());
91+
case Column_Value : return d->value();
92+
}
93+
}
94+
else if (role == Qt::BackgroundRole)
95+
{
96+
switch(index.column())
97+
{
98+
case Column_Status:
99+
{
100+
int status = d->status();
101+
if (status == mb::Status_MbStopped)
102+
return QBrush(QColor(0xF0, 0xF0, 0xF0));
103+
if (status == mb::Status_MbInitializing)
104+
return QBrush(Qt::lightGray);
105+
if (Modbus::StatusIsGood(static_cast<Modbus::StatusCode>(status)))
106+
return QBrush(QColor(0xCC, 0xFF, 0xCC));
107+
if (Modbus::StatusIsBad(static_cast<Modbus::StatusCode>(status)))
108+
return QBrush(QColor(0xFF, 0xCC, 0xCC));
109+
}
80110
break;
81-
case Column_Address : return d->addressStr();
82-
case Column_Format : return d->formatStr();
83-
case Column_Period : return d->period();
84-
case Column_Comment : return d->comment();
85-
case Column_Status : return mb::toString(d->status());
86-
case Column_Timestamp: return mb::toString(d->timestamp());
87-
case Column_Value : return d->value();
111+
}
112+
88113
}
89114
}
90115
return QVariant();

src/core/gui/dataview/core_dataviewui.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ mbCoreDataViewUi::mbCoreDataViewUi(mbCoreDataView *dataView, mbCoreDataViewModel
8484
header = m_view->verticalHeader();
8585
header->setSectionResizeMode(QHeaderView::ResizeToContents);
8686

87+
QString headerStyleSheet = R"(
88+
QHeaderView::section {
89+
background-color: #f0f0f0; /* Light gray background */
90+
color: #2c3e50; /* Dark gray text color */
91+
border: 1px solid #dcdcdc; /* Subtle light gray border around sections */
92+
font-size: 11px; /* Font size */
93+
font-weight: normal; /* Normal text weight for a clean look */
94+
text-align: left; /* Align text to the left */
95+
}
96+
97+
QHeaderView::section:pressed {
98+
background-color: #d0d0d0; /* Darker background when pressed */
99+
border: 1px solid #bcbcbc; /* Darker border when pressed */
100+
}
101+
102+
)";
103+
104+
m_view->setStyleSheet(headerStyleSheet);
105+
87106
connect(dataView, &mbCoreDataView::nameChanged, this, &mbCoreDataViewUi::nameChanged);
88107

89108
QVBoxLayout *layout = new QVBoxLayout(this);

src/server/gui/actions/server_actionsui.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mbServerActionsUi::mbServerActionsUi(QWidget *parent) : QWidget(parent)
4646
header = m_view->verticalHeader();
4747
header->setSectionResizeMode(QHeaderView::ResizeToContents);
4848
m_view->setContextMenuPolicy(Qt::CustomContextMenu);
49+
m_view->setAlternatingRowColors(true);
4950
connect(m_view, &QAbstractItemView::customContextMenuRequested, this, &mbServerActionsUi::customContextMenu);
5051

5152
m_model = new mbServerActionsModel(this);
@@ -56,6 +57,25 @@ mbServerActionsUi::mbServerActionsUi(QWidget *parent) : QWidget(parent)
5657
connect(m_delegate, &mbServerActionsDelegate::contextMenu, this, &mbServerActionsUi::contextMenu);
5758
m_view->setItemDelegate(m_delegate);
5859

60+
QString headerStyleSheet = R"(
61+
QHeaderView::section {
62+
background-color: #f0f0f0; /* Light gray background */
63+
color: #2c3e50; /* Dark gray text color */
64+
border: 1px solid #dcdcdc; /* Subtle light gray border around sections */
65+
font-size: 11px; /* Font size */
66+
font-weight: normal; /* Normal text weight for a clean look */
67+
text-align: left; /* Align text to the left */
68+
}
69+
70+
QHeaderView::section:pressed {
71+
background-color: #d0d0d0; /* Darker background when pressed */
72+
border: 1px solid #bcbcbc; /* Darker border when pressed */
73+
}
74+
75+
)";
76+
77+
m_view->setStyleSheet(headerStyleSheet);
78+
5979
QVBoxLayout *layout = new QVBoxLayout(this);
6080
layout->setMargin(0);
6181
layout->addWidget(m_view);

src/server/gui/device/server_deviceui.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,43 @@ mbServerDeviceUi::mbServerDeviceUi(mbServerDevice *device, QWidget *parent) :
3939

4040
m_timerId = 0;
4141

42+
QTableView *tbl;
43+
4244
m_device = device;
4345
connect(device, &mbServerDevice::nameChanged, this, &mbServerDeviceUi::deviceChanged);
4446
connect(device, &mbServerDevice::changed, this, &mbServerDeviceUi::deviceChanged);
4547
// memory models
4648
m_model_0x = new mbServerDeviceUiModel_0x(m_device, this);
47-
ui->tableView_0x->setModel(m_model_0x);
48-
ui->tableView_0x->setItemDelegate(new mbServerDeviceUiDelegateBool(this));
49-
ui->tableView_0x->setSelectionMode(QAbstractItemView::ContiguousSelection);
49+
tbl = ui->tableView_0x;
50+
tbl->setModel(m_model_0x);
51+
tbl->setItemDelegate(new mbServerDeviceUiDelegateBool(this));
52+
tbl->setSelectionMode(QAbstractItemView::ContiguousSelection);
53+
tbl->setAlternatingRowColors(true);
54+
tbl->setStyleSheet("QHeaderView::section { background-color:lightgray }");
5055

5156
m_model_1x = new mbServerDeviceUiModel_1x(m_device, this);
52-
ui->tableView_1x->setModel(m_model_1x);
53-
ui->tableView_1x->setItemDelegate(new mbServerDeviceUiDelegateBool(this));
54-
ui->tableView_1x->setSelectionMode(QAbstractItemView::ContiguousSelection);
57+
tbl = ui->tableView_1x;
58+
tbl->setModel(m_model_1x);
59+
tbl->setItemDelegate(new mbServerDeviceUiDelegateBool(this));
60+
tbl->setSelectionMode(QAbstractItemView::ContiguousSelection);
61+
tbl->setAlternatingRowColors(true);
62+
tbl->setStyleSheet("QHeaderView::section { background-color:lightgray }");
5563

5664
m_model_3x = new mbServerDeviceUiModel_3x(m_device, this);
57-
ui->tableView_3x->setModel(m_model_3x);
58-
ui->tableView_3x->setItemDelegate(new mbServerDeviceUiDelegate(this));
59-
ui->tableView_3x->setSelectionMode(QAbstractItemView::ContiguousSelection);
65+
tbl = ui->tableView_3x;
66+
tbl->setModel(m_model_3x);
67+
tbl->setItemDelegate(new mbServerDeviceUiDelegate(this));
68+
tbl->setSelectionMode(QAbstractItemView::ContiguousSelection);
69+
tbl->setAlternatingRowColors(true);
70+
tbl->setStyleSheet("QHeaderView::section { background-color:lightgray }");
6071

6172
m_model_4x = new mbServerDeviceUiModel_4x(m_device, this);
62-
ui->tableView_4x->setModel(m_model_4x);
63-
ui->tableView_4x->setItemDelegate(new mbServerDeviceUiDelegate(this));
64-
ui->tableView_4x->setSelectionMode(QAbstractItemView::ContiguousSelection);
73+
tbl = ui->tableView_4x;
74+
tbl->setModel(m_model_4x);
75+
tbl->setItemDelegate(new mbServerDeviceUiDelegate(this));
76+
tbl->setSelectionMode(QAbstractItemView::ContiguousSelection);
77+
tbl->setAlternatingRowColors(true);
78+
tbl->setStyleSheet("QHeaderView::section { background-color:lightgray }");
6579

6680
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &mbServerDeviceUi::tabChanged);
6781
}

src/server/gui/device/server_deviceuimodel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ QVariant mbServerDeviceUiModel_0x::data(const QModelIndex &index, int role) cons
146146
{
147147
int offset = index.row()*ColumnCount+index.column();
148148
if (offset < m_device->count_0x())
149-
return m_device->bool_0x(static_cast<quint16>(offset)) ? QBrush(Qt::gray) : QBrush(Qt::white);
149+
if (m_device->bool_0x(static_cast<quint16>(offset)))
150+
return QBrush(Qt::gray);
150151
}
151152
break;
152153
}
@@ -213,7 +214,8 @@ QVariant mbServerDeviceUiModel_1x::data(const QModelIndex &index, int role) cons
213214
{
214215
int offset = index.row()*ColumnCount+index.column();
215216
if (offset < m_device->count_1x())
216-
return m_device->bool_1x(static_cast<quint16>(offset)) ? QBrush(Qt::gray) : QBrush(Qt::white);
217+
if (m_device->bool_1x(static_cast<quint16>(offset)))
218+
return QBrush(Qt::gray);
217219
}
218220
break;
219221
}

0 commit comments

Comments
 (0)