QElectroTech  0.8-dev
qetgraphicsheaderitem.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 QETGRAPHICSHEADERITEM_H
19 #define QETGRAPHICSHEADERITEM_H
20 
21 #include "qetapp.h"
22 
23 #include <QGraphicsObject>
24 #include <QFont>
25 #include <QMargins>
26 
27 class QAbstractItemModel;
28 
40 class QetGraphicsHeaderItem : public QGraphicsObject
41 {
42  Q_OBJECT
43 
44  public:
45  QetGraphicsHeaderItem(QGraphicsItem *parent = nullptr);
46 
47  enum { Type = UserType + 1301 };
48  int type() const override { return Type; }
49 
50  void setModel(QAbstractItemModel *model = nullptr);
51  QAbstractItemModel *model() const;
52 
53  virtual QRectF boundingRect() const override;
54  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
55  QRect rect() const;
56  void resizeSection(int logicalIndex, int size);
57  int sectionSize(int logical_index) const;
58  QVector<int> minimumSectionWidth() const {return m_sections_minimum_width;}
59  int minimumWidth() const {return m_minimum_width;}
60 
61  QDomElement toXml (QDomDocument &document) const;
62  void fromXml(const QDomElement &element);
63  static QString xmlTagName() {return QString("graphics_header");}
64 
65  signals:
66  void sectionResized(int logicalIndex, int size);
67  void heightResized();
68 
69  private:
71  void setUpBoundingRect();
72  void headerDataChanged(Qt::Orientations orientation, int first, int last);
73  void adjustSize();
74  void modelReseted();
75 
76  private:
78  QAbstractItemModel *m_model = nullptr;
85 };
86 
87 #endif // QETGRAPHICSHEADERITEM_H
QETXML::marginsToXml
QDomElement marginsToXml(QDomDocument &parent_document, const QMargins &margins)
QETXML::marginsToXml Save a QMargins to xml. the xml tag name is 'margins'.
Definition: qetxml.cpp:377
QetGraphicsHeaderItem::m_bounding_rect
QRectF m_bounding_rect
Definition: qetgraphicsheaderitem.h:77
QetGraphicsHeaderItem::m_current_rect
QRect m_current_rect
Definition: qetgraphicsheaderitem.h:84
QetGraphicsHeaderItem::setUpMinimumSectionsSize
void setUpMinimumSectionsSize()
QetGraphicsHeaderItem::setUpMinimumSectionsSize Setup the minimum section size and height of the item...
Definition: qetgraphicsheaderitem.cpp:239
QetGraphicsHeaderItem::sectionResized
void sectionResized(int logicalIndex, int size)
QetGraphicsHeaderItem::resizeSection
void resizeSection(int logicalIndex, int size)
QetGraphicsHeaderItem::resizeSection.
Definition: qetgraphicsheaderitem.cpp:156
QetGraphicsHeaderItem::m_current_sections_width
QVector< int > m_current_sections_width
Definition: qetgraphicsheaderitem.h:80
QetGraphicsHeaderItem
The QetGraphicsHeaderItem class The header have a few parameters to edit her visual aspect....
Definition: qetgraphicsheaderitem.h:41
QETXML::marginsFromXml
QMargins marginsFromXml(const QDomElement &element)
QETXML::marginsFromXml.
Definition: qetxml.cpp:399
QetGraphicsHeaderItem::setUpBoundingRect
void setUpBoundingRect()
QetGraphicsHeaderItem::setUpBoundingRect Setup the bounding rect of the item.
Definition: qetgraphicsheaderitem.cpp:271
QetGraphicsHeaderItem::minimumWidth
int minimumWidth() const
Definition: qetgraphicsheaderitem.h:59
QetGraphicsHeaderItem::m_model
QAbstractItemModel * m_model
Definition: qetgraphicsheaderitem.h:78
qetapp.h
QET::Icons::Orientations
QIcon Orientations
Definition: qeticons.cpp:126
QetGraphicsHeaderItem::headerDataChanged
void headerDataChanged(Qt::Orientations orientation, int first, int last)
QetGraphicsHeaderItem::headerDataChanged Update the header when data of displayed model change.
Definition: qetgraphicsheaderitem.cpp:282
QetGraphicsHeaderItem::minimumSectionWidth
QVector< int > minimumSectionWidth() const
Definition: qetgraphicsheaderitem.h:58
QetGraphicsHeaderItem::type
int type() const override
Definition: qetgraphicsheaderitem.h:48
QetGraphicsHeaderItem::m_minimum_section_height
int m_minimum_section_height
Definition: qetgraphicsheaderitem.h:82
QetGraphicsHeaderItem::modelReseted
void modelReseted()
Definition: qetgraphicsheaderitem.cpp:322
QetGraphicsHeaderItem::setModel
void setModel(QAbstractItemModel *model=nullptr)
QetGraphicsHeaderItem::setModel Set the model presented by this item Since QetGraphicsHeaderItem don'...
Definition: qetgraphicsheaderitem.cpp:43
QetGraphicsHeaderItem::QetGraphicsHeaderItem
QetGraphicsHeaderItem(QGraphicsItem *parent=nullptr)
QetGraphicsHeaderItem::QetGraphicsHeaderItem.
Definition: qetgraphicsheaderitem.cpp:32
QETUtils::marginsToString
QString marginsToString(const QMargins &margins)
QETUtils::marginsToString.
Definition: qetutils.cpp:27
QetGraphicsHeaderItem::fromXml
void fromXml(const QDomElement &element)
QetGraphicsHeaderItem::fromXml Restore the header from xml.
Definition: qetgraphicsheaderitem.cpp:224
QetGraphicsHeaderItem::adjustSize
void adjustSize()
QetGraphicsHeaderItem::adjustSize If needed, this function resize the current height and section acco...
Definition: qetgraphicsheaderitem.cpp:298
QetGraphicsHeaderItem::Type
@ Type
Definition: qetgraphicsheaderitem.h:47
QetGraphicsHeaderItem::boundingRect
virtual QRectF boundingRect() const override
QetGraphicsHeaderItem::boundingRect Reimplemented from QGraphicsObject::boundingRect() const;.
Definition: qetgraphicsheaderitem.cpp:80
QetGraphicsHeaderItem::m_minimum_width
int m_minimum_width
Definition: qetgraphicsheaderitem.h:83
qetgraphicsheaderitem.h
QetGraphicsHeaderItem::rect
QRect rect() const
QetGraphicsHeaderItem::rect.
Definition: qetgraphicsheaderitem.cpp:147
qetutils.h
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
QetGraphicsHeaderItem::m_sections_minimum_width
QVector< int > m_sections_minimum_width
Definition: qetgraphicsheaderitem.h:79
QetGraphicsHeaderItem::sectionSize
int sectionSize(int logical_index) const
QetGraphicsHeaderItem::sectionSize.
Definition: qetgraphicsheaderitem.cpp:194
QetGraphicsHeaderItem::heightResized
void heightResized()
qetxml.h
QetGraphicsHeaderItem::m_section_height
int m_section_height
Definition: qetgraphicsheaderitem.h:81
QET::Horizontal
@ Horizontal
Horizontal segment.
Definition: qet.h:89
QetGraphicsHeaderItem::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QetGraphicsHeaderItem::paint Reimplemented from QGraphicsObject::paint(QPainter *painter,...
Definition: qetgraphicsheaderitem.cpp:91
QetGraphicsHeaderItem::model
QAbstractItemModel * model() const
QetGraphicsHeaderItem::model.
Definition: qetgraphicsheaderitem.cpp:71
QetGraphicsHeaderItem::xmlTagName
static QString xmlTagName()
Definition: qetgraphicsheaderitem.h:63