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

@@ -25,16 +25,16 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QLineEdit>
# include <QPainter>
#include <QLineEdit>
#include <QPainter>
#endif
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Mod/Spreadsheet/App/Sheet.h>
#include "SpreadsheetDelegate.h"
#include "LineEdit.h"
#include "SpreadsheetDelegate.h"
FC_LOG_LEVEL_INIT("Spreadsheet", true, true)
@@ -42,43 +42,45 @@ FC_LOG_LEVEL_INIT("Spreadsheet", true, true)
using namespace Spreadsheet;
using namespace SpreadsheetGui;
SpreadsheetDelegate::SpreadsheetDelegate(Spreadsheet::Sheet * _sheet, QWidget *parent)
SpreadsheetDelegate::SpreadsheetDelegate(Spreadsheet::Sheet* _sheet, QWidget* parent)
: QStyledItemDelegate(parent)
, sheet(_sheet)
{
}
{}
QWidget *SpreadsheetDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex &index) const
QWidget* SpreadsheetDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem&,
const QModelIndex& index) const
{
App::CellAddress addr(index.row(),index.column());
App::Range range(addr,addr);
if(sheet && sheet->getCellBinding(range)) {
App::CellAddress addr(index.row(), index.column());
App::Range range(addr, addr);
if (sheet && sheet->getCellBinding(range)) {
FC_ERR("Bound cell " << addr.toString() << " cannot be edited");
return nullptr;
}
SpreadsheetGui::LineEdit *editor = new SpreadsheetGui::LineEdit(parent);
SpreadsheetGui::LineEdit* editor = new SpreadsheetGui::LineEdit(parent);
editor->setDocumentObject(sheet);
connect(editor, &SpreadsheetGui::LineEdit::finishedWithKey, this, &SpreadsheetDelegate::onEditorFinishedWithKey);
connect(editor,
&SpreadsheetGui::LineEdit::finishedWithKey,
this,
&SpreadsheetDelegate::onEditorFinishedWithKey);
return editor;
}
void SpreadsheetDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
void SpreadsheetDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
QLineEdit* edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
edit->setText(index.model()->data(index, Qt::EditRole).toString());
return;
}
}
void SpreadsheetDelegate::setModelData(QWidget *editor,
QAbstractItemModel *model, const QModelIndex &index) const
void SpreadsheetDelegate::setModelData(QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index) const
{
QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
QLineEdit* edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
model->setData(index, edit->text());
return;
@@ -90,49 +92,59 @@ void SpreadsheetDelegate::onEditorFinishedWithKey(int key, Qt::KeyboardModifiers
Q_EMIT finishedWithKey(key, modifiers);
}
QSize SpreadsheetDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
QSize SpreadsheetDelegate::sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
return {};
}
static inline void drawBorder(QPainter *painter, const QStyleOptionViewItem &option,
unsigned flags, QColor color, Qt::PenStyle style)
static inline void drawBorder(QPainter* painter,
const QStyleOptionViewItem& option,
unsigned flags,
QColor color,
Qt::PenStyle style)
{
if(!flags)
if (!flags) {
return;
}
QPen pen(color);
pen.setWidth(2);
pen.setStyle(style);
painter->setPen(pen);
QRect rect = option.rect.adjusted(1,1,0,0);
if(flags == Sheet::BorderAll) {
painter->drawRect(rect.adjusted(0,0,-1,-1));
QRect rect = option.rect.adjusted(1, 1, 0, 0);
if (flags == Sheet::BorderAll) {
painter->drawRect(rect.adjusted(0, 0, -1, -1));
return;
}
if(flags & Sheet::BorderLeft)
if (flags & Sheet::BorderLeft) {
painter->drawLine(rect.topLeft(), rect.bottomLeft());
if(flags & Sheet::BorderTop)
}
if (flags & Sheet::BorderTop) {
painter->drawLine(rect.topLeft(), rect.topRight());
if(flags & Sheet::BorderRight)
}
if (flags & Sheet::BorderRight) {
painter->drawLine(rect.topRight(), rect.bottomRight());
if(flags & Sheet::BorderBottom)
}
if (flags & Sheet::BorderBottom) {
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
}
}
void SpreadsheetDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index ) const
void SpreadsheetDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QStyledItemDelegate::paint(painter, option, index);
if(!sheet)
if (!sheet) {
return;
}
App::CellAddress addr(index.row(), index.column());
drawBorder(painter, option, sheet->getCellBindingBorder(addr), Qt::blue, Qt::SolidLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr,true), Qt::green, Qt::DashLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr,false), Qt::red, Qt::DashLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr, true), Qt::green, Qt::DashLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr, false), Qt::red, Qt::DashLine);
}
#include "moc_SpreadsheetDelegate.cpp"