Fraxinus  16.5.0-fx-rc4
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxLayoutData.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXLAYOUTDATA_H_
34 #define CXLAYOUTDATA_H_
35 
36 #include "cxResourceVisualizationExport.h"
37 
38 #include <vector>
39 class QDomNode;
40 #include <QString>
41 #include "cxDefinitions.h"
42 #include "cxForwardDeclarations.h"
43 #include "cxView.h"
44 
45 namespace cx
46 {
53 struct cxResourceVisualization_EXPORT LayoutPosition
54 {
55  LayoutPosition() : row(0), col(0) {}
56  LayoutPosition(int r, int c) : row(r), col(c) {}
57  int row;
58  int col;
59 };
60 
61 struct cxResourceVisualization_EXPORT LayoutRegion
62 {
64  LayoutRegion(int r, int c, int rSpan = 1, int cSpan = 1) :
65  pos(r, c), span(rSpan, cSpan) {}
68 
69  bool contains(LayoutPosition p) const
70  {
71  return pos.row <= p.row && p.row < pos.row + span.row && pos.col <= p.col && p.col < pos.col + span.col;
72  }
73 };
74 
75 cxResourceVisualization_EXPORT LayoutRegion merge(LayoutRegion a, LayoutRegion b);
76 
80 {
81  LayoutViewData() : mGroup(-1), mPlane(ptCOUNT), mType(View::VIEW), mRegion(-1, -1, 1, 1) {}
82  LayoutViewData(int row, int col, int rowSpan = 1, int colSpan = 1) :
83  mGroup(-1), mPlane(ptCOUNT), mType(View::VIEW), mRegion(row, col, rowSpan, colSpan) {}
84  int mGroup;
85  PLANE_TYPE mPlane;
88 
89  void addXml(QDomNode node) const;
90  void parseXml(QDomNode node);
91  bool isValid() const { return (( mGroup>=0 )&&( mPlane!=ptCOUNT )); }
92 };
93 
97 class cxResourceVisualization_EXPORT LayoutData
98 {
99 public:
100  typedef std::vector<LayoutViewData> ViewDataContainer;
101  typedef ViewDataContainer::iterator iterator;
102  typedef ViewDataContainer::const_iterator const_iterator;
103 
104 public:
105  static LayoutData createHeader(QString uid, QString name);
106  static LayoutData create(QString uid, QString name, int rows, int cols);
107  LayoutData();
108  QString getUid() const { return mUid; }
109  QString getName() const { return mName; }
110  void setName(const QString& name) { mName = name; }
111  void resetUid(const QString& uid);
112  void setView(int group, PLANE_TYPE type, LayoutRegion region);
113  void setView(int group, View::Type type, LayoutRegion region);
114  LayoutViewData& get(LayoutPosition pos);
115  iterator begin() { return mView.begin(); }
116  iterator end() { return mView.end(); }
117  const_iterator begin() const { return mView.begin(); }
118  const_iterator end() const { return mView.end(); }
119  iterator find(LayoutPosition pos);
120  bool isEmpty() const { return mSize.col == 0 || mSize.row == 0; }
121 
122  void split(iterator iter);
123  void split(LayoutRegion region);
124  bool merge(LayoutRegion region);
125  void resize(int rows, int cols);
126  LayoutPosition size() const { return mSize; }
127 
128  void addXml(QDomNode node) const;
129  void parseXml(QDomNode node);
130 
131 private:
132  QString mUid;
133  QString mName;
134  LayoutPosition mSize;
135  std::vector<LayoutViewData> mView;
136 };
137 
141 } // namespace cx
142 
143 #endif /* CXLAYOUTDATA_H_ */
int mGroup
what group to connect to. -1 means not set.
Definition: cxLayoutData.h:84
LayoutPosition(int r, int c)
Definition: cxLayoutData.h:56
std::vector< LayoutViewData > ViewDataContainer
Definition: cxLayoutData.h:100
ViewDataContainer::iterator iterator
Definition: cxLayoutData.h:101
bool contains(LayoutPosition p) const
Definition: cxLayoutData.h:69
LayoutRegion(int r, int c, int rSpan=1, int cSpan=1)
Definition: cxLayoutData.h:64
LayoutPosition span
size of region
Definition: cxLayoutData.h:67
QString getUid() const
Definition: cxLayoutData.h:108
iterator begin()
Definition: cxLayoutData.h:115
bool isValid() const
Definition: cxLayoutData.h:91
void setName(const QString &name)
Definition: cxLayoutData.h:110
LayoutViewData(int row, int col, int rowSpan=1, int colSpan=1)
Definition: cxLayoutData.h:82
void parseXml(QDomNode node)
load state from xml
PLANE_TYPE mPlane
ptNOPLANE means 3D
Definition: cxLayoutData.h:85
LayoutRegion mRegion
Definition: cxLayoutData.h:87
const_iterator begin() const
Definition: cxLayoutData.h:117
LayoutPosition size() const
Definition: cxLayoutData.h:126
QString getName() const
Definition: cxLayoutData.h:109
LayoutPosition pos
start position of region
Definition: cxLayoutData.h:66
ViewDataContainer::const_iterator const_iterator
Definition: cxLayoutData.h:102
void addXml(QDomNode node) const
save state to xml
const_iterator end() const
Definition: cxLayoutData.h:118
iterator end()
Definition: cxLayoutData.h:116
View::Type mType
Definition: cxLayoutData.h:86
LayoutRegion merge(LayoutRegion a, LayoutRegion b)
bool isEmpty() const
Definition: cxLayoutData.h:120