mvdMaplaMainWindow.cxx 6.2 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
#include "mvdMaplaMainWindow.h"
#include "ui_mvdMaplaMainWindow.h"
24 25 26 27 28 29 30 31


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

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

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

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

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

//
// Monteverdi includes (sorted by alphabetic order)
45
#ifdef OTB_USE_QT4
46 47 48
# include "mvdApplicationLauncher.h"
# include "mvdApplicationsToolBoxController.h"
# include "mvdOTBApplicationsModel.h"
49
# if 1
50
#   include "mvdQtWidgetView.h"
51 52 53
# else
#   include "otbWrappperQtWidgetView.h"
# endif
54 55
#endif
//
56
#include "mvdApplicationsToolBox.h"
57
//
58
#include "mvdMaplaApplication.h"
59 60 61 62 63 64
// #include "mvdPreferencesDialog.h"

namespace mvd
{

/*
65
  TRANSLATOR mvd::MaplaMainWindow
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

  Necessary for lupdate to be aware of C++ namespaces.

  Context comment for translator.
*/


/*****************************************************************************/
/* CONSTANTS                                                                 */


/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION                                             */


/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION                                              */

/*****************************************************************************/
85
MaplaMainWindow
86 87
::MaplaMainWindow( QWidget * p, Qt::WindowFlags flags ) :
  I18nMainWindow( p, flags ),
88
  m_UI( new mvd::Ui::MaplaMainWindow() )
89
#ifdef OTB_USE_QT4
90 91 92 93 94 95 96 97
  ,
  m_ApplicationsToolBoxController( NULL )
#endif
{
  m_UI->setupUi( this );
}

/*****************************************************************************/
98 99
MaplaMainWindow
::~MaplaMainWindow()
100 101 102 103 104 105 106
{
  delete m_UI;
  m_UI = NULL;
}

/*****************************************************************************/
void
107
MaplaMainWindow
108 109
::virtual_SetupUI()
{
110
  setObjectName( "Mapla" );
111
  setWindowTitle( PROJECT_NAME " Application Launcher" );
112

113
#ifdef OTB_USE_QT4
114 115 116 117 118 119 120 121 122

  assert( m_ApplicationsToolBoxController==NULL );

  m_ApplicationsToolBoxController =
    new ApplicationsToolBoxController(
      new ApplicationsToolBox( this ),
      this
    );

123
  assert( MaplaApplication::Instance() );
124

125 126
  setCentralWidget( m_ApplicationsToolBoxController->GetWidget() );

127
#else // OTB_USE_QT4
128 129 130

  setCentralWidget(
    new QLabel(
131
      tr( "Enable OTB_USE_QT4 preprocessor definition at compile time!" ),
132 133 134 135
      this
    )
  );

136
#endif // OTB_USE_QT4
137 138 139 140 141

  if( !RestoreLayout( Monteverdi_UI_VERSION ) )
    {
    qWarning() << "Failed to restore window layout!";
    }
142 143 144 145
}

/*****************************************************************************/
void
146
MaplaMainWindow
147 148 149 150
::virtual_ConnectUI()
{
  //
  // OTB application support.
151
#ifdef OTB_USE_QT4
152 153 154 155 156 157 158 159 160 161 162 163 164 165

  QObject::connect(
    m_ApplicationsToolBoxController->GetWidget(),
    SIGNAL( ApplicationToLaunchSelected( const QString &, const QString & ) ),
    // to:
    this,
    SLOT( OnApplicationToLaunchSelected(const QString &, const QString & ) )
  );

#endif
}

/*****************************************************************************/
void
166
MaplaMainWindow
167
::closeEvent( QCloseEvent* e )
168
{
169
  assert( MaplaApplication::Instance() );
170
  assert(
171 172
    MaplaApplication::Instance()->GetModel()==
    MaplaApplication::Instance()->GetModel< OTBApplicationsModel >()
173 174
  );

175 176
  SaveLayout( Monteverdi_UI_VERSION );

177
  I18nMainWindow::closeEvent( e );
178 179 180 181 182 183
}

/*****************************************************************************/
/* SLOTS                                                                     */
/*****************************************************************************/
void
184
MaplaMainWindow
185
::on_action_Preferences_triggered()
186 187 188 189 190 191 192 193 194 195
{
#if 0
  PreferencesDialog prefDialog( this );

  prefDialog.exec();
#endif
}

/*****************************************************************************/
void
196
MaplaMainWindow
197
::OnAboutToChangeModel( const AbstractModel * )
198
{
199
  // qDebug() << this << "::OnAboutToChangeModel(" << model << ")";
200 201

  m_ApplicationsToolBoxController->SetModel( NULL );
202 203 204 205
}

/*****************************************************************************/
void
206
MaplaMainWindow
207 208
::OnModelChanged( AbstractModel* model )
{
209
  // qDebug() << this << "::OnModelChanged(" << model << ")";
210 211

  m_ApplicationsToolBoxController->SetModel( model );
212 213 214 215
}

/*****************************************************************************/
void
216
MaplaMainWindow
217 218
::OnApplicationToLaunchSelected( const QString & appName,
				 const QString & )
219
{
220
#ifdef OTB_USE_QT4
221

222 223
  assert( MaplaApplication::ConstInstance()!=NULL );
  assert( MaplaApplication::ConstInstance()->GetModel()!=NULL );
224
  assert(
225 226
    MaplaApplication::ConstInstance()->GetModel()==
    MaplaApplication::ConstInstance()->GetModel< OTBApplicationsModel >()
227
  );
228
  assert(
229
    MaplaApplication::ConstInstance()
230 231
    ->GetModel< OTBApplicationsModel >()
    ->GetLauncher()!=NULL
232 233
  );

234
  QWidget * appWindow =
235
    MaplaApplication::ConstInstance()
236
    ->GetModel< OTBApplicationsModel >()
237
    ->GetLauncher()
238
    ->NewOtbApplicationWindow( appName, true, this );
239

240
  assert( appWindow!=NULL );
241

242
  appWindow->show();
243

244
#endif // OTB_USE_QT4
245 246 247 248
}

/*****************************************************************************/
void
249
MaplaMainWindow
250 251 252 253 254 255 256
::OnExecutionDone( int status )
{
  if( status<0 )
    return;
}

} // end namespace 'mvd'