Mantid
Loading...
Searching...
No Matches
CellStandardItem.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10void applyCellPropertiesToItem(Cell const &cell, QStandardItem &item) {
11 item.setText(QString::fromStdString(cell.contentText()));
12 item.setEditable(cell.isEditable());
13 item.setToolTip(QString::fromStdString(cell.toolTip()));
16 setBorderColor(item, cell.borderColor(), cell.borderOpacity());
17 setIcon(item, cell.iconFilePath());
19}
20
21Cell extractCellPropertiesFromItem(QStandardItem const &item) {
22 auto cell = Cell(item.text().toStdString());
23 cell.setBorderThickness(getBorderThickness(item));
24 cell.setIconFilePath(getIconFilePath(item));
25 cell.setBackgroundColor(getBackgroundColor(item));
26 cell.setForegroundColor(getForegroundColor(item));
27
28 auto borderColor = getBorderColor(item);
29 cell.setBorderColor(borderColor.name().toStdString());
30 cell.setBorderOpacity(borderColor.alpha());
31
32 cell.setEditable(item.isEditable());
33 cell.setToolTip(item.toolTip().toStdString());
34 return cell;
35}
36
37void setBorderThickness(QStandardItem &item, int borderThickness) {
38 item.setData(borderThickness, CellUserRoles::BorderThickness);
39}
40
41int getBorderThickness(QStandardItem const &item) { return item.data(CellUserRoles::BorderThickness).toInt(); }
42
43std::string getIconFilePath(QStandardItem const &item) {
44 return item.data(CellUserRoles::IconFilePath).toString().toStdString();
45}
46
47void setIconFilePath(QStandardItem &item, QString const &iconFilePath) {
48 item.setData(iconFilePath, CellUserRoles::IconFilePath);
49}
50
51void setIcon(QStandardItem &item, std::string const &iconFilePath) {
52 auto qiconFilePath = QString::fromStdString(iconFilePath);
53 setIconFilePath(item, qiconFilePath);
54 if (!qiconFilePath.isEmpty())
55 item.setIcon(QIcon(qiconFilePath));
56 else
57 item.setIcon(QIcon());
58}
59
60void setBorderColor(QStandardItem &item, std::string const &borderColor, int alpha) {
61 auto borderQColor = QColor(borderColor.c_str());
62 borderQColor.setAlpha(alpha);
63 item.setData(borderQColor, CellUserRoles::BorderColor);
64}
65
66void setBackgroundColor(QStandardItem &item, std::string const &backgroundColor) {
67 auto borderColor = QColor(backgroundColor.c_str());
68 item.setData(QBrush(borderColor), Qt::BackgroundRole);
69}
70
71std::string getBackgroundColor(QStandardItem const &item) {
72 return item.data(Qt::BackgroundRole).value<QBrush>().color().name().toStdString();
73}
74
75void setForegroundColor(QStandardItem &item, std::string const &foregroundColor) {
76 auto borderColor = QColor(foregroundColor.c_str());
77 item.setData(QBrush(borderColor), Qt::ForegroundRole);
78}
79
80std::string getForegroundColor(QStandardItem const &item) {
81 return item.data(Qt::ForegroundRole).value<QBrush>().color().name().toStdString();
82}
83
84QColor getBorderColor(QStandardItem const &item) { return item.data(CellUserRoles::BorderColor).value<QColor>(); }
85} // namespace MantidQt::MantidWidgets::Batch
std::string const & backgroundColor() const
Definition: Cell.cpp:53
std::string const & borderColor() const
Definition: Cell.cpp:31
std::string const & foregroundColor() const
Definition: Cell.cpp:55
std::string const & iconFilePath() const
Definition: Cell.cpp:61
std::string const & toolTip() const
Definition: Cell.cpp:25
std::string const & contentText() const
Definition: Cell.cpp:23
void applyCellPropertiesToItem(Cell const &cell, QStandardItem &item)
void setIconFilePath(QStandardItem &item, QString const &iconFilePath)
void setForegroundColor(QStandardItem &item, std::string const &foregroundColor)
void setBackgroundColor(QStandardItem &item, std::string const &backgroundColor)
std::string getBackgroundColor(QStandardItem const &item)
Cell extractCellPropertiesFromItem(QStandardItem const &item)
QColor getBorderColor(QStandardItem const &item)
std::string getForegroundColor(QStandardItem const &item)
std::string getIconFilePath(QStandardItem const &item)
int getBorderThickness(QStandardItem const &item)
void setBorderColor(QStandardItem &item, std::string const &borderColor, int alpha)
void setBorderThickness(QStandardItem &item, int borderThickness)
void setIcon(QStandardItem &item, std::string const &iconFilePath)