OTB  6.7.0
Orfeo Toolbox
mvdAbstractModel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef mvdAbstractModel_h
23 #define mvdAbstractModel_h
24 
25 //
26 // Configuration include.
28 #include "ConfigureMonteverdi.h"
29 
30 /*****************************************************************************/
31 /* INCLUDE SECTION */
32 
33 //
34 // Qt includes (sorted by alphabetic order)
36 #include <QtCore>
37 
38 //
39 // System includes (sorted by alphabetic order)
40 #include <cassert>
41 
42 //
43 // ITK includes (sorted by alphabetic order)
44 
45 //
46 // OTB includes (sorted by alphabetic order)
47 #include "OTBMonteverdiCoreExport.h"
48 //
49 // Monteverdi includes (sorted by alphabetic order)
50 
51 
52 /*****************************************************************************/
53 /* PRE-DECLARATION SECTION */
54 
55 //
56 // External classes pre-declaration.
57 namespace
58 {
59 }
60 
61 namespace mvd
62 {
63 //
64 // Internal classes pre-declaration.
65 
66 
67 /*****************************************************************************/
68 /* CLASS DEFINITION SECTION */
69 
75 class OTBMonteverdiCore_EXPORT AbstractModel :
76  public QObject
77 {
78 
79  /*-[ QOBJECT SECTION ]-----------------------------------------------------*/
80 
81  Q_OBJECT;
82 
83  /*-[ PUBLIC SECTION ]------------------------------------------------------*/
84 
85 //
86 // Public methods.
87 public:
88 
90  ~AbstractModel() override;
91 
93  template< typename TModel >
94  inline const TModel* GetParentModel() const;
95 
97  template< typename TModel >
98  inline TModel* GetParentModel();
99 
101  template< typename TModel >
102  TModel* newChildModel( void* context =NULL );
103 
105  inline void attachChildModel( AbstractModel* model, void* context =NULL );
106 
108  inline void BuildModel( void* context =NULL );
109 
112  virtual bool IsModified() const;
113 
116  virtual void ClearModified();
117 
120  inline void Save();
121 
122  /*-[ SIGNALS SECTION ]-----------------------------------------------------*/
123 
124 //
125 // Signals.
126 signals:
127 
128  /*-[ PROTECTED SECTION ]---------------------------------------------------*/
129 
130 //
131 // Protected methods.
132 protected:
134  AbstractModel( QObject* p =NULL );
135 
138  virtual void virtual_BuildModel( void* context =NULL );
139 
140 //
141 // Protected attributes.
142 protected:
143 
144  /*-[ PRIVATE SECTION ]-----------------------------------------------------*/
145 
146 //
147 // Private methods.
148 private:
149 
152  virtual void virtual_Save();
153 
154 //
155 // Private attributes.
156 private:
157 
158  /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
159 
160 //
161 // Slots.
162 private slots:
163 };
164 
165 } // end namespace 'mvd'.
166 
167 /*****************************************************************************/
168 /* INLINE SECTION */
169 
170 namespace mvd
171 {
172 
173 /*****************************************************************************/
174 template< typename TModel >
175 const TModel*
178 {
179  return qobject_cast< const TModel* >( parent() );
180 }
181 
182 /*****************************************************************************/
183 template< typename TModel >
184 TModel*
187 {
188  // qDebug()
189  // << "parent:" << parent()
190  // << ";" << qobject_cast< TModel* >( parent() );
191 
192  return qobject_cast< TModel* >( parent() );
193 }
194 
195 /*****************************************************************************/
196 template< typename T >
197 T *
199 ::newChildModel( void * context )
200 {
201  T* model = new T( this );
202 
203  try
204  {
205  attachChildModel( model, context );
206  }
207  catch( ... )
208  {
209  delete model;
210  model = NULL;
211 
212  throw;
213  }
214 
215  return model;
216 }
217 
218 /*****************************************************************************/
219 inline
220 void
222 ::attachChildModel( AbstractModel* model, void* context )
223 {
224  assert( model!=NULL );
225 
226  model->setParent( this );
227  model->BuildModel( context );
228 }
229 
230 /*****************************************************************************/
231 inline
232 void
234 ::BuildModel( void* context )
235 {
236  virtual_BuildModel( context );
237 }
238 
239 /*****************************************************************************/
240 inline
241 void
244 {
245  virtual_Save();
246 
247  ClearModified();
248 }
249 
250 } // end namespace 'mvd'
251 
252 #endif // mvdAbstractModel_h
void BuildModel(void *context=NULL)
const TModel * GetParentModel() const
void attachChildModel(AbstractModel *model, void *context=NULL)
TModel * newChildModel(void *context=NULL)