Improve code style

This commit is contained in:
Simon De Backer 2020-08-16 14:25:31 +02:00
parent 6c806d151d
commit e55d336dc1
9 changed files with 85 additions and 56 deletions

View File

@ -54,7 +54,7 @@ class ElementItemEditor : public QWidget
virtual bool setParts(QList <CustomElementPart *>) {return false;} virtual bool setParts(QList <CustomElementPart *>) {return false;}
virtual CustomElementPart *currentPart() const = 0; virtual CustomElementPart *currentPart() const = 0;
virtual QList<CustomElementPart*> currentParts() const = 0; virtual QList<CustomElementPart*> currentParts() const = 0;
virtual void updateForm() = 0; virtual void updateForm() = 0;
// attributes // attributes

View File

@ -114,14 +114,14 @@ void ElementView::zoomOut() {
Agrandit le schema avec le trackpad Agrandit le schema avec le trackpad
*/ */
void ElementView::zoomInSlowly() { void ElementView::zoomInSlowly() {
scale(1.02, 1.02); scale(1.02, 1.02);
} }
/** /**
Retrecit le schema avec le trackpad Retrecit le schema avec le trackpad
*/ */
void ElementView::zoomOutSlowly() { void ElementView::zoomOutSlowly() {
scale(0.98, 0.98); scale(0.98, 0.98);
} }
/** /**

View File

@ -93,8 +93,8 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar
QVariant property (const char *name) const override {return QObject::property(name);} QVariant property (const char *name) const override {return QObject::property(name);}
virtual QPainterPath shadowShape ()const = 0; virtual QPainterPath shadowShape ()const = 0;
virtual void setHandlerColor(QPointF /*pos*/, const QColor &/*color*/) {} virtual void setHandlerColor(QPointF /*pos*/, const QColor &/*color*/) {}
virtual void resetAllHandlerColor() {} virtual void resetAllHandlerColor() {}
protected: protected:
void stylesToXml (QDomElement &) const; void stylesToXml (QDomElement &) const;
@ -119,7 +119,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar
Filling _filling ; Filling _filling ;
Color _color; Color _color;
bool _antialiased; bool _antialiased;
QPointF m_origin_pos; QPointF m_origin_pos;
}; };
typedef CustomElementGraphicPart CEGP; typedef CustomElementGraphicPart CEGP;

View File

@ -254,7 +254,7 @@ void PartPolygon::setClosed(bool close)
if (m_closed == close) return; if (m_closed == close) return;
prepareGeometryChange(); prepareGeometryChange();
m_closed = close; m_closed = close;
emit closedChange(); emit closedChange();
} }
/** /**
@ -544,7 +544,7 @@ void PartPolygon::removePoint()
if (index > -1 && index<m_handler_vector.count()) if (index > -1 && index<m_handler_vector.count())
{ {
QPolygonF polygon = this->polygon(); QPolygonF polygon = this->polygon();
qDebug() << index; qDebug() << index;
polygon.removeAt(index); polygon.removeAt(index);
//Wrap the undo for avoid to merge the undo commands when user add several points. //Wrap the undo for avoid to merge the undo commands when user add several points.

View File

@ -84,8 +84,8 @@ class PartPolygon : public CustomElementGraphicPart
bool isClosed () const {return m_closed;} bool isClosed () const {return m_closed;}
void setClosed (bool close); void setClosed (bool close);
void setHandlerColor(QPointF pos, const QColor &color) final; void setHandlerColor(QPointF pos, const QColor &color) final;
void resetAllHandlerColor() final; void resetAllHandlerColor() final;
protected: protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;

View File

@ -25,7 +25,7 @@
@param scene La scene sur laquelle figure cette borne @param scene La scene sur laquelle figure cette borne
*/ */
PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) : PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
CustomElementGraphicPart(editor, parent) CustomElementGraphicPart(editor, parent)
{ {
d = new TerminalData(this); d = new TerminalData(this);
d -> m_orientation = Qet::North; d -> m_orientation = Qet::North;

View File

@ -490,7 +490,7 @@ bool StyleEditor::setPart(CustomElementPart *new_part) {
if (CustomElementGraphicPart *part_graphic = dynamic_cast<CustomElementGraphicPart *>(new_part)) if (CustomElementGraphicPart *part_graphic = dynamic_cast<CustomElementGraphicPart *>(new_part))
{ {
part = part_graphic; part = part_graphic;
m_cep_list.append(part_graphic); m_cep_list.append(part_graphic);
updateForm(); updateForm();
return(true); return(true);
} }
@ -541,13 +541,14 @@ CustomElementPart *StyleEditor::currentPart() const {
} }
QList<CustomElementPart*> StyleEditor::currentParts() const { QList<CustomElementPart*> StyleEditor::currentParts() const {
return m_cep_list; return m_cep_list;
} }
/** /**
@brief StyleEditor::isStyleEditable @brief StyleEditor::isStyleEditable
@param cep_list @param cep_list
@return true if all of the content of cep_list can be edited by style editor, else return false. @return true if all of the content of cep_list
can be edited by style editor, else return false.
*/ */
bool StyleEditor::isStyleEditable(QList<CustomElementPart *> cep_list) bool StyleEditor::isStyleEditable(QList<CustomElementPart *> cep_list)
{ {

View File

@ -29,41 +29,55 @@
@param part @param part
@param parent @param parent
*/ */
PolygonEditor::PolygonEditor(QETElementEditor *editor, PartPolygon *part, QWidget *parent) : PolygonEditor::PolygonEditor(QETElementEditor *editor,
ElementItemEditor(editor, parent), PartPolygon *part,
ui(new Ui::PolygonEditor), QWidget *parent) :
m_part(part) ElementItemEditor(editor, parent),
ui(new Ui::PolygonEditor),
m_part(part)
{ {
ui->setupUi(this); ui->setupUi(this);
m_style = new StyleEditor(editor); m_style = new StyleEditor(editor);
ui->m_main_layout->insertWidget(0, m_style); ui->m_main_layout->insertWidget(0, m_style);
updateForm(); updateForm();
ui->m_points_list_tree->installEventFilter(this); ui->m_points_list_tree->installEventFilter(this);
ui->m_points_list_tree->addAction(ui->m_add_point_action); ui->m_points_list_tree->addAction(ui->m_add_point_action);
ui->m_points_list_tree->addAction(ui->m_remove_point_action); ui->m_points_list_tree->addAction(ui->m_remove_point_action);
} }
/** /**
@brief PolygonEditor::~PolygonEditor @brief PolygonEditor::~PolygonEditor
*/ */
PolygonEditor::~PolygonEditor() { PolygonEditor::~PolygonEditor() {
delete ui; delete ui;
} }
void PolygonEditor::setUpChangeConnections() void PolygonEditor::setUpChangeConnections()
{ {
m_change_connections << connect(m_part, &PartPolygon::polygonChanged, this, &PolygonEditor::updateForm); m_change_connections << connect(m_part,
m_change_connections << connect(m_part, &PartPolygon::closedChange, this, &PolygonEditor::updateForm); &PartPolygon::polygonChanged,
m_change_connections << connect(m_part, &PartPolygon::xChanged, this, &PolygonEditor::updateForm); this,
m_change_connections << connect(m_part, &PartPolygon::yChanged, this, &PolygonEditor::updateForm); &PolygonEditor::updateForm);
m_change_connections << connect(m_part,
&PartPolygon::closedChange,
this,
&PolygonEditor::updateForm);
m_change_connections << connect(m_part,
&PartPolygon::xChanged,
this,
&PolygonEditor::updateForm);
m_change_connections << connect(m_part,
&PartPolygon::yChanged,
this,
&PolygonEditor::updateForm);
} }
void PolygonEditor::disconnectChangeConnections() void PolygonEditor::disconnectChangeConnections()
{ {
for (QMetaObject::Connection c : m_change_connections) { for (QMetaObject::Connection c : m_change_connections) {
disconnect(c); disconnect(c);
} }
m_change_connections.clear(); m_change_connections.clear();
} }
/** /**
@ -102,11 +116,11 @@ bool PolygonEditor::setPart(CustomElementPart *new_part)
@return the curent edited part @return the curent edited part
*/ */
CustomElementPart *PolygonEditor::currentPart() const { CustomElementPart *PolygonEditor::currentPart() const {
return m_part; return m_part;
} }
QList<CustomElementPart*> PolygonEditor::currentParts() const { QList<CustomElementPart*> PolygonEditor::currentParts() const {
return m_style->currentParts(); return m_style->currentParts();
} }
/** /**
@ -115,23 +129,24 @@ QList<CustomElementPart*> PolygonEditor::currentParts() const {
*/ */
void PolygonEditor::updateForm() void PolygonEditor::updateForm()
{ {
if (!m_part) { if (!m_part) {
return; return;
} }
ui->m_points_list_tree->clear(); ui->m_points_list_tree->clear();
for(QPointF point : m_part->polygon()) for(QPointF point : m_part->polygon())
{ {
point = m_part->mapToScene(point); point = m_part->mapToScene(point);
QTreeWidgetItem *qtwi = new QTreeWidgetItem(); QTreeWidgetItem *qtwi = new QTreeWidgetItem();
qtwi->setData(0, Qt::EditRole, point.x()); qtwi->setData(0, Qt::EditRole, point.x());
qtwi->setData(1, Qt::EditRole, point.y()); qtwi->setData(1, Qt::EditRole, point.y());
qtwi -> setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled); qtwi -> setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled);
ui->m_points_list_tree->addTopLevelItem(qtwi); ui->m_points_list_tree->addTopLevelItem(qtwi);
} }
ui->m_close_polygon_cb->setChecked(m_part->isClosed()); ui->m_close_polygon_cb->setChecked(m_part->isClosed());
ui->m_remove_point_action->setEnabled(m_part->polygon().size() > 2 ? true : false); ui->m_remove_point_action->setEnabled(m_part->polygon().size()
> 2 ? true : false);
} }
/** /**
@ -185,7 +200,11 @@ void PolygonEditor::on_m_close_polygon_cb_stateChanged(int arg1)
bool close = ui->m_close_polygon_cb->isChecked(); bool close = ui->m_close_polygon_cb->isChecked();
if (close != m_part->isClosed()) if (close != m_part->isClosed())
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_part, "closed", m_part->property("closed"), close); QPropertyUndoCommand *undo =
new QPropertyUndoCommand(m_part,
"closed",
m_part->property("closed"),
close);
undo->setText(tr("Modifier un polygone")); undo->setText(tr("Modifier un polygone"));
undoStack().push(undo); undoStack().push(undo);
} }
@ -195,7 +214,8 @@ void PolygonEditor::on_m_close_polygon_cb_stateChanged(int arg1)
@brief PolygonEditor::on_m_points_list_tree_itemChanged @brief PolygonEditor::on_m_points_list_tree_itemChanged
Update the polygon according to the current value of the tree editor Update the polygon according to the current value of the tree editor
*/ */
void PolygonEditor::on_m_points_list_tree_itemChanged(QTreeWidgetItem *item, int column) void PolygonEditor::on_m_points_list_tree_itemChanged(QTreeWidgetItem *item,
int column)
{ {
Q_UNUSED(item); Q_UNUSED(item);
Q_UNUSED(column); Q_UNUSED(column);
@ -207,13 +227,21 @@ void PolygonEditor::on_m_points_list_tree_itemChanged(QTreeWidgetItem *item, int
QPolygonF points = pointsFromTree(); QPolygonF points = pointsFromTree();
if (points.count() < 2) if (points.count() < 2)
{ {
QET::QetMessageBox::warning(this, tr("Erreur", "message box title"), tr("Le polygone doit comporter au moins deux points.", "message box content")); QET::QetMessageBox::warning(this,
tr("Erreur",
"message box title"),
tr("Le polygone doit comporter au moins deux points.",
"message box content"));
return; return;
} }
if (points != m_part->polygon()) if (points != m_part->polygon())
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_part, "polygon", m_part->property("polygon"), points); QPropertyUndoCommand *undo = new QPropertyUndoCommand(
m_part,
"polygon",
m_part->property("polygon"),
points);
undo->setText(tr("Modifier un polygone")); undo->setText(tr("Modifier un polygone"));
undoStack().push(undo); undoStack().push(undo);
} }

View File

@ -25,7 +25,7 @@ class PartPolygon;
class QTreeWidgetItem; class QTreeWidgetItem;
namespace Ui { namespace Ui {
class PolygonEditor; class PolygonEditor;
} }
class PolygonEditor : public ElementItemEditor class PolygonEditor : public ElementItemEditor