Sheet: Apply clang format

This commit is contained in:
wmayer
2023-09-10 14:24:00 +02:00
committed by wwmayer
parent 50bb81e6fc
commit b5d363baf1
30 changed files with 1947 additions and 1403 deletions

View File

@@ -43,14 +43,16 @@ using namespace Spreadsheet;
using namespace App;
namespace sp = std::placeholders;
SheetModel::SheetModel(Sheet* _sheet, QObject* parent) : QAbstractTableModel(parent), sheet(_sheet)
SheetModel::SheetModel(Sheet* _sheet, QObject* parent)
: QAbstractTableModel(parent)
, sheet(_sheet)
{
//NOLINTBEGIN
// NOLINTBEGIN
cellUpdatedConnection =
sheet->cellUpdated.connect(std::bind(&SheetModel::cellUpdated, this, sp::_1));
rangeUpdatedConnection =
sheet->rangeUpdated.connect(std::bind(&SheetModel::rangeUpdated, this, sp::_1));
//NOLINTEND
// NOLINTEND
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Spreadsheet");
@@ -108,10 +110,11 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
int col = index.column();
const Cell* cell = sheet->getCell(CellAddress(row, col));
if (!cell)
if (!cell) {
cell = emptyCell;
}
//#define DEBUG_DEPS
// #define DEBUG_DEPS
#ifdef DEBUG_DEPS
if (role == Qt::ToolTipRole) {
QString v;
@@ -123,15 +126,17 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (deps.size() > 0) {
v += QString::fromUtf8("Depends on:");
for (std::set<std::string>::const_iterator i = deps.begin(); i != deps.end(); ++i)
for (std::set<std::string>::const_iterator i = deps.begin(); i != deps.end(); ++i) {
v += QString::fromUtf8("\n\t") + Tools::fromStdString(*i);
}
v += QString::fromUtf8("\n");
}
if (provides.size() > 0) {
v += QString::fromUtf8("Used by:");
for (std::set<std::string>::const_iterator i = provides.begin(); i != provides.end();
++i)
++i) {
v += QString::fromUtf8("\n\t") + Tools::fromStdString(*i);
}
v += QString::fromUtf8("\n");
}
return QVariant(v);
@@ -139,8 +144,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
#else
if (!cell->hasException() && role == Qt::ToolTipRole) {
std::string alias;
if (cell->getAlias(alias))
if (cell->getAlias(alias)) {
return QVariant(Base::Tools::fromStdString(alias));
}
}
#endif
@@ -156,8 +162,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
QString::fromUtf8("#ERR: %1").arg(Tools::fromStdString(cell->getException())));
#else
std::string str;
if (cell->getStringContent(str))
if (cell->getStringContent(str)) {
return QVariant::fromValue(QString::fromUtf8(str.c_str()));
}
return QVariant::fromValue(QString::fromUtf8("#ERR"));
#endif
}
@@ -174,8 +181,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (role == Qt::EditRole || role == Qt::StatusTipRole) {
std::string str;
if (cell->getStringContent(str))
if (cell->getStringContent(str)) {
return QVariant(QString::fromUtf8(str.c_str()));
}
return {};
}
@@ -186,9 +194,10 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (role == Qt::BackgroundRole) {
Color color;
if (cell->getBackground(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));
}
else {
std::string alias;
if (cell->getAlias(alias)) {
@@ -203,30 +212,39 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
int alignment;
cell->getAlignment(alignment);
if (alignment & Cell::ALIGNMENT_LEFT)
if (alignment & Cell::ALIGNMENT_LEFT) {
qtAlignment |= Qt::AlignLeft;
if (alignment & Cell::ALIGNMENT_HCENTER)
}
if (alignment & Cell::ALIGNMENT_HCENTER) {
qtAlignment |= Qt::AlignHCenter;
if (alignment & Cell::ALIGNMENT_RIGHT)
}
if (alignment & Cell::ALIGNMENT_RIGHT) {
qtAlignment |= Qt::AlignRight;
if (alignment & Cell::ALIGNMENT_TOP)
}
if (alignment & Cell::ALIGNMENT_TOP) {
qtAlignment |= Qt::AlignTop;
if (alignment & Cell::ALIGNMENT_VCENTER)
}
if (alignment & Cell::ALIGNMENT_VCENTER) {
qtAlignment |= Qt::AlignVCenter;
if (alignment & Cell::ALIGNMENT_BOTTOM)
}
if (alignment & Cell::ALIGNMENT_BOTTOM) {
qtAlignment |= Qt::AlignBottom;
}
std::set<std::string> style;
if (role == Qt::FontRole && cell->getStyle(style)) {
QFont f;
for (const auto& i : style) {
if (i == "bold")
if (i == "bold") {
f.setBold(true);
else if (i == "italic")
}
else if (i == "italic") {
f.setItalic(true);
else if (i == "underline")
}
else if (i == "underline") {
f.setUnderline(true);
}
}
return QVariant::fromValue(f);
@@ -238,7 +256,8 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (!prop || dirty) {
switch (role) {
case Qt::ForegroundRole: {
return QColor(0, 0,
return QColor(0,
0,
255.0);// TODO: Remove this hardcoded color, replace with preference
}
case Qt::TextAlignmentRole: {
@@ -275,11 +294,13 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(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
}
else {
return QVariant(QColor(textFgColor));
}
}
case Qt::DisplayRole: {
QString v = QString::fromUtf8(stringProp->getValue());
@@ -308,14 +329,17 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(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)
if (floatProp->getValue() < 0) {
return QVariant::fromValue(QColor(negativeFgColor));
else
}
else {
return QVariant::fromValue(QColor(positiveFgColor));
}
}
}
case Qt::TextAlignmentRole: {
@@ -338,9 +362,11 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (cell->getDisplayUnit(displayUnit)) {
if (computedUnit.isEmpty() || computedUnit == displayUnit.unit) {
QString number =
QLocale().toString(floatProp->getValue() / displayUnit.scaler, 'f',
QLocale().toString(floatProp->getValue() / displayUnit.scaler,
'f',
Base::UnitsApi::getDecimals());
//QString number = QString::number(floatProp->getValue() / displayUnit.scaler);
// QString number = QString::number(floatProp->getValue() /
// displayUnit.scaler);
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
else {
@@ -366,8 +392,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
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;
l = static_cast<const App::PropertyInteger*>(prop)->getValue();
@@ -378,14 +405,17 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(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)
if (d < 0) {
return QVariant::fromValue(QColor(negativeFgColor));
else
}
else {
return QVariant::fromValue(QColor(positiveFgColor));
}
}
}
case Qt::TextAlignmentRole: {
@@ -405,17 +435,19 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
// Display locale specific decimal separator (#0003875,#0003876)
if (cell->getDisplayUnit(displayUnit)) {
QString number = QLocale().toString(d / displayUnit.scaler, 'f',
QString number = QLocale().toString(d / displayUnit.scaler,
'f',
Base::UnitsApi::getDecimals());
//QString number = QString::number(d / displayUnit.scaler);
// 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);
// v = QString::number(d);
}
else
else {
v = QString::number(l);
}
return formatCellDisplay(v, cell);
}
default:
@@ -429,11 +461,13 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(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
}
else {
return QVariant(QColor(textFgColor));
}
}
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
@@ -478,12 +512,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)
if (orientation == Qt::Horizontal) {
return QVariant(
QSize(sheet->getColumnWidth(section), PropertyRowHeights::defaultHeight));
else
}
else {
return QVariant(
QSize(PropertyColumnWidths::defaultHeaderWidth, sheet->getRowHeight(section)));
}
}
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
@@ -537,12 +573,16 @@ bool SheetModel::setData(const QModelIndex& index, const QVariant& value, int ro
if (cell) {
std::string oldContent;
cell->getStringContent(oldContent);
if (str == QString::fromStdString(oldContent))
if (str == QString::fromStdString(oldContent)) {
return true;
}
}
QMetaObject::invokeMethod(this, "setCellData", Qt::QueuedConnection,
Q_ARG(QModelIndex, index), Q_ARG(QString, str));
QMetaObject::invokeMethod(this,
"setCellData",
Qt::QueuedConnection,
Q_ARG(QModelIndex, index),
Q_ARG(QString, str));
}
return true;
}