mvdI18nMainWindow.h 8.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20 21


22 23
#ifndef mvdI18nMainWindow_h
#define mvdI18nMainWindow_h
24 25 26 27

//
// Configuration include.
//// Included at first position before any other ones.
28
#include "ConfigureMonteverdi.h"
29 30 31 32 33 34 35

/*****************************************************************************/
/* INCLUDE SECTION                                                           */

//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
36
#include <QtWidgets>
37 38 39 40 41 42 43 44 45

//
// System includes (sorted by alphabetic order)

//
// ITK includes (sorted by alphabetic order)

//
// OTB includes (sorted by alphabetic order)
46
#include "OTBMonteverdiGUIExport.h"
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//
// Monteverdi includes (sorted by alphabetic order)


/*****************************************************************************/
/* PRE-DECLARATION SECTION                                                   */

//
// External class pre-declaration.
namespace
{
}

namespace mvd
{
//
// Internal class pre-declaration.
class AbstractModel;
65
class AbstractModelController;
66
class AbstractWorker;
67
class DatasetModel;
68
class VectorImageModel;
69 70 71 72 73

/*****************************************************************************/
/* CLASS DEFINITION SECTION                                                  */

/**
74
 * \class I18nMainWindow
75
 *
76
 * \ingroup OTBMonteverdiGUI
77
*
78 79
 * \brief Main-window widget base for the i18n application.
 */
80
class OTBMonteverdiGUI_EXPORT I18nMainWindow
81 82 83 84 85 86 87 88
  : public QMainWindow
{

  /*-[ QOBJECT SECTION ]-----------------------------------------------------*/

  Q_OBJECT;

  /*-[ PUBLIC SECTION ]------------------------------------------------------*/
89

90 91 92
//
// Public types.
public:
93 94 95 96 97 98 99 100
  enum DockLayout
  {
    DOCK_LAYOUT_NONE = 0,
    DOCK_LAYOUT_FLOATING = 1,
    DOCK_LAYOUT_SCROLLABLE = 2,
  };

  typedef QFlags< DockLayout > DockLayoutFlags;
101 102 103 104 105

//
// Public methods.
public:
  /** \brief Destructor. */
106
  ~I18nMainWindow() ITK_OVERRIDE;
107 108 109 110 111 112 113 114 115 116

  /**
   */
  void Initialize();

  /*-[ SIGNALS SECTION ]-----------------------------------------------------*/

//
// SIGNALS.
signals:
117

118 119 120 121 122
  /*-[ PROTECTED SECTION ]---------------------------------------------------*/

//
// Protected methods.
protected:
123

124 125 126 127 128
  /** \brief Constructor. */
  I18nMainWindow( QWidget* Parent =0, Qt::WindowFlags flags =0 );

  /**
   */
129 130 131 132 133
  QDockWidget*
    AddWidgetToDock( QWidget* widget,
		     const QString& dockName,
		     const QString& dockTitle,
		     Qt::DockWidgetArea dockArea,
134
		     DockLayoutFlags flags = DOCK_LAYOUT_NONE );
135 136 137

  /**
   */
138 139 140 141 142 143
  template< typename TWidget, typename TDockWidget >
    inline
    TDockWidget*
    AddDockWidget( const QString& dockName,
		   const QString& dockTitle,
		   Qt::DockWidgetArea dockArea,
144
		   DockLayoutFlags flags = DOCK_LAYOUT_NONE );
145

146 147 148
  /**
   */
  template< typename TWidget, typename TController, typename TDockWidget >
149
    inline
150 151 152
    TDockWidget*
    AddDockWidget( const QString& dockName,
		   const QString& dockTitle,
153
		   Qt::DockWidgetArea dockArea,
154
		   DockLayoutFlags flags = DOCK_LAYOUT_NONE );
155 156
  /**
   */
157
  const AbstractModelController *
158 159 160 161 162
    GetController( const QDockWidget * ) const;
  /**
   */
  AbstractModelController *
    GetController( const QDockWidget * );
163 164 165 166 167 168 169 170 171 172 173 174

  /**
   * \brief Assign model to the controller which is child of given
   * dock-widget.
   *
   * \param dock The dock-widget which is parent of the controller to
   * assign model to.
   *
   * \param model The model to assign to the controller.
   */
  inline void SetControllerModel( QDockWidget* dock, AbstractModel* model );

175 176 177 178 179 180
  /**
   */
  VectorImageModel *
    ImportImage( const QString & filename,
                 int width,
                 int height );
181

182 183
  /**
   */
184
  bool BuildGDALOverviews( const QStringList & filenames );
185

186 187
  /**
   */
188
  void SaveLayout( int version ) const;
189 190 191

  /**
   */
192
  bool RestoreLayout( int version );
193

194
  //
195
  // QMainWindow methods.
196

197
  void closeEvent( QCloseEvent* event ) ITK_OVERRIDE;
198 199 200 201 202

//
// Protected attributes.
protected:

203 204 205
  /*-[ PROTECTED SLOTS SECTION ]---------------------------------------------*/

//
206
// Protected slots.
207 208 209 210 211 212 213 214 215 216
protected slots:

  /**
   */
  virtual void OnAboutToChangeModel( const AbstractModel* ) =0;

  /**
   */
  virtual void OnModelChanged( AbstractModel* ) =0;

217 218 219 220 221 222 223 224 225 226
  /*-[ PRIVATE SECTION ]-----------------------------------------------------*/

//
// Private nested classes.
private:


//
// Private methods.
private:
227 228
  /**
   */
229
  QObject * Import( AbstractWorker * );
230 231 232

  /**
   */
233 234 235 236 237
  virtual void virtual_SetupUI() =0;

  /**
   */
  virtual void virtual_ConnectUI() =0;
238

239 240 241 242
  /**
   */
  virtual void virtual_InitializeUI();

243 244
  /**
   */
245

246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
//
// Private attributes.
private:

  /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/

//
// Private slots.
private slots:

  /**
   * \brief Qt auto-connected slot which is called when File/Quit menu
   * action is activated.
   */
  void on_action_Quit_triggered();

  /**
   * \brief Qt auto-connected slot which is called when Help/About
   * menu action is activated.
   */
266
  virtual void on_action_About_triggered();
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286

};

} // end namespace 'mvd'

/*****************************************************************************/
/* INLINE SECTION                                                            */

//
// System includes (sorted by alphabetic order)
#include <cassert>

//
// ITK includes (sorted by alphabetic order)

//
// OTB includes (sorted by alphabetic order)

//
// Monteverdi includes (sorted by alphabetic order)
287
#include "mvdAbstractModelController.h"
288 289 290 291

namespace mvd
{

292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
/*****************************************************************************/
inline
const AbstractModelController *
I18nMainWindow
::GetController( const QDockWidget * dock ) const
{
  assert( dock!=NULL );

  return dock->findChild< const AbstractModelController * >();
}

/*****************************************************************************/
inline
AbstractModelController *
I18nMainWindow
::GetController( const QDockWidget * dock )
{
  assert( dock!=NULL );

  return dock->findChild< AbstractModelController * >();
}

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
/*****************************************************************************/
inline
void
I18nMainWindow
::SetControllerModel( QDockWidget* dock, AbstractModel* model )
{
  assert( dock );

  AbstractModelController* controller =
    dock->findChild< AbstractModelController* >();

  assert( controller!=NULL );

  controller->SetModel( model );
}

330 331 332 333 334
/*****************************************************************************/
template< typename TWidget, typename TDockWidget >
inline
TDockWidget*
I18nMainWindow
335 336
::AddDockWidget( const QString & dockName,
		 const QString & dockTitle,
337
		 Qt::DockWidgetArea dockArea,
338
		 DockLayoutFlags flags )
339
{
340
  TWidget * widget = new TWidget( this );
341

342
  TDockWidget * dockWidget =
343 344 345 346 347
    AddWidgetToDock(
      widget,
      dockName,
      dockTitle,
      dockArea,
348
      flags
349 350 351 352 353
    );

  return dockWidget;
}

354 355
/*****************************************************************************/
template< typename TWidget, typename TController, typename TDockWidget >
356
inline
357 358
TDockWidget*
I18nMainWindow
359 360
::AddDockWidget( const QString & dockName,
		 const QString & dockTitle,
361
		 Qt::DockWidgetArea dockArea,
362
		 DockLayoutFlags flags )
363
{
364 365 366 367 368 369 370 371 372
  TWidget * widget = new TWidget( this );

  QWidget * pannel = widget;

  if( flags.testFlag( DOCK_LAYOUT_SCROLLABLE ) )
    {
    QScrollArea * scrollArea = new QScrollArea( this );

    scrollArea->setWidgetResizable( true );
373

374 375 376 377 378 379 380
    scrollArea->setWidget( widget );

    pannel = scrollArea;
    }


  TDockWidget * dockWidget =
381
    AddWidgetToDock(
382
      pannel,
383 384
      dockName,
      dockTitle,
385
      dockArea,
386
      flags
387 388
    );

389 390 391 392 393 394
  new TController(
    // wraps:
    widget,
    // as chid of:
    dockWidget
  );
395 396 397 398

  return dockWidget;
}

399 400
} // end namespace 'mvd'

401
#endif // I18nMainWindow_h