SpreadSheet: Display alias

Add an option to display in the cell the alias of the cell.
In preference, add a custom field to format this display.
This commit is contained in:
ShuffleWire
2022-11-28 16:45:59 +01:00
committed by Chris Hennes
parent 707b7efeda
commit c4ef31c2ed
3 changed files with 320 additions and 211 deletions

View File

@@ -20,6 +20,64 @@
<string>Spreadsheet</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox1">
<property name="title">
<string>Display Settings</string>
</property>
<layout class="QHBoxLayout" name="gridLayout1">
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxShowAlias">
<property name="toolTip">
<string>If checked, use the custom presentation to display cell string.</string>
</property>
<property name="text">
<string>Show alias in cell with format</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>showAliasName</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Spreadsheet</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="Gui::PrefLineEdit" name="formatString">
<property name="text">
<string notr="true">%V = %A</string>
</property>
<property name="toolTip">
<string>The format of the custom cell string presentation.
Defaults to: %V = %A
%A - alias name
%V - cell value</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>DisplayAliasFormatString</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Spreadsheet</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
@@ -150,7 +208,7 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -177,6 +235,11 @@
<extends>QLineEdit</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@@ -59,6 +59,8 @@ void DlgSettingsImp::saveSettings()
hGrp->SetASCII("ImportExportDelimiter", delimiter.toStdString().c_str());
ui->quoteCharLineEdit->onSave();
ui->escapeCharLineEdit->onSave();
ui->formatString->onSave();
ui->checkBoxShowAlias->onSave();
}
void DlgSettingsImp::loadSettings()
@@ -89,6 +91,8 @@ void DlgSettingsImp::loadSettings()
ui->quoteCharLineEdit->onRestore();
ui->escapeCharLineEdit->onRestore();
ui->formatString->onRestore();
ui->checkBoxShowAlias->onRestore();
}
/**

View File

@@ -23,8 +23,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QFont>
# include <QLocale>
#include <QFont>
#include <QLocale>
#endif
#include <App/Document.h>
@@ -43,18 +43,22 @@ using namespace Spreadsheet;
using namespace App;
namespace bp = boost::placeholders;
SheetModel::SheetModel(Sheet *_sheet, QObject *parent)
: QAbstractTableModel(parent)
, sheet(_sheet)
SheetModel::SheetModel(Sheet* _sheet, QObject* parent) : QAbstractTableModel(parent), sheet(_sheet)
{
cellUpdatedConnection = sheet->cellUpdated.connect(bind(&SheetModel::cellUpdated, this, bp::_1));
rangeUpdatedConnection = sheet->rangeUpdated.connect(bind(&SheetModel::rangeUpdated, this, bp::_1));
cellUpdatedConnection =
sheet->cellUpdated.connect(bind(&SheetModel::cellUpdated, this, bp::_1));
rangeUpdatedConnection =
sheet->rangeUpdated.connect(bind(&SheetModel::rangeUpdated, this, bp::_1));
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Spreadsheet");
aliasBgColor = QColor(Base::Tools::fromStdString(hGrp->GetASCII("AliasedCellBackgroundColor", "#feff9e")));
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Spreadsheet");
aliasBgColor =
QColor(Base::Tools::fromStdString(hGrp->GetASCII("AliasedCellBackgroundColor", "#feff9e")));
textFgColor = QColor(Base::Tools::fromStdString(hGrp->GetASCII("TextColor", "#000000")));
positiveFgColor = QColor(Base::Tools::fromStdString(hGrp->GetASCII("PositiveNumberColor", "#000000")));
negativeFgColor = QColor(Base::Tools::fromStdString(hGrp->GetASCII("NegativeNumberColor", "#000000")));
positiveFgColor =
QColor(Base::Tools::fromStdString(hGrp->GetASCII("PositiveNumberColor", "#000000")));
negativeFgColor =
QColor(Base::Tools::fromStdString(hGrp->GetASCII("NegativeNumberColor", "#000000")));
}
SheetModel::~SheetModel()
@@ -63,25 +67,44 @@ SheetModel::~SheetModel()
rangeUpdatedConnection.disconnect();
}
int SheetModel::rowCount(const QModelIndex &parent) const
int SheetModel::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
return 16384;
}
int SheetModel::columnCount(const QModelIndex &parent) const
int SheetModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
return 26 * 26 + 26;
}
QVariant SheetModel::data(const QModelIndex &index, int role) const
namespace
{
static const Cell * emptyCell = new Cell(CellAddress(0, 0), nullptr);
QVariant formatCellDisplay(QString value, const Cell* cell)
{
std::string alias;
static auto hGrpSpreadsheet =
App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/Mod/Spreadsheet");
if (cell->getAlias(alias) && hGrpSpreadsheet->GetBool("showAliasName", false)) {
QString formatStr = QString::fromStdString(
hGrpSpreadsheet->GetASCII("DisplayAliasFormatString", "%V = %A"));
if (formatStr.contains(QLatin1String("%V")) || formatStr.contains(QLatin1String("%A"))) {
formatStr.replace(QLatin1String("%A"), QString::fromStdString(alias));
formatStr.replace(QLatin1String("%V"), value);
return QVariant(formatStr);
}
}
return QVariant(value);
}
}// namespace
QVariant SheetModel::data(const QModelIndex& index, int role) const
{
static const Cell* emptyCell = new Cell(CellAddress(0, 0), nullptr);
int row = index.row();
int col = index.column();
const Cell * cell = sheet->getCell(CellAddress(row, col));
const Cell* cell = sheet->getCell(CellAddress(row, col));
if (!cell)
cell = emptyCell;
@@ -104,7 +127,8 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
}
if (provides.size() > 0) {
v += QString::fromUtf8("Used by:");
for (std::set<std::string>::const_iterator i = provides.begin(); i != provides.end(); ++i)
for (std::set<std::string>::const_iterator i = provides.begin(); i != provides.end();
++i)
v += QString::fromUtf8("\n\t") + Tools::fromStdString(*i);
v += QString::fromUtf8("\n");
}
@@ -120,26 +144,27 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
if (cell->hasException()) {
switch (role) {
case Qt::ToolTipRole: {
QString txt(Base::Tools::fromStdString(cell->getException()).toHtmlEscaped());
return QVariant(QString::fromLatin1("<pre>%1</pre>").arg(txt));
}
case Qt::DisplayRole: {
case Qt::ToolTipRole: {
QString txt(Base::Tools::fromStdString(cell->getException()).toHtmlEscaped());
return QVariant(QString::fromLatin1("<pre>%1</pre>").arg(txt));
}
case Qt::DisplayRole: {
#ifdef DEBUG_DEPS
return QVariant::fromValue(QString::fromUtf8("#ERR: %1").arg(Tools::fromStdString(cell->getException())));
return QVariant::fromValue(
QString::fromUtf8("#ERR: %1").arg(Tools::fromStdString(cell->getException())));
#else
std::string str;
if(cell->getStringContent(str))
return QVariant::fromValue(QString::fromUtf8(str.c_str()));
return QVariant::fromValue(QString::fromUtf8("#ERR"));
std::string str;
if (cell->getStringContent(str))
return QVariant::fromValue(QString::fromUtf8(str.c_str()));
return QVariant::fromValue(QString::fromUtf8("#ERR"));
#endif
}
case Qt::ForegroundRole:
return QVariant::fromValue(QColor(255.0, 0, 0));
case Qt::TextAlignmentRole:
return QVariant(Qt::AlignVCenter | Qt::AlignLeft);
default:
break;
}
case Qt::ForegroundRole:
return QVariant::fromValue(QColor(255.0, 0, 0));
case Qt::TextAlignmentRole:
return QVariant(Qt::AlignVCenter | Qt::AlignLeft);
default:
break;
}
}
@@ -155,13 +180,14 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
// Get display value as computed property
std::string address = CellAddress(row, col).toString();
Property * prop = sheet->getPropertyByName(address.c_str());
Property* prop = sheet->getPropertyByName(address.c_str());
if (role == Qt::BackgroundRole) {
Color color;
if (cell->getBackground(color))
return QVariant::fromValue(QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else {
std::string alias;
if (cell->getAlias(alias)) {
@@ -207,134 +233,140 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
}
auto dirtyCells = sheet->getCells()->getDirty();
auto dirty = (dirtyCells.find(CellAddress(row,col)) != dirtyCells.end());
auto dirty = (dirtyCells.find(CellAddress(row, col)) != dirtyCells.end());
if (!prop || dirty) {
switch (role) {
case Qt::ForegroundRole: {
return QColor(0, 0, 255.0); // TODO: Remove this hardcoded color, replace with preference
}
case Qt::TextAlignmentRole: {
qtAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
return QVariant::fromValue(qtAlignment);
}
case Qt::DisplayRole:
if(cell->getExpression()) {
std::string str;
if (cell->getStringContent(str))
if (!str.empty() && str[0] == '=')
// If this is a real computed value, indicate that a recompute is
// needed before we can display it
return QVariant(QLatin1String("#PENDING"));
case Qt::ForegroundRole: {
return QColor(0, 0,
255.0);// TODO: Remove this hardcoded color, replace with preference
}
case Qt::TextAlignmentRole: {
qtAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
return QVariant::fromValue(qtAlignment);
}
case Qt::DisplayRole:
if (cell->getExpression()) {
std::string str;
if (cell->getStringContent(str))
if (!str.empty() && str[0] == '=')
// If this is a real computed value, indicate that a recompute is
// needed before we can display it
return QVariant(QLatin1String("#PENDING"));
else
// If it's just a simple value, display the new value, but still
// format it as a pending value to indicate to the user that
// a recompute is needed
return QVariant(QString::fromUtf8(str.c_str()));
else
// If it's just a simple value, display the new value, but still
// format it as a pending value to indicate to the user that
// a recompute is needed
return QVariant(QString::fromUtf8(str.c_str()));
return QVariant();
}
else
return QVariant();
}
else
default:
return QVariant();
default:
return QVariant();
}
} else if (prop->isDerivedFrom(App::PropertyString::getClassTypeId())) {
}
else if (prop->isDerivedFrom(App::PropertyString::getClassTypeId())) {
/* String */
const App::PropertyString * stringProp = static_cast<const App::PropertyString*>(prop);
const App::PropertyString* stringProp = static_cast<const App::PropertyString*>(prop);
switch (role) {
case Qt::ForegroundRole: {
Color color;
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
return QVariant::fromValue(QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else
return QVariant(QColor(textFgColor));
}
case Qt::DisplayRole:
return QVariant(QString::fromUtf8(stringProp->getValue()));
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignLeft;
if (cell->getForeground(color))
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else
return QVariant(QColor(textFgColor));
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
case Qt::DisplayRole: {
QString v = QString::fromUtf8(stringProp->getValue());
return formatCellDisplay(v, cell);
}
return QVariant::fromValue(qtAlignment);
}
default:
return QVariant();
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignLeft;
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
}
return QVariant::fromValue(qtAlignment);
}
default:
return QVariant();
}
}
else if (prop->isDerivedFrom(App::PropertyQuantity::getClassTypeId())) {
/* Number */
const App::PropertyQuantity * floatProp = static_cast<const App::PropertyQuantity*>(prop);
const App::PropertyQuantity* floatProp = static_cast<const App::PropertyQuantity*>(prop);
switch (role) {
case Qt::ForegroundRole: {
Color color;
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
return QVariant::fromValue(QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else {
if (floatProp->getValue() < 0)
return QVariant::fromValue(QColor(negativeFgColor));
else
return QVariant::fromValue(QColor(positiveFgColor));
if (cell->getForeground(color))
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else {
if (floatProp->getValue() < 0)
return QVariant::fromValue(QColor(negativeFgColor));
else
return QVariant::fromValue(QColor(positiveFgColor));
}
}
}
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignRight;
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignRight;
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
}
return QVariant::fromValue(qtAlignment);
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
}
return QVariant::fromValue(qtAlignment);
}
case Qt::DisplayRole: {
QString v;
const Base::Unit & computedUnit = floatProp->getUnit();
DisplayUnit displayUnit;
case Qt::DisplayRole: {
QString v;
const Base::Unit& computedUnit = floatProp->getUnit();
DisplayUnit displayUnit;
// Display locale specific decimal separator (#0003875,#0003876)
if (cell->getDisplayUnit(displayUnit)) {
if (computedUnit.isEmpty() || computedUnit == displayUnit.unit) {
QString number = QLocale().toString(floatProp->getValue() / displayUnit.scaler,'f',Base::UnitsApi::getDecimals());
//QString number = QString::number(floatProp->getValue() / displayUnit.scaler);
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
// Display locale specific decimal separator (#0003875,#0003876)
if (cell->getDisplayUnit(displayUnit)) {
if (computedUnit.isEmpty() || computedUnit == displayUnit.unit) {
QString number =
QLocale().toString(floatProp->getValue() / displayUnit.scaler, 'f',
Base::UnitsApi::getDecimals());
//QString number = QString::number(floatProp->getValue() / displayUnit.scaler);
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
else {
v = QString::fromUtf8("#ERR: unit");
}
}
else {
v = QString::fromUtf8("#ERR: unit");
// When displaying a quantity then use the globally set scheme
// See: https://forum.freecadweb.org/viewtopic.php?f=3&t=50078
Base::Quantity value = floatProp->getQuantityValue();
v = value.getUserString();
}
return formatCellDisplay(v, cell);
}
else {
// When displaying a quantity then use the globally set scheme
// See: https://forum.freecadweb.org/viewtopic.php?f=3&t=50078
Base::Quantity value = floatProp->getQuantityValue();
v = value.getUserString();
}
return QVariant(v);
}
default:
return QVariant();
default:
return QVariant();
}
}
else if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId())
|| prop->isDerivedFrom(App::PropertyInteger::getClassTypeId()))
{
|| prop->isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
/* Number */
double d;
long l;
bool isInteger = false;
if(prop->isDerivedFrom(App::PropertyFloat::getClassTypeId()))
if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId()))
d = static_cast<const App::PropertyFloat*>(prop)->getValue();
else {
isInteger = true;
@@ -343,92 +375,100 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
}
switch (role) {
case Qt::ForegroundRole: {
Color color;
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
return QVariant::fromValue(QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else {
if (d < 0)
return QVariant::fromValue(QColor(negativeFgColor));
if (cell->getForeground(color))
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else {
if (d < 0)
return QVariant::fromValue(QColor(negativeFgColor));
else
return QVariant::fromValue(QColor(positiveFgColor));
}
}
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignRight;
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
}
return QVariant::fromValue(qtAlignment);
}
case Qt::DisplayRole: {
QString v;
DisplayUnit displayUnit;
// Display locale specific decimal separator (#0003875,#0003876)
if (cell->getDisplayUnit(displayUnit)) {
QString number = QLocale().toString(d / displayUnit.scaler, 'f',
Base::UnitsApi::getDecimals());
//QString number = QString::number(d / displayUnit.scaler);
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
else if (!isInteger) {
v = QLocale::system().toString(d, 'f', Base::UnitsApi::getDecimals());
//v = QString::number(d);
}
else
return QVariant::fromValue(QColor(positiveFgColor));
v = QString::number(l);
return formatCellDisplay(v, cell);
}
}
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignRight;
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
}
return QVariant::fromValue(qtAlignment);
}
case Qt::DisplayRole: {
QString v;
DisplayUnit displayUnit;
// Display locale specific decimal separator (#0003875,#0003876)
if (cell->getDisplayUnit(displayUnit)) {
QString number = QLocale().toString(d / displayUnit.scaler,'f',Base::UnitsApi::getDecimals());
//QString number = QString::number(d / displayUnit.scaler);
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
else if (!isInteger) {
v = QLocale::system().toString(d,'f',Base::UnitsApi::getDecimals());
//v = QString::number(d);
} else
v = QString::number(l);
return QVariant(v);
}
default:
return QVariant();
default:
return QVariant();
}
}
else if (prop->isDerivedFrom(App::PropertyPythonObject::getClassTypeId())) {
auto pyProp = static_cast<const App::PropertyPythonObject*>(prop);
switch (role) {
case Qt::ForegroundRole: {
Color color;
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
return QVariant::fromValue(QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else
return QVariant(QColor(textFgColor));
}
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignHCenter;
if (cell->getForeground(color))
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else
return QVariant(QColor(textFgColor));
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
qtAlignment &= ~(Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight);
qtAlignment |= Qt::AlignHCenter;
}
if (alignment & Cell::ALIGNMENT_VIMPLIED) {
qtAlignment &= ~(Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom);
qtAlignment |= Qt::AlignVCenter;
}
return QVariant::fromValue(qtAlignment);
}
return QVariant::fromValue(qtAlignment);
}
case Qt::DisplayRole: {
Base::PyGILStateLocker lock;
std::string value;
try {
value = pyProp->getValue().as_string();
} catch (Py::Exception &) {
Base::PyException e;
value = "#ERR: ";
value += e.what();
} catch (Base::Exception &e) {
value = "#ERR: ";
value += e.what();
} catch (...) {
value = "#ERR: unknown exception";
case Qt::DisplayRole: {
Base::PyGILStateLocker lock;
std::string value;
try {
value = pyProp->getValue().as_string();
}
catch (Py::Exception&) {
Base::PyException e;
value = "#ERR: ";
value += e.what();
}
catch (Base::Exception& e) {
value = "#ERR: ";
value += e.what();
}
catch (...) {
value = "#ERR: unknown exception";
}
QString v = QString::fromUtf8(value.c_str());
return formatCellDisplay(v, cell);
}
return QVariant(QString::fromUtf8(value.c_str()));
}
default:
return QVariant();
default:
return QVariant();
}
}
@@ -436,12 +476,14 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
}
QVariant SheetModel::headerData(int section, Qt::Orientation orientation, int role) const
{
{
if (role == Qt::SizeHintRole) {
if (orientation == Qt::Horizontal)
return QVariant(QSize(sheet->getColumnWidth(section), PropertyRowHeights::defaultHeight));
return QVariant(
QSize(sheet->getColumnWidth(section), PropertyRowHeights::defaultHeight));
else
return QVariant(QSize(PropertyColumnWidths::defaultHeaderWidth, sheet->getRowHeight(section)));
return QVariant(
QSize(PropertyColumnWidths::defaultHeaderWidth, sheet->getRowHeight(section)));
}
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
@@ -480,7 +522,7 @@ void SheetModel::setCellData(QModelIndex index, QString str)
}
}
bool SheetModel::setData(const QModelIndex & index, const QVariant & value, int role)
bool SheetModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
if (role == Qt::DisplayRole) {
// Nothing to do, it will get updated by the sheet in the application logic
@@ -505,9 +547,9 @@ bool SheetModel::setData(const QModelIndex & index, const QVariant & value, int
return true;
}
Qt::ItemFlags SheetModel::flags(const QModelIndex & /*index*/) const
Qt::ItemFlags SheetModel::flags(const QModelIndex& /*index*/) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
}
void SheetModel::cellUpdated(CellAddress address)
@@ -517,7 +559,7 @@ void SheetModel::cellUpdated(CellAddress address)
Q_EMIT dataChanged(i, i);
}
void SheetModel::rangeUpdated(const Range &range)
void SheetModel::rangeUpdated(const Range& range)
{
QModelIndex i = index(range.from().row(), range.from().col());
QModelIndex j = index(range.to().row(), range.to().col());