mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-28 09:19:59 +01:00
Improve code style, Wrap code for better readability, Mod doc
This commit is contained in:
@@ -26,10 +26,15 @@ class QETProject;
|
||||
|
||||
/**
|
||||
@brief The ProjectDBModel class
|
||||
This model is intended to be use with the @class projectDataBase
|
||||
and is designed to be displayed by the @class QetGraphicsTableItem (but can be use by other view class since it inherit from QAbstractTableModel).
|
||||
This class should be sufficient to display the content of the project data base from a query set by the method void ProjectDBModel::setQuery(const QString &query).
|
||||
The indentifier method is used by widget editor to retrieve the good widget for edit the query. By defaut identifer return the string 'unknow'.
|
||||
This model is intended to be use with the class projectDataBase
|
||||
and is designed to be displayed by the class QetGraphicsTableItem
|
||||
(but can be use by other view class since it inherit from QAbstractTableModel).
|
||||
This class should be sufficient to display the content of
|
||||
the project data base from a query set by the method
|
||||
void ProjectDBModel::setQuery(const QString &query).
|
||||
The indentifier method is used by widget editor to retrieve
|
||||
the good widget for edit the query.
|
||||
By defaut identifer return the string 'unknow'.
|
||||
You should use setIdentfier method to set your custom identifier.
|
||||
At the time this sentence is written, there is two identifier :
|
||||
nomenclature
|
||||
@@ -37,39 +42,48 @@ class QETProject;
|
||||
*/
|
||||
class ProjectDBModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProjectDBModel(QETProject *project, QObject *parent = nullptr);
|
||||
explicit ProjectDBModel (const ProjectDBModel &other_model);
|
||||
public:
|
||||
explicit ProjectDBModel(QETProject *project, QObject *parent = nullptr);
|
||||
explicit ProjectDBModel (const ProjectDBModel &other_model);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
void setQuery(const QString &setQuery);
|
||||
QString queryString() const;
|
||||
QETProject *project() const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
bool setHeaderData(int section,
|
||||
Qt::Orientation orientation,
|
||||
const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
QVariant headerData(int section,
|
||||
Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
bool setData(const QModelIndex &index,
|
||||
const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
QVariant data(const QModelIndex &index,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
void setQuery(const QString &setQuery);
|
||||
QString queryString() const;
|
||||
QETProject *project() const;
|
||||
|
||||
QDomElement toXml(QDomDocument &document) const;
|
||||
void fromXml(const QDomElement &element);
|
||||
QDomElement toXml(QDomDocument &document) const;
|
||||
void fromXml(const QDomElement &element);
|
||||
void setIdentifier(const QString &identifier);
|
||||
QString identifier() const {return m_identifier;}
|
||||
static QString xmlTagName() {return QString("project_data_base_model");}
|
||||
|
||||
private:
|
||||
void dataBaseUpdated();
|
||||
void setHeaderString();
|
||||
void fillValue();
|
||||
private:
|
||||
void dataBaseUpdated();
|
||||
void setHeaderString();
|
||||
void fillValue();
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
QString m_query;
|
||||
QVector<QStringList> m_record;
|
||||
QHash<int, QHash<int, QVariant>> m_header_data; //First int = section, second int = Qt::role, QVariant = value
|
||||
QHash<int, QVariant> m_index_0_0_data;
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
QString m_query;
|
||||
QVector<QStringList> m_record;
|
||||
//First int = section, second int = Qt::role, QVariant = value
|
||||
QHash<int, QHash<int, QVariant>> m_header_data;
|
||||
QHash<int, QVariant> m_index_0_0_data;
|
||||
QString m_identifier = "unknow";
|
||||
};
|
||||
|
||||
|
||||
@@ -41,17 +41,17 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QetGraphicsHeaderItem(QGraphicsItem *parent = nullptr);
|
||||
public:
|
||||
QetGraphicsHeaderItem(QGraphicsItem *parent = nullptr);
|
||||
|
||||
enum { Type = UserType + 1301 };
|
||||
int type() const override { return Type; }
|
||||
|
||||
void setModel(QAbstractItemModel *model = nullptr);
|
||||
QAbstractItemModel *model() const;
|
||||
QAbstractItemModel *model() const;
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
QRect rect() const;
|
||||
void resizeSection(int logicalIndex, int size);
|
||||
int sectionSize(int logical_index) const;
|
||||
@@ -73,9 +73,9 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
void adjustSize();
|
||||
void modelReseted();
|
||||
|
||||
private:
|
||||
QRectF m_bounding_rect;
|
||||
QAbstractItemModel *m_model = nullptr;
|
||||
private:
|
||||
QRectF m_bounding_rect;
|
||||
QAbstractItemModel *m_model = nullptr;
|
||||
QVector<int> m_sections_minimum_width,
|
||||
m_current_sections_width;
|
||||
int m_section_height=1,
|
||||
|
||||
@@ -37,7 +37,7 @@ class QButtonGroup;
|
||||
*/
|
||||
class GraphicsTablePropertiesEditor : public PropertiesEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GraphicsTablePropertiesEditor(QetGraphicsTableItem *table = nullptr, QWidget *parent = nullptr);
|
||||
|
||||
@@ -32,9 +32,9 @@ class ProjectDBModelPropertiesWidget;
|
||||
*/
|
||||
class ProjectDBModelPropertiesWidget : public PropertiesEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
explicit ProjectDBModelPropertiesWidget(ProjectDBModel *model = nullptr, QWidget *parent = nullptr);
|
||||
~ProjectDBModelPropertiesWidget();
|
||||
|
||||
|
||||
@@ -1011,22 +1011,22 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
|
||||
dom_element.setAttribute("x", QString::number(pos().x()));
|
||||
dom_element.setAttribute("y", QString::number(pos().y()));
|
||||
|
||||
// Terminal is uniquely identified by the uuid of the terminal and the element
|
||||
if (terminal1->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
|
||||
}
|
||||
// Terminal is uniquely identified by the uuid of the terminal and the element
|
||||
if (terminal1->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
|
||||
}
|
||||
|
||||
if (terminal2->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
|
||||
}
|
||||
if (terminal2->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
|
||||
}
|
||||
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
|
||||
|
||||
// on n'exporte les segments du conducteur que si ceux-ci ont
|
||||
@@ -2006,8 +2006,9 @@ Conductor * longuestConductorInPotential(Conductor *conductor, bool all_diagram)
|
||||
/**
|
||||
@brief relatedConductors
|
||||
@param conductor
|
||||
@return return all conductors who share the same terminals of @conductor given as parametre,
|
||||
except @conductor himself.
|
||||
@return return all conductors who share the same terminals
|
||||
of conductor given as parametre,
|
||||
except conductor himself.
|
||||
*/
|
||||
QList <Conductor *> relatedConductors(const Conductor *conductor) {
|
||||
QList<Conductor *> other_conductors_list = conductor -> terminal1 -> conductors();
|
||||
|
||||
@@ -142,7 +142,7 @@ class Conductor : public QGraphicsObject
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange, const QVariant &) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void adjusteHandlerPos();
|
||||
|
||||
@@ -38,9 +38,9 @@ ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) :
|
||||
Constructeur
|
||||
@param text Le texte affiche par le champ de texte
|
||||
@param parent_conductor Conducteur auquel ce texte est rattache
|
||||
@param parent_diagram Schema auquel ce texte et son conducteur parent sont rattaches
|
||||
*/
|
||||
ConductorTextItem::ConductorTextItem(const QString &text, Conductor *parent_conductor) :
|
||||
ConductorTextItem::ConductorTextItem(const QString &text,
|
||||
Conductor *parent_conductor) :
|
||||
DiagramTextItem(text, parent_conductor),
|
||||
parent_conductor_(parent_conductor),
|
||||
moved_by_user_(false),
|
||||
|
||||
@@ -29,40 +29,40 @@ class Conductor;
|
||||
class ConductorTextItem : public DiagramTextItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
// constructors, destructor
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
ConductorTextItem(Conductor * = nullptr);
|
||||
ConductorTextItem(const QString &, Conductor * = nullptr);
|
||||
~ConductorTextItem() override;
|
||||
ConductorTextItem(Conductor * = nullptr);
|
||||
ConductorTextItem(const QString &, Conductor * = nullptr);
|
||||
~ConductorTextItem() override;
|
||||
private:
|
||||
ConductorTextItem(const ConductorTextItem &);
|
||||
ConductorTextItem(const ConductorTextItem &);
|
||||
|
||||
public:
|
||||
enum { Type = UserType + 1006 };
|
||||
Conductor *parentConductor() const;
|
||||
void fromXml(const QDomElement &) override;
|
||||
int type() const override { return Type; }
|
||||
virtual bool wasMovedByUser() const;
|
||||
virtual bool wasRotateByUser() const;
|
||||
virtual void forceMovedByUser(bool);
|
||||
virtual void forceRotateByUser(bool);
|
||||
virtual void setPos(const QPointF &pos);
|
||||
virtual void setPos(qreal x, qreal y);
|
||||
|
||||
enum { Type = UserType + 1006 };
|
||||
Conductor *parentConductor() const;
|
||||
void fromXml(const QDomElement &) override;
|
||||
int type() const override { return Type; }
|
||||
virtual bool wasMovedByUser() const;
|
||||
virtual bool wasRotateByUser() const;
|
||||
virtual void forceMovedByUser(bool);
|
||||
virtual void forceRotateByUser(bool);
|
||||
virtual void setPos(const QPointF &pos);
|
||||
virtual void setPos(qreal x, qreal y);
|
||||
|
||||
protected:
|
||||
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
|
||||
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
|
||||
|
||||
// attributes
|
||||
// attributes
|
||||
private:
|
||||
Conductor *parent_conductor_;
|
||||
bool moved_by_user_;
|
||||
bool rotate_by_user_;
|
||||
QPointF before_mov_pos_;
|
||||
Conductor *parent_conductor_;
|
||||
bool moved_by_user_;
|
||||
bool rotate_by_user_;
|
||||
QPointF before_mov_pos_;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -70,7 +70,7 @@ void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
||||
painter -> setRenderHint(QPainter::Antialiasing, false);
|
||||
painter -> setRenderHint(QPainter::TextAntialiasing, false);
|
||||
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
// Dessin du cadre de selection en noir à partir du boundingrect
|
||||
// Dessin du cadre de selection en noir à partir du boundingrect
|
||||
QPen t(Qt::black);
|
||||
t.setStyle(Qt::DashLine);
|
||||
painter -> setPen(t);
|
||||
|
||||
@@ -166,7 +166,7 @@ void DiagramTextItem::setFont(const QFont &font)
|
||||
|
||||
void DiagramTextItem::setColor(const QColor& color)
|
||||
{
|
||||
setDefaultTextColor(color);
|
||||
setDefaultTextColor(color);
|
||||
emit colorChanged(color);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ class QDomDocument;
|
||||
class DiagramTextItem : public QGraphicsTextItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||
Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText)
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||
@@ -68,10 +68,10 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
QPointF mapMovementFromParent (const QPointF &) const;
|
||||
|
||||
void setFont(const QFont &font);
|
||||
|
||||
void setColor(const QColor& color);
|
||||
QColor color() const;
|
||||
|
||||
|
||||
void setColor(const QColor& color);
|
||||
QColor color() const;
|
||||
|
||||
void setNoEditable(bool e = true) {m_no_editable = e;}
|
||||
|
||||
void setAlignment(const Qt::Alignment &alignment);
|
||||
@@ -85,7 +85,9 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
bool isHtml() const;
|
||||
|
||||
protected:
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||
void paint(QPainter *,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
void focusInEvent(QFocusEvent *) override;
|
||||
void focusOutEvent(QFocusEvent *) override;
|
||||
|
||||
@@ -104,13 +106,15 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
|
||||
|
||||
protected:
|
||||
bool m_mouse_hover = false,
|
||||
m_first_move = true,
|
||||
m_no_editable,
|
||||
m_is_html = false;
|
||||
bool
|
||||
m_mouse_hover = false,
|
||||
m_first_move = true,
|
||||
m_no_editable,
|
||||
m_is_html = false;
|
||||
|
||||
QString m_previous_html_text,
|
||||
m_previous_text;
|
||||
QString
|
||||
m_previous_html_text,
|
||||
m_previous_text;
|
||||
|
||||
QPointF m_mouse_to_origin_movement;
|
||||
|
||||
|
||||
@@ -40,16 +40,16 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
friend class DynamicTextItemDelegate;
|
||||
friend class CompositeTextEditDialog;
|
||||
friend class Element;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||
Q_PROPERTY(TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY textFromChanged)
|
||||
Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
|
||||
Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
|
||||
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
|
||||
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum TextFrom {
|
||||
@@ -60,7 +60,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
Q_ENUM (TextFrom)
|
||||
enum {Type = UserType + 1010};
|
||||
int type() const override {return Type;}
|
||||
|
||||
|
||||
signals:
|
||||
void textChanged(QString text);
|
||||
void textFromChanged(DynamicElementTextItem::TextFrom text_from);
|
||||
@@ -69,7 +69,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
void frameChanged(bool frame);
|
||||
void plainTextChanged();
|
||||
void textWidthChanged(qreal width);
|
||||
|
||||
|
||||
public:
|
||||
DynamicElementTextItem(Element *parent_element);
|
||||
~DynamicElementTextItem() override;
|
||||
@@ -81,12 +81,12 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
public:
|
||||
QDomElement toXml(QDomDocument &dom_doc) const override;
|
||||
void fromXml(const QDomElement &dom_elmt) override;
|
||||
|
||||
|
||||
Element *parentElement() const;
|
||||
ElementTextItemGroup *parentGroup() const;
|
||||
Element *elementUseForInfo() const;
|
||||
void refreshLabelConnection();
|
||||
|
||||
|
||||
DynamicElementTextItem::TextFrom textFrom() const;
|
||||
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
|
||||
QString text() const;
|
||||
@@ -103,7 +103,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
void setPlainText(const QString &text);
|
||||
void setTextWidth(qreal width);
|
||||
void setXref_item(Qt::AlignmentFlag m_exHrefPos);
|
||||
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
@@ -114,7 +114,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
|
||||
private:
|
||||
void elementInfoChanged();
|
||||
void masterChanged();
|
||||
@@ -134,25 +134,28 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
QString reportReplacedCompositeText() const;
|
||||
void zoomToLinkedElement();
|
||||
|
||||
|
||||
private:
|
||||
QPointer <Element> m_parent_element,
|
||||
m_master_element,
|
||||
m_other_report;
|
||||
QPointer <Element>
|
||||
m_parent_element,
|
||||
m_master_element,
|
||||
m_other_report;
|
||||
QPointer <Conductor> m_watched_conductor;
|
||||
QString m_text,
|
||||
m_info_name,
|
||||
m_composite_text,
|
||||
m_report_formula,
|
||||
m_F_str;
|
||||
QString
|
||||
m_text,
|
||||
m_info_name,
|
||||
m_composite_text,
|
||||
m_report_formula,
|
||||
m_F_str;
|
||||
DynamicElementTextItem::TextFrom m_text_from = UserText;
|
||||
QUuid m_uuid;
|
||||
QMetaObject::Connection m_report_formula_con;
|
||||
QList<QMetaObject::Connection> m_formula_connection,
|
||||
m_update_slave_Xref_connection;
|
||||
QList<QMetaObject::Connection>
|
||||
m_formula_connection,
|
||||
m_update_slave_Xref_connection;
|
||||
QColor m_user_color;
|
||||
bool m_frame = false,
|
||||
m_first_scene_change = true;
|
||||
bool
|
||||
m_frame = false,
|
||||
m_first_scene_change = true;
|
||||
CrossRefItem *m_Xref_item = nullptr;
|
||||
QGraphicsTextItem *m_slave_Xref_item = nullptr;
|
||||
qreal m_text_width = -1;
|
||||
|
||||
@@ -64,8 +64,8 @@ QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, QGraphicsItem
|
||||
|
||||
QetShapeItem::~QetShapeItem()
|
||||
{
|
||||
if(!m_handler_vector.isEmpty())
|
||||
qDeleteAll(m_handler_vector);
|
||||
if(!m_handler_vector.isEmpty())
|
||||
qDeleteAll(m_handler_vector);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,8 +221,9 @@ void QetShapeItem::setNextPoint(QPointF P)
|
||||
/**
|
||||
@brief QetShapeItem::removePoints
|
||||
Number of point to remove on the polygon
|
||||
If @number is superior to number of polygon points-2,
|
||||
all points of polygon will be removed except the first two (minimum point for the polygon);
|
||||
If number is superior to number of polygon points-2,
|
||||
all points of polygon will be removed except
|
||||
the first two (minimum point for the polygon);
|
||||
*/
|
||||
void QetShapeItem::removePoints(int number)
|
||||
{
|
||||
@@ -259,12 +260,14 @@ QPainterPath QetShapeItem::shape() const
|
||||
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case Line:
|
||||
case Line:
|
||||
path.moveTo(m_P1);
|
||||
path.lineTo(m_P2);
|
||||
path.lineTo(m_P2);
|
||||
break;
|
||||
case Rectangle:
|
||||
path.addRoundedRect(QRectF(m_P1, m_P2), m_xRadius, m_yRadius);
|
||||
path.addRoundedRect(QRectF(m_P1, m_P2),
|
||||
m_xRadius,
|
||||
m_yRadius);
|
||||
break;
|
||||
case Ellipse:
|
||||
path.addEllipse(QRectF(m_P1, m_P2));
|
||||
@@ -292,7 +295,9 @@ QPainterPath QetShapeItem::shape() const
|
||||
@param option
|
||||
@param widget
|
||||
*/
|
||||
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void QetShapeItem::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
@@ -317,9 +322,12 @@ void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case Line: painter->drawLine(QLineF(m_P1, m_P2)); break;
|
||||
case Rectangle: painter->drawRoundedRect(QRectF(m_P1, m_P2), m_xRadius, m_yRadius); break;
|
||||
case Rectangle: painter->drawRoundedRect(QRectF(m_P1, m_P2),
|
||||
m_xRadius,
|
||||
m_yRadius); break;
|
||||
case Ellipse: painter->drawEllipse(QRectF(m_P1, m_P2)); break;
|
||||
case Polygon: m_closed ? painter->drawPolygon(m_polygon) : painter->drawPolyline(m_polygon); break;
|
||||
case Polygon: m_closed ? painter->drawPolygon(m_polygon)
|
||||
: painter->drawPolyline(m_polygon); break;
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
@@ -364,11 +372,13 @@ void QetShapeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant QetShapeItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
QVariant QetShapeItem::itemChange(QGraphicsItem::GraphicsItemChange change,
|
||||
const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged)
|
||||
{
|
||||
if (value.toBool() == true) { //If this is selected, wa add handlers.
|
||||
if (value.toBool() == true) {
|
||||
//If this is selected, wa add handlers.
|
||||
addHandler();
|
||||
}
|
||||
else //Else this is deselected, we remove handlers
|
||||
@@ -956,11 +966,32 @@ QDomElement QetShapeItem::toXml(QDomDocument &document) const
|
||||
bool QetShapeItem::toDXF(const QString &filepath,const QPen &pen)
|
||||
{
|
||||
|
||||
switch (m_shapeType)
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case Line: Createdxf::drawLine (filepath, QLineF(mapToScene(m_P1), mapToScene(m_P2)), Createdxf::getcolorCode(pen.color().red(),pen.color().green(),pen.color().blue())); return true;
|
||||
case Rectangle: Createdxf::drawRectangle(filepath, QRectF(mapToScene(m_P1), mapToScene(m_P2)).normalized(), Createdxf::getcolorCode(pen.color().red(),pen.color().green(),pen.color().blue())); return true;
|
||||
case Ellipse: Createdxf::drawEllipse (filepath, QRectF(mapToScene(m_P1), mapToScene(m_P2)).normalized(), Createdxf::getcolorCode(pen.color().red(),pen.color().green(),pen.color().blue())); return true;
|
||||
case Line:
|
||||
Createdxf::drawLine(filepath,
|
||||
QLineF(mapToScene(m_P1),
|
||||
mapToScene(m_P2)),
|
||||
Createdxf::getcolorCode(pen.color().red(),
|
||||
pen.color().green(),
|
||||
pen.color().blue()));
|
||||
return true;
|
||||
case Rectangle:
|
||||
Createdxf::drawRectangle(filepath,
|
||||
QRectF(mapToScene(m_P1),
|
||||
mapToScene(m_P2)).normalized(),
|
||||
Createdxf::getcolorCode(pen.color().red(),
|
||||
pen.color().green(),
|
||||
pen.color().blue()));
|
||||
return true;
|
||||
case Ellipse:
|
||||
Createdxf::drawEllipse (filepath,
|
||||
QRectF(mapToScene(m_P1),
|
||||
mapToScene(m_P2)).normalized(),
|
||||
Createdxf::getcolorCode(pen.color().red(),
|
||||
pen.color().green(),
|
||||
pen.color().blue()));
|
||||
return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,8 @@ class QetShapeItem : public QetGraphicsItem
|
||||
void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override;
|
||||
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
|
||||
private:
|
||||
@@ -140,7 +140,7 @@ class QetShapeItem : public QetGraphicsItem
|
||||
bool m_closed = false,
|
||||
m_modifie_radius_equaly = false;
|
||||
int m_resize_mode = 1;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
QAction *m_insert_point,
|
||||
*m_remove_point;
|
||||
qreal m_xRadius = 0,
|
||||
|
||||
Reference in New Issue
Block a user