QElectroTech  0.8-dev
qetgraphicstableitem.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef QetGraphicsTableItem_H
19 #define QetGraphicsTableItem_H
20 
21 #include <QFont>
22 
23 #include "qetgraphicsitem.h"
24 #include "qetapp.h"
26 
27 class QAbstractItemModel;
29 
43 {
44  Q_OBJECT
45 
46  Q_PROPERTY(QSize size READ size WRITE setSize)
47  Q_PROPERTY(int displayNRow READ displayNRow WRITE setDisplayNRow)
48 
49  public :
50  static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins = QMargins(20,20,20,0));
51  static void checkInsufficientRowsCount(QetGraphicsTableItem *first_table);
52 
53  public:
54  QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
55  virtual ~QetGraphicsTableItem() override;
56 
57  enum { Type = UserType + 1300 };
58  int type() const override { return Type; }
59 
60  void setModel(QAbstractItemModel *model = nullptr);
61  QAbstractItemModel *model() const;
62 
63  virtual QRectF boundingRect() const override;
64  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
66  void setSize(const QSize &size);
67  QSize size() const;
68  QSize minimumSize() const;
69  void setDisplayNRow(const int &number);
70  int displayNRow() const;
71  void setPreviousTable(QetGraphicsTableItem *table = nullptr);
72  void setNextTable(QetGraphicsTableItem *table = nullptr);
73  void setTableName(const QString &name);
74  QString tableName() const;
75  int displayNRowOffset() const;
78  void setToMinimumHeight();
79  void initLink();
80  QUuid uuid() const {return m_uuid;}
81  int minimumRowHeigth() const;
82 
83  QDomElement toXml(QDomDocument &dom_document) const;
84  void fromXml(const QDomElement &dom_element);
85  static QString xmlTagName() {return QString("graphics_table");}
86 
87  protected:
88  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
89  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
90  virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
91  virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
92 
93  private:
94  void modelReseted();
96  void setUpBoundingRect();
97  void adjustHandlerPos();
98  void setUpHandler();
99  void handlerMousePressEvent (QGraphicsSceneMouseEvent *event);
100  void handlerMouseMoveEvent (QGraphicsSceneMouseEvent *event);
101  void handlerMouseReleaseEvent (QGraphicsSceneMouseEvent *event);
102  void adjustColumnsWidth();
103  void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
104  void headerSectionResized();
105  void adjustSize();
107 
108  private:
109  QAbstractItemModel *m_model= nullptr;
110 
117 
118  int m_br_margin= 10;
120 
123 
125  *m_next_table = nullptr;
126 
127  QString m_name;
128  QUuid m_uuid = QUuid::createUuid(),
130 };
131 
132 #endif // QetGraphicsTableItem_H
QetGraphicsTableItem::m_header_item
QetGraphicsHeaderItem * m_header_item
Definition: qetgraphicstableitem.h:122
QetGraphicsTableItem::boundingRect
virtual QRectF boundingRect() const override
QetGraphicsTableItem::boundingRect Reimplemented from QGraphicsObject.
Definition: qetgraphicstableitem.cpp:196
QetGraphicsTableItem::m_previous_table
QetGraphicsTableItem * m_previous_table
Definition: qetgraphicstableitem.h:124
ProjectDBModel::xmlTagName
static QString xmlTagName()
Definition: projectdbmodel.h:73
QetGraphicsTableItem::m_minimum_column_width
QVector< int > m_minimum_column_width
Definition: qetgraphicstableitem.h:111
QetGraphicsItem
Definition: qetgraphicsitem.h:27
QetGraphicsTableItem::initLink
void initLink()
Definition: qetgraphicstableitem.cpp:483
qetgraphicsitem.h
QetGraphicsTableItem::m_bounding_rect
QRectF m_bounding_rect
Definition: qetgraphicstableitem.h:119
QetGraphicsTableItem::m_old_size
QSize m_old_size
Definition: qetgraphicstableitem.h:115
QetGraphicsTableItem::setSize
void setSize(const QSize &size)
QetGraphicsTableItem::setSize Set the current size of the table to size.
Definition: qetgraphicstableitem.cpp:295
QetGraphicsTableItem::handlerMouseReleaseEvent
void handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Definition: qetgraphicstableitem.cpp:754
QetGraphicsTableItem::m_handler_item
QetGraphicsHandlerItem m_handler_item
Definition: qetgraphicstableitem.h:121
QetGraphicsHeaderItem::sectionResized
void sectionResized(int logicalIndex, int size)
ElementProvider
Definition: elementprovider.h:37
QetGraphicsTableItem
The QetGraphicsTableItem class This item display a table destined to represent the content of a QAbst...
Definition: qetgraphicstableitem.h:43
QetGraphicsTableItem::setNextTable
void setNextTable(QetGraphicsTableItem *table=nullptr)
QetGraphicsTableItem::setNextTable Set the next table to table nullptr will remove an existing next t...
Definition: qetgraphicstableitem.cpp:420
QetGraphicsItem::diagram
Diagram * diagram() const
Definition: qetgraphicsitem.cpp:40
QetGraphicsHeaderItem::resizeSection
void resizeSection(int logicalIndex, int size)
QetGraphicsHeaderItem::resizeSection.
Definition: qetgraphicsheaderitem.cpp:156
QetGraphicsTableItem::m_model
QAbstractItemModel * m_model
Definition: qetgraphicstableitem.h:109
QetGraphicsTableItem::m_minimum_row_height
int m_minimum_row_height
Definition: qetgraphicstableitem.h:112
QetGraphicsTableItem::headerSectionResized
void headerSectionResized()
QetGraphicsTableItem::headerSectionResized Connected to the header signal QetGraphicsTableItem sectio...
Definition: qetgraphicstableitem.cpp:832
QetGraphicsTableItem::m_number_of_displayed_row
int m_number_of_displayed_row
Definition: qetgraphicstableitem.h:113
QetGraphicsTableItem::adjustHandlerPos
void adjustHandlerPos()
QetGraphicsTableItem::adjustHandlerPos Adjust the pos of the handler item.
Definition: qetgraphicstableitem.cpp:716
QetGraphicsTableItem::fromXml
void fromXml(const QDomElement &dom_element)
QetGraphicsTableItem::fromXml Restore the table from xml. Make this item is already in a diagram to.
Definition: qetgraphicstableitem.cpp:550
QetGraphicsTableItem::previousTable
QetGraphicsTableItem * previousTable() const
Definition: qetgraphicstableitem.cpp:463
QetGraphicsHeaderItem
The QetGraphicsHeaderItem class The header have a few parameters to edit her visual aspect....
Definition: qetgraphicsheaderitem.h:41
QetGraphicsTableItem::toXml
QDomElement toXml(QDomDocument &dom_document) const
QetGraphicsTableItem::toXml Save the table to xml.
Definition: qetgraphicstableitem.cpp:510
QetGraphicsItem::name
virtual QString name() const
Definition: qetgraphicsitem.h:44
ProjectDBModel
The ProjectDBModel class This model is intended to be use with the class projectDataBase and is desig...
Definition: projectdbmodel.h:44
QetGraphicsTableItem::modelReseted
void modelReseted()
Definition: qetgraphicstableitem.cpp:660
QetGraphicsTableItem::m_current_size
QSize m_current_size
Definition: qetgraphicstableitem.h:114
QetGraphicsTableItem::tableName
QString tableName() const
Definition: qetgraphicstableitem.cpp:445
QetGraphicsTableItem::setUpColumnAndRowMinimumSize
void setUpColumnAndRowMinimumSize()
QetGraphicsTableItem::setUpColumnAndRowMinimumSize Calcule the minimum row height and the minimum col...
Definition: qetgraphicstableitem.cpp:674
QetGraphicsTableItem::m_next_table
QetGraphicsTableItem * m_next_table
Definition: qetgraphicstableitem.h:125
QetGraphicsTableItem::QetGraphicsTableItem
QetGraphicsTableItem(QGraphicsItem *parent=nullptr)
QetGraphicsTableItem::QetGraphicsTableItem Default constructor.
Definition: qetgraphicstableitem.cpp:124
QetGraphicsTableItem::minimumRowHeigth
int minimumRowHeigth() const
QetGraphicsTableItem::minimumRowHeigth.
Definition: qetgraphicstableitem.cpp:500
QetGraphicsTableItem::setUpHandler
void setUpHandler()
QetGraphicsTableItem::setUpHandler.
Definition: qetgraphicstableitem.cpp:723
Diagram::border_and_titleblock
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition: diagram.h:83
qetapp.h
QetGraphicsHeaderItem::minimumSectionWidth
QVector< int > minimumSectionWidth() const
Definition: qetgraphicsheaderitem.h:58
BorderTitleBlock::insideBorderRect
QRectF insideBorderRect() const
BorderTitleBlock::insideBorderRect.
Definition: bordertitleblock.cpp:185
QetGraphicsTableItem::itemChange
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
QetGraphicsTableItem::itemChange.
Definition: qetgraphicstableitem.cpp:648
elementprovider.h
QetGraphicsTableItem::uuid
QUuid uuid() const
Definition: qetgraphicstableitem.h:80
QetGraphicsTableItem::adjustColumnsWidth
void adjustColumnsWidth()
QetGraphicsTableItem::adjustColumnsWidth Adjust the size of each column according to the current tabl...
Definition: qetgraphicstableitem.cpp:772
QetGraphicsTableItem::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QetGraphicsTableItem::paint Draw the table.
Definition: qetgraphicstableitem.cpp:207
QetGraphicsTableItem::Type
@ Type
Definition: qetgraphicstableitem.h:57
QetGraphicsHeaderItem::setModel
void setModel(QAbstractItemModel *model=nullptr)
QetGraphicsHeaderItem::setModel Set the model presented by this item Since QetGraphicsHeaderItem don'...
Definition: qetgraphicsheaderitem.cpp:43
QetGraphicsTableItem::adjustSize
void adjustSize()
QetGraphicsTableItem::adjustSize If needed, this function resize the current height and width of tabl...
Definition: qetgraphicstableitem.cpp:848
QetGraphicsTableItem::setToMinimumHeight
void setToMinimumHeight()
QetGraphicsTableItem::setToMinimumHeight Set the height to the the minimum. The width stay unchanged.
Definition: qetgraphicstableitem.cpp:476
QetGraphicsTableItem::adjustTableToFolio
static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins=QMargins(20, 20, 20, 0))
QetGraphicsTableItem::adjustTableToFolio Adjust the table to fit at best the folio.
Definition: qetgraphicstableitem.cpp:42
QET::QetMessageBox::information
QMessageBox::StandardButton information(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
Definition: qetmessagebox.cpp:38
QetGraphicsTableItem::m_pending_previous_table_uuid
QUuid m_pending_previous_table_uuid
Definition: qetgraphicstableitem.h:129
QetGraphicsTableItem::displayNRowOffset
int displayNRowOffset() const
QetGraphicsTableItem::displayNRowOffset.
Definition: qetgraphicstableitem.cpp:454
QetGraphicsTableItem::handlerMouseMoveEvent
void handlerMouseMoveEvent(QGraphicsSceneMouseEvent *event)
Definition: qetgraphicstableitem.cpp:739
qpropertyundocommand.h
QetGraphicsHeaderItem::fromXml
void fromXml(const QDomElement &element)
QetGraphicsHeaderItem::fromXml Restore the header from xml.
Definition: qetgraphicsheaderitem.cpp:224
QetGraphicsTableItem::handlerMousePressEvent
void handlerMousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: qetgraphicstableitem.cpp:729
QetGraphicsTableItem::m_uuid
QUuid m_uuid
Definition: qetgraphicstableitem.h:128
QetGraphicsTableItem::setTableName
void setTableName(const QString &name)
Definition: qetgraphicstableitem.cpp:441
qetgraphicshandleritem.h
Diagram::undoStack
QUndoStack & undoStack()
Diagram::undoStack.
Definition: diagram.h:397
QetGraphicsHandlerItem
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition: qetgraphicshandleritem.h:37
QetGraphicsTableItem::hoverLeaveEvent
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
QetGraphicsTableItem::hoverLeaveEvent Reimplemented from QetGraphicsItem.
Definition: qetgraphicstableitem.cpp:603
QetGraphicsTableItem::checkInsufficientRowsCount
static void checkInsufficientRowsCount(QetGraphicsTableItem *first_table)
QetGraphicsTableItem::checkInsufficientRowsCount Check if the number of rows of table + linked table ...
Definition: qetgraphicstableitem.cpp:72
QETXML::directChild
QVector< QDomElement > directChild(const QDomElement &element, const QString &tag_name)
QETXML::directChild.
Definition: qetxml.cpp:313
QetGraphicsTableItem::m_br_margin
int m_br_margin
Definition: qetgraphicstableitem.h:118
QetGraphicsTableItem::setModel
void setModel(QAbstractItemModel *model=nullptr)
QetGraphicsTableItem::setModel Set the model presented by this item. Since QetGraphicsTableItem don't...
Definition: qetgraphicstableitem.cpp:158
qetgraphicsheaderitem.h
QetGraphicsTableItem::type
int type() const override
Definition: qetgraphicstableitem.h:58
QetGraphicsHeaderItem::rect
QRect rect() const
QetGraphicsHeaderItem::rect.
Definition: qetgraphicsheaderitem.cpp:147
qetgraphicstableitem.h
QetGraphicsTableItem::headerItem
QetGraphicsHeaderItem * headerItem() const
Definition: qetgraphicstableitem.h:65
qetutils.h
QetGraphicsTableItem::setPreviousTable
void setPreviousTable(QetGraphicsTableItem *table=nullptr)
QetGraphicsTableItem::setPreviousTable Set the previous table to table. If this table already have a ...
Definition: qetgraphicstableitem.cpp:389
QETUtils::marginsFromString
QMargins marginsFromString(const QString &string)
QETUtils::marginsFromString.
Definition: qetutils.cpp:46
QetGraphicsHeaderItem::toXml
QDomElement toXml(QDomDocument &document) const
QetGraphicsHeaderItem::toXml save the header to xml.
Definition: qetgraphicsheaderitem.cpp:209
QetGraphicsHandlerItem::setColor
void setColor(QColor color)
QetGraphicsHandlerItem::setColor.
Definition: qetgraphicshandleritem.cpp:48
QetGraphicsTableItem::minimumSize
QSize minimumSize() const
QetGraphicsTableItem::minimumSize.
Definition: qetgraphicstableitem.cpp:329
QetGraphicsTableItem::model
QAbstractItemModel * model() const
QetGraphicsTableItem::model.
Definition: qetgraphicstableitem.cpp:187
QetGraphicsHeaderItem::sectionSize
int sectionSize(int logical_index) const
QetGraphicsHeaderItem::sectionSize.
Definition: qetgraphicsheaderitem.cpp:194
QetGraphicsHeaderItem::heightResized
void heightResized()
qetxml.h
QetGraphicsTableItem::displayNRow
int displayNRow
Definition: qetgraphicstableitem.h:47
Diagram::snapToGrid
static QPointF snapToGrid(const QPointF &p)
Diagram::snapToGrid Return a nearest snap point of p.
Definition: diagram.cpp:2240
QetGraphicsTableItem::setDisplayNRow
void setDisplayNRow(const int &number)
QetGraphicsTableItem::setDisplayNRow Limit the number of row to display.
Definition: qetgraphicstableitem.cpp:358
QetGraphicsTableItem::nextTable
QetGraphicsTableItem * nextTable() const
Definition: qetgraphicstableitem.cpp:467
QetGraphicsTableItem::m_pending_size
QSize m_pending_size
Definition: qetgraphicstableitem.h:116
QetGraphicsTableItem::hoverEnterEvent
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
QetGraphicsTableItem::hoverEnterEvent Reimplemented from QetGraphicsItem.
Definition: qetgraphicstableitem.cpp:587
projectdbmodel.h
QetGraphicsTableItem::setUpBoundingRect
void setUpBoundingRect()
QetGraphicsTableItem::setUpBoundingRect.
Definition: qetgraphicstableitem.cpp:705
QetGraphicsItem::setPos
virtual void setPos(const QPointF &p)
Definition: qetgraphicsitem.cpp:49
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
QetGraphicsTableItem::size
QSize size
Definition: qetgraphicstableitem.h:46
QetGraphicsTableItem::xmlTagName
static QString xmlTagName()
Definition: qetgraphicstableitem.h:85
QetGraphicsTableItem::dataChanged
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
Definition: qetgraphicstableitem.cpp:817
QetGraphicsTableItem::m_name
QString m_name
Definition: qetgraphicstableitem.h:127
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
ElementProvider::tableFromUuid
QetGraphicsTableItem * tableFromUuid(const QUuid &uuid)
ElementProvider::tableFromUuid.
Definition: elementprovider.cpp:172
QetGraphicsTableItem::~QetGraphicsTableItem
virtual ~QetGraphicsTableItem() override
Definition: qetgraphicstableitem.cpp:148
diagram.h
QetGraphicsHeaderItem::xmlTagName
static QString xmlTagName()
Definition: qetgraphicsheaderitem.h:63
QetGraphicsTableItem::sceneEventFilter
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
QetGraphicsTableItem::sceneEventFilter Reimplemented from QetGraphicsItem.
Definition: qetgraphicstableitem.cpp:618
QetGraphicsTableItem::previousTableDisplayRowChanged
void previousTableDisplayRowChanged()
Definition: qetgraphicstableitem.cpp:876