QElectroTech  0.8-dev
templateview.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 TITLEBLOCK_SLASH_TEMPLATE_VIEW_H
19 #define TITLEBLOCK_SLASH_TEMPLATE_VIEW_H
20 #include <QGraphicsView>
21 #include "titleblocktemplate.h"
22 class HelperCell;
23 class SplittedHelperCell;
26 
32 class TitleBlockTemplateView : public QGraphicsView {
33  Q_OBJECT
34 
35  // constructors, destructor
36  public:
37  TitleBlockTemplateView(QWidget * = nullptr);
38  TitleBlockTemplateView(QGraphicsScene *,
39  QWidget * = nullptr);
40  ~TitleBlockTemplateView() override;
41  private:
43 
44  // methods and slots
45  public:
47  virtual QList<TitleBlockCell *> selectedCells() const;
49  virtual TitleBlockTemplateCellsSet cells(const QRectF &) const;
50  virtual void analyzeSelectedCells(bool *, bool *, int *);
51  virtual QSizeF templateSize() const;
52  virtual qreal templateWidth() const;
53  virtual qreal templateHeight() const;
54 
55  public slots:
57  void selectionChanged();
58  void zoomIn();
59  void zoomOut();
60  void zoomFit();
61  void zoomReset();
62  QList<TitleBlockCell *> cut();
63  QList<TitleBlockCell *> copy();
64  bool mayPaste();
65  QList<TitleBlockCell> pastedCells();
66  void paste();
67  void addColumnAtEnd();
68  void addRowAtEnd();
69  void addColumnBefore();
70  void addRowBefore();
71  void addColumnAfter();
72  void addRowAfter();
73  void editColumn(HelperCell * = nullptr);
74  void editRow(HelperCell * = nullptr);
75  void deleteColumn();
76  void deleteRow();
77  void mergeSelectedCells();
78  void splitSelectedCell();
79  void refresh();
80  void changePreviewWidth();
81  void setPreviewWidth(int);
82  void updateLayout();
83  void rowsDimensionsChanged();
86  void setReadOnly(bool);
87 
88  protected slots:
89  virtual void applyColumnsWidths(bool = true);
90  virtual void applyRowsHeights(bool = true);
91  virtual void updateRowsHelperCells();
92  virtual void updateColumnsHelperCells();
93 
94  protected:
95  void drawBackground(QPainter *, const QRectF &) override;
96  virtual void addCells();
97  virtual void loadTemplate(TitleBlockTemplate *);
98  virtual void init();
99  void wheelEvent(QWheelEvent *) override;
100  virtual qreal zoomFactor() const;
101  virtual void fillWithEmptyCells();
102  bool event(QEvent *) override;
103  virtual void normalizeCells(QList<TitleBlockCell> &,
104  int x = 0,
105  int y = 0) const;
106 
107  signals:
108  void selectedCellsChanged(QList<TitleBlockCell *>);
110  void previewWidthChanged(int, int);
111 
112  private:
113  QList<QAction *> rowsActions() const;
114  QList<QAction *> columnsActions() const;
115  void updateTotalWidthLabel();
117  int lastContextMenuCellIndex() const;
118  int indexOf(QGraphicsLayoutItem *);
119  void removeItem(QGraphicsLayoutItem *);
121  const QList<QGraphicsItem *> &) const;
122  QString makePrettyToolTip(const QString &);
123 
124  private slots:
126  void adjustSceneRect();
127 
128  // attributes
129  private:
131  QGraphicsGridLayout *tbgrid_;
132  QGraphicsWidget *form_;
145  bool read_only_;
146 };
147 #endif
TitleBlockTemplateView::delete_column_
QAction * delete_column_
Definition: templateview.h:139
TitleBlockDimensionWidget::label
QLabel * label() const
Definition: dimensionwidget.cpp:53
TitleBlockTemplateView::cells
virtual TitleBlockTemplateCellsSet cells(const QRectF &) const
Definition: templateview.cpp:442
TitleBlockTemplateView::apply_rows_heights_count_
int apply_rows_heights_count_
Definition: templateview.h:143
TitleBlockTemplateView::pastedCells
QList< TitleBlockCell > pastedCells()
Definition: templateview.cpp:189
GridLayoutAnimation
Definition: gridlayoutanimation.h:26
ModifyTemplateGridCommand::deleteRow
static ModifyTemplateGridCommand * deleteRow(TitleBlockTemplate *, int=-1)
Definition: templatecommands.cpp:267
TitleBlockTemplateView::tbgrid_
QGraphicsGridLayout * tbgrid_
Definition: templateview.h:131
TitleBlockTemplateView::zoomIn
void zoomIn()
Definition: templateview.cpp:106
PasteTemplateCellsCommand
Definition: templatecommands.h:290
TitleBlockTemplateView::zoomOut
void zoomOut()
Definition: templateview.cpp:114
TitleBlockTemplateView::add_column_after_
QAction * add_column_after_
Definition: templateview.h:137
TitleBlockDimension::value
int value
Numeric value.
Definition: dimension.h:34
COL_OFFSET
#define COL_OFFSET
Definition: templateview.cpp:28
QET::Icons::EditTableInsertRowUnder
QIcon EditTableInsertRowUnder
Definition: qeticons.cpp:80
QET::Icons::EditTableDeleteColumn
QIcon EditTableDeleteColumn
Definition: qeticons.cpp:75
ModifyTemplateDimension
Definition: templatecommands.h:140
TitleBlockTemplateView::applyColumnsWidths
virtual void applyColumnsWidths(bool=true)
Definition: templateview.cpp:574
TitleBlockTemplateView::selectedCellsChanged
void selectedCellsChanged(QList< TitleBlockCell * >)
TitleBlockDimension::type
QET::TitleBlockColumnLength type
Kind of length.
Definition: dimension.h:33
TitleBlockTemplateView::selectedCellsSet
virtual TitleBlockTemplateCellsSet selectedCellsSet() const
Definition: templateview.cpp:433
TitleBlockTemplateView::makeCellsSetFromGraphicsItems
TitleBlockTemplateCellsSet makeCellsSetFromGraphicsItems(const QList< QGraphicsItem * > &) const
TitleBlockTemplateView::makeCellsSetFromGraphicsItems.
Definition: templateview.cpp:1073
TitleBlockTemplateView::updateTotalWidthLabel
void updateTotalWidthLabel()
Definition: templateview.cpp:1007
splittedhelpercell.h
TitleBlockTemplateView::add_row_before_
QAction * add_row_before_
Definition: templateview.h:136
TitleBlockCell::num_col
int num_col
x coordinate of the cell within its parent title block template grid
Definition: titleblockcell.h:62
TitleBlockTemplateView::splitSelectedCell
void splitSelectedCell()
Definition: templateview.cpp:406
TitleBlockTemplateView::templateHeight
virtual qreal templateHeight() const
Definition: templateview.cpp:505
TitleBlockDimension::toString
QString toString() const
Definition: dimension.cpp:34
TitleBlockTemplateView::zoomFit
void zoomFit()
Definition: templateview.cpp:122
TitleBlockTemplateView::delete_row_
QAction * delete_row_
Definition: templateview.h:139
TitleBlockTemplateView::addColumnAfter
void addColumnAfter()
Definition: templateview.cpp:304
HelperCell
Definition: helpercell.h:27
TitleBlockTemplateView::add_column_before_
QAction * add_column_before_
Definition: templateview.h:136
DEFAULT_PREVIEW_HELPER_CELL_HEIGHT
#define DEFAULT_PREVIEW_HELPER_CELL_HEIGHT
Definition: templateview.cpp:30
QET::Icons::EditTableInsertColumnLeft
QIcon EditTableInsertColumnLeft
Definition: qeticons.cpp:77
TitleBlockTemplateView
Definition: templateview.h:32
TitleBlockTemplateView::addColumnBefore
void addColumnBefore()
Definition: templateview.cpp:282
TitleBlockCell::loadContentFromXml
void loadContentFromXml(const QDomElement &)
Definition: titleblockcell.cpp:157
SplittedHelperCell
Definition: splittedhelpercell.h:26
TitleBlockTemplateView::addColumnAtEnd
void addColumnAtEnd()
Definition: templateview.cpp:265
TitleBlockTemplateView::makePrettyToolTip
QString makePrettyToolTip(const QString &)
TitleBlockTemplateView::makePrettyToolTip.
Definition: templateview.cpp:1091
TitleBlockTemplateView::first_activation_
bool first_activation_
Boolean used to detect the first display of this widget.
Definition: templateview.h:144
TitleBlockTemplateView::indexOf
int indexOf(QGraphicsLayoutItem *)
Definition: templateview.cpp:1044
TitleBlockTemplateView::refresh
void refresh()
Definition: templateview.cpp:771
TitleBlockTemplateView::apply_columns_widths_count_
int apply_columns_widths_count_
Definition: templateview.h:142
TitleBlockTemplateVisualCell
Definition: templatevisualcell.h:29
gridlayoutanimation.h
TitleBlockTemplateView::columnsActions
QList< QAction * > columnsActions() const
Definition: templateview.cpp:906
TitleBlockTemplateView::templateWidth
virtual qreal templateWidth() const
Definition: templateview.cpp:492
TitleBlockDimension
Definition: dimension.h:26
TitleBlockTemplateView::editRow
void editRow(HelperCell *=nullptr)
Definition: templateview.cpp:353
TitleBlockTemplateView::columnsDimensionsChanged
void columnsDimensionsChanged()
Definition: templateview.cpp:932
TitleBlockTemplateView::applyRowsHeights
virtual void applyRowsHeights(bool=true)
Definition: templateview.cpp:639
TitleBlockTemplateView::mergeSelectedCells
void mergeSelectedCells()
Definition: templateview.cpp:395
TitleBlockTemplateView::~TitleBlockTemplateView
~TitleBlockTemplateView() override
Definition: templateview.cpp:76
SplitCellsCommand::canSplit
static bool canSplit(const TitleBlockTemplateCellsSet &splitted_cells, TitleBlockTemplate *tbtemplate)
Definition: templatecommands.cpp:782
TitleBlockTemplateView::fillWithEmptyCells
virtual void fillWithEmptyCells()
Definition: templateview.cpp:803
TitleBlockTemplate
The TitleBlockTemplate class This class represents an title block template for an electric diagram....
Definition: titleblocktemplate.h:36
templatecommands.h
DEFAULT_COLS_HELPER_CELLS_HEIGHT
#define DEFAULT_COLS_HELPER_CELLS_HEIGHT
Definition: templateview.cpp:31
TitleBlockTemplateView::add_row_after_
QAction * add_row_after_
Definition: templateview.h:137
TitleBlockTemplateView::mayPaste
bool mayPaste()
Definition: templateview.cpp:180
TitleBlockCell::Disabled
@ Disabled
the cell span parameters should not applied at all
Definition: titleblockcell.h:34
qeticons.h
TitleBlockTemplateView::paste
void paste()
Definition: templateview.cpp:238
TitleBlockTemplateView::setTitleBlockTemplate
void setTitleBlockTemplate(TitleBlockTemplate *)
Definition: templateview.cpp:83
TitleBlockTemplateView::lastContextMenuCellIndex
int lastContextMenuCellIndex() const
Definition: templateview.cpp:1033
ModifyTemplateGridCommand::addColumn
static ModifyTemplateGridCommand * addColumn(TitleBlockTemplate *, int=-1)
Definition: templatecommands.cpp:246
TitleBlockDimensionWidget::setValue
void setValue(const TitleBlockDimension &)
Definition: dimensionwidget.cpp:79
TitleBlockTemplateView::zoomReset
void zoomReset()
Definition: templateview.cpp:130
DEFAULT_PREVIEW_WIDTH
#define DEFAULT_PREVIEW_WIDTH
Definition: templateview.cpp:29
TitleBlockTemplateView::TitleBlockTemplateView
TitleBlockTemplateView(QWidget *=nullptr)
Definition: templateview.cpp:40
QET::Absolute
@ Absolute
the length is absolute and should be applied as is
Definition: qet.h:146
TitleBlockTemplateView::updateLayout
void updateLayout()
Definition: templateview.cpp:915
TitleBlockTemplateView::analyzeSelectedCells
virtual void analyzeSelectedCells(bool *, bool *, int *)
TitleBlockTemplateView::analyzeSelectedCells.
Definition: templateview.cpp:457
TitleBlockTemplateView::addRowAfter
void addRowAfter()
Definition: templateview.cpp:315
TitleBlockTemplateView::addCells
virtual void addCells()
Definition: templateview.cpp:703
MergeCellsCommand::canMerge
static bool canMerge(const TitleBlockTemplateCellsSet &, TitleBlockTemplate *)
Definition: templatecommands.cpp:642
TitleBlockCell::col_span
int col_span
number of extra columns spanned by this cell
Definition: titleblockcell.h:64
TitleBlockTemplateView::changePreviewWidth
void changePreviewWidth()
Definition: templateview.cpp:790
TitleBlockTemplateView::total_width_helper_cell_
SplittedHelperCell * total_width_helper_cell_
Definition: templateview.h:134
TitleBlockTemplateView::change_preview_width_
QAction * change_preview_width_
Definition: templateview.h:140
ModifyTemplateGridCommand::addRow
static ModifyTemplateGridCommand * addRow(TitleBlockTemplate *, int=-1)
Definition: templatecommands.cpp:225
templateview.h
templatecellsset.h
TitleBlockTemplateView::updateColumnsHelperCells
virtual void updateColumnsHelperCells()
Definition: templateview.cpp:687
TitleBlockTemplateView::preview_width_
int preview_width_
Definition: templateview.h:133
TitleBlockTemplateView::read_only_
bool read_only_
Boolean stating whether this view allows template edition.
Definition: templateview.h:145
TitleBlockTemplateView::selectionChanged
void selectionChanged()
Definition: templateview.cpp:98
TitleBlockCell::num_row
int num_row
y coordinate of the cell within its parent title block template grid
Definition: titleblockcell.h:61
TitleBlockTemplateView::requestGridModification
void requestGridModification(TitleBlockTemplateCommand *)
Definition: templateview.cpp:1023
MergeCellsCommand
Definition: templatecommands.h:177
TitleBlockTemplateView::init
virtual void init()
Definition: templateview.cpp:542
CutTemplateCellsCommand
Definition: templatecommands.h:265
SplitCellsCommand
Definition: templatecommands.h:211
TitleBlockTemplateView::TitleBlockTemplateView
TitleBlockTemplateView(const TitleBlockTemplateView &)
TitleBlockDimensionWidget::setReadOnly
void setReadOnly(bool)
Definition: dimensionwidget.cpp:101
TitleBlockTemplateView::adjustSceneRect
void adjustSceneRect()
Definition: templateview.cpp:1112
TitleBlockTemplateView::form_
QGraphicsWidget * form_
Definition: templateview.h:132
TitleBlockTemplateView::previewWidthChanged
void previewWidthChanged(int, int)
TitleBlockTemplateView::rowsDimensionsChanged
void rowsDimensionsChanged()
Definition: templateview.cpp:924
TitleBlockTemplateView::addRowAtEnd
void addRowAtEnd()
Definition: templateview.cpp:273
TitleBlockTemplateView::edit_row_dim_
QAction * edit_row_dim_
Definition: templateview.h:138
TitleBlockTemplateView::cut
QList< TitleBlockCell * > cut()
Definition: templateview.cpp:140
TitleBlockTemplateView::gridModificationRequested
void gridModificationRequested(TitleBlockTemplateCommand *)
TitleBlockCell::row_span
int row_span
number of extra rows spanned by this cell
Definition: titleblockcell.h:63
TitleBlockTemplateCellsSet::topLeftCell
TitleBlockTemplateVisualCell * topLeftCell() const
Definition: templatecellsset.cpp:98
helpercell.h
TitleBlockTemplateView::last_context_menu_cell_
HelperCell * last_context_menu_cell_
Definition: templateview.h:141
ROW_OFFSET
#define ROW_OFFSET
Definition: templateview.cpp:27
TitleBlockDimensionWidget::value
TitleBlockDimension value() const
Definition: dimensionwidget.cpp:68
TitleBlockTemplateView::deleteColumn
void deleteColumn()
Definition: templateview.cpp:377
TitleBlockTemplateView::addRowBefore
void addRowBefore()
Definition: templateview.cpp:293
TitleBlockTemplateView::editColumn
void editColumn(HelperCell *=nullptr)
Definition: templateview.cpp:327
QET::Vertical
@ Vertical
Vertical segment.
Definition: qet.h:90
TitleBlockTemplateView::tbtemplate_
TitleBlockTemplate * tbtemplate_
Definition: templateview.h:130
QET::Icons::EditTableInsertRowAbove
QIcon EditTableInsertRowAbove
Definition: qeticons.cpp:79
TitleBlockTemplateView::drawBackground
void drawBackground(QPainter *, const QRectF &) override
Definition: templateview.cpp:418
TitleBlockTemplateView::edit_column_dim_
QAction * edit_column_dim_
Definition: templateview.h:138
QET::attributeIsAnInteger
bool attributeIsAnInteger(const QDomElement &, const QString &, int *=nullptr)
Definition: qet.cpp:210
TitleBlockTemplateView::normalizeCells
virtual void normalizeCells(QList< TitleBlockCell > &, int x=0, int y=0) const
TitleBlockTemplateView::normalizeCells Given a cells list, change their position so the top left one ...
Definition: templateview.cpp:840
TitleBlockTemplateView::rowsActions
QList< QAction * > rowsActions() const
Definition: templateview.cpp:899
TitleBlockTemplateView::titleBlockTemplate
TitleBlockTemplate * titleBlockTemplate() const
Definition: templateview.cpp:91
templatevisualcell.h
TitleBlockTemplateView::wheelEvent
void wheelEvent(QWheelEvent *) override
Definition: templateview.cpp:519
TitleBlockTemplateView::zoomFactor
virtual qreal zoomFactor() const
Definition: templateview.cpp:535
ModifyTemplateGridCommand::deleteColumn
static ModifyTemplateGridCommand * deleteColumn(TitleBlockTemplate *, int=-1)
Definition: templatecommands.cpp:286
QET::Horizontal
@ Horizontal
Horizontal segment.
Definition: qet.h:89
QET::Icons::EditTableInsertColumnRight
QIcon EditTableInsertColumnRight
Definition: qeticons.cpp:78
TitleBlockTemplateView::extra_cells_width_helper_cell_
HelperCell * extra_cells_width_helper_cell_
Definition: templateview.h:135
TitleBlockTemplateView::loadTemplate
virtual void loadTemplate(TitleBlockTemplate *)
Definition: templateview.cpp:863
TitleBlockTemplateView::templateSize
virtual QSizeF templateSize() const
Definition: templateview.cpp:485
TitleBlockTemplateView::event
bool event(QEvent *) override
Definition: templateview.cpp:824
TitleBlockTemplateView::copy
QList< TitleBlockCell * > copy()
Definition: templateview.cpp:156
titleblocktemplate.h
TitleBlockTemplateView::setReadOnly
void setReadOnly(bool)
Definition: templateview.cpp:975
TitleBlockTemplateView::updateRowsHelperCells
virtual void updateRowsHelperCells()
Definition: templateview.cpp:672
TitleBlockTemplateView::deleteRow
void deleteRow()
Definition: templateview.cpp:386
TitleBlockTemplateView::updateDisplayedMinMaxWidth
void updateDisplayedMinMaxWidth()
Definition: templateview.cpp:940
TitleBlockTemplateCommand
Definition: templatecommands.h:66
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
TitleBlockDimensionWidget
Definition: dimensionwidget.h:27
DEFAULT_ROWS_HELPER_CELLS_WIDTH
#define DEFAULT_ROWS_HELPER_CELLS_WIDTH
Definition: templateview.cpp:32
TitleBlockTemplateCellsSet
Definition: templatecellsset.h:28
TitleBlockCell
Definition: titleblockcell.h:26
TitleBlockTemplateView::removeItem
void removeItem(QGraphicsLayoutItem *)
Definition: templateview.cpp:1055
TitleBlockTemplateView::selectedCells
virtual QList< TitleBlockCell * > selectedCells() const
Definition: templateview.cpp:426
TitleBlockTemplateView::updateLastContextMenuCell
void updateLastContextMenuCell(HelperCell *)
Definition: templateview.cpp:1105
TitleBlockTemplateView::setPreviewWidth
void setPreviewWidth(int)
Definition: templateview.cpp:991
dimensionwidget.h
QET::Icons::EditTableDeleteRow
QIcon EditTableDeleteRow
Definition: qeticons.cpp:76