QElectroTech  0.70
templatecellsset.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 #include "templatecellsset.h"
19 #include "templatevisualcell.h"
20 #include "templateview.h"
21 #include "titleblockcell.h"
22 
28  parent_view_(parent_view)
29 {
30 }
31 
37  QList<TitleBlockTemplateVisualCell *>(copy),
38  parent_view_(copy.parent_view_)
39 {
40 }
41 
46 }
47 
52  QPainterPath cells_path;
53  foreach (TitleBlockTemplateVisualCell *cell, *this) {
54  cells_path.addRect(cell -> geometry());
55  }
56  return(cells_path);
57 }
58 
64  if (!count()) return(false);
65  if (count() == 1) return(true);
66 
67  QPolygonF points = painterPath().simplified().toFillPolygon();
68  if (points.isClosed()) points.pop_back();
69 
70  return(points.count() == 4 || points.count() == 5);
71 }
72 
77  foreach (TitleBlockTemplateVisualCell *cell, *this) {
78  if (!cell -> isSelected()) {
79  return(false);
80  }
81  }
82  return(true);
83 }
84 
90  // fetches all cells concerned by this set
91  QSet<TitleBlockCell *> all_cells = cells(true);
92 
93  // look for cells spanned by cells that do not belong to this set
94  foreach (TitleBlockCell *cell, all_cells) {
95  if (cell -> spanner_cell && !all_cells.contains(cell -> spanner_cell)) {
96  return(true);
97  }
98  }
99  return(false);
100 }
101 
106  if (empty()) return(nullptr);
107  if (count() == 1) return(first());
108 
109  // look for cells at the top
110  QMultiMap<int, TitleBlockTemplateVisualCell *> top_cells;
111  foreach (TitleBlockTemplateVisualCell *cell_view, *this) {
112  if (TitleBlockCell *cell = cell_view -> cell()) {
113  top_cells.insertMulti(cell -> num_row, cell_view);
114  }
115  }
116  QList<TitleBlockTemplateVisualCell *> candidates = top_cells.values(top_cells.keys().first());
117  if (candidates.count() == 1) return(candidates.first());
118 
119  // look for the cell at the left
120  int lowest_num_col = 100000;
121  TitleBlockTemplateVisualCell *candidate = nullptr;
122  foreach (TitleBlockTemplateVisualCell *cell_view, candidates) {
123  if (TitleBlockCell *cell = cell_view -> cell()) {
124  if (cell -> num_col < lowest_num_col) {
125  lowest_num_col = cell -> num_col;
126  candidate = cell_view;
127  }
128  }
129  }
130  return(candidate);
131 }
132 
137  if (empty()) return(nullptr);
138  if (count() == 1) return(first());
139 
140  // look for cells at the bottom
141  QMultiMap<qreal, TitleBlockTemplateVisualCell *> bottom_cells;
142  foreach (TitleBlockTemplateVisualCell *cell_view, *this) {
143  bottom_cells.insertMulti(cell_view -> geometry().bottom(), cell_view);
144  }
145  QList<TitleBlockTemplateVisualCell *> candidates = bottom_cells.values(bottom_cells.keys().last());
146  if (candidates.count() == 1) return(candidates.first());
147 
148  // look for the cell at the right
149  qreal highest_right = -100000;
150  TitleBlockTemplateVisualCell *candidate = nullptr;
151  foreach (TitleBlockTemplateVisualCell *cell_view, candidates) {
152  qreal right = cell_view -> geometry().right();
153  if (right > highest_right) {
154  highest_right = right;
155  candidate = cell_view;
156  }
157  }
158  return(candidate);
159 }
160 
166  QRectF merge_area;
167  if (!parent_view_) return(merge_area);
168 
169  TitleBlockTemplateVisualCell *top_left_cell = topLeftCell();
170  if (!top_left_cell) return(merge_area);
171  TitleBlockTemplateVisualCell *bottom_right_cell = bottomRightCell();
172  if (!bottom_right_cell) return(merge_area);
173 
174  merge_area.setTopLeft(top_left_cell -> geometry().topLeft());
175  merge_area.setBottomRight(bottom_right_cell -> geometry().bottomRight());
176  return(merge_area);
177 }
178 
186  if (!parent_view_) return(merge_area);
187 
188  QRectF merge_area_rect = rect.isNull() ? mergeAreaRect() : rect;
189 
190  merge_area = parent_view_ -> cells(merge_area_rect);
191  return(merge_area);
192 }
193 
198 QSet<TitleBlockCell *> TitleBlockTemplateCellsSet::cells(bool include_spanned) const {
199  QSet<TitleBlockCell *> set;
200  foreach (TitleBlockTemplateVisualCell *cell_view, *this) {
201  if (TitleBlockCell *cell = cell_view -> cell()) {
202  if (include_spanned) {
203  foreach (TitleBlockCell *cell, cell_view -> cells()) {
204  set << cell;
205  }
206  } else {
207  set << cell;
208  }
209  }
210  }
211  return(set);
212 }
QPainterPath painterPath() const
TitleBlockTemplateCellsSet(const TitleBlockTemplateView *)
TitleBlockTemplateCellsSet mergeArea(const QRectF &=QRectF()) const
QSet< TitleBlockCell * > cells(bool=true) const
const TitleBlockTemplateView * parent_view_
the view displaying the cells
TitleBlockTemplateVisualCell * topLeftCell() const
TitleBlockTemplateVisualCell * bottomRightCell() const