otbWrapperQtWidgetView.h 5.08 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
#ifndef otbWrapperQtWidgetView_h
#define otbWrapperQtWidgetView_h
23

24
#include <QtWidgets>
25 26 27 28

//
// OTB includes (sorted by alphabetic order)
#include "otbWrapperApplication.h"
29
#include "otbWrapperQtWidgetModel.h"
30
#include "OTBQtWidgetExport.h"
31 32 33 34 35 36

namespace otb
{
namespace Wrapper
{

37 38 39 40 41
/*****************************************************************************/
/* CLASS DEFINITION SECTION                                                  */

/**
 * \class QtWidgetView
42 43
 *
 * \ingroup OTBQtWidget
44 45
 *
 * \brief WIP.
46
 */
47 48 49

class OTBQtWidget_EXPORT QtWidgetView :
    public QWidget
50
{
51 52
  /*-[ QOBJECT SECTION ]-----------------------------------------------------*/

53
  Q_OBJECT
54 55 56 57 58 59 60 61 62

  Q_PROPERTY( bool isClosable
	      READ IsClosable
	      WRITE SetClosable );

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

//
// Public methods.
63 64
public:

65 66 67 68 69 70
  /**
   */
  static char const * const OBJECT_NAME;

  /** \brief Constructor. */
  QtWidgetView( const otb::Wrapper::Application::Pointer & otbApp,
71
		QWidget* parent,
72 73 74
		Qt::WindowFlags flags =0 );

  /** \brief Destructor. */
75
  ~QtWidgetView() override;
76

77
  /** \brief Gui Creation. */
78 79
  void CreateGui();

80 81
  /** \brief Model Accessor */
  inline otb::Wrapper::QtWidgetModel* GetModel()
82
  {
83
    return m_Model;
84 85
  }

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  /**
   * \return The OTB-application pointer of this view.
   */
  //~ otb::Wrapper::Application::ConstPointer GetApplication() const
  //~ {
    //~ return otb::ConstCast< otb::Wrapper::Application >(
      //~ m_Application
    //~ );
  //~ }

  /**
   */
  inline bool IsClosable() const;

  /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/

//
// Public SLOTS.
104 105
public slots:

106
  /*-[ SIGNALS SECTION ]-----------------------------------------------------*/
107

108 109
//
// Signals.
110 111
signals:
  void QuitSignal();
112 113
  void ExecuteAndWriteOutput();
  void Stop();
114

115

116 117 118 119 120 121
  /*-[ PROTECTED SECTION ]---------------------------------------------------*/

//
// Protected methods.
protected:

122 123 124 125
  bool IsRunning();

  virtual QWidget* CreateInputWidgets();

126 127 128 129 130 131 132 133 134 135 136
  //
  // QWidget overloads.

  void closeEvent( QCloseEvent * event ) override;

//
// Protected attributes.
protected:

  /** Html section for 'Done' icon */
  std::string m_IconPathDone;
137

138 139
  /** Html section for 'Failed' icon */
  std::string m_IconPathFailed;
140 141 142 143 144 145 146 147 148

protected slots:

  /**
   */
  void OnExecButtonClicked();

  void UnhandledException(QString message);
  void OnExceptionRaised( QString what );
149 150
  
  /*-[ PRIVATE SECTION ]-----------------------------------------------------*/
151

152 153
//
// Private methods.
154
private:
155

156 157 158 159 160
  QtWidgetView(const QtWidgetView&); //purposely not implemented
  void operator=(const QtWidgetView&); //purposely not implemented

  QWidget* CreateFooter();

Cyrille Valladeau's avatar
Cyrille Valladeau committed
161 162
  QWidget* CreateDoc();

163

164 165
//
// Private attributes.
166

167 168 169
private:

  otb::Wrapper::QtWidgetModel* m_Model;
170

171 172
  QPushButton* m_ExecButton;
  QPushButton* m_QuitButton;
173
  QShortcut* m_QuitShortcut;
174
  QLabel* m_Message;
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
  QTextEdit *m_LogText;
  QTabWidget *m_TabWidget;

  bool m_IsClosable : 1;

  bool m_IsRunning;

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

//
// Slots.
private slots:
  void UpdateMessageAfterExecution(int status);
  void UpdateMessageAfterApplicationReady(bool val);

  /**
   */
  inline void OnProgressReportBegin();

  /**
   */
  inline void OnProgressReportEnd( int status );

  /**
   */
  inline void SetClosable( bool );

202 203
};

204
} // end namespace 'Wrapper'
205

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
} // end namespace 'otb'

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

namespace otb
{

namespace Wrapper
{

/*****************************************************************************/
inline
bool
QtWidgetView
::IsClosable() const
{
  return m_IsClosable;
224
}
225 226 227 228 229 230 231 232 233 234 235 236 237

/*****************************************************************************/
inline
void
QtWidgetView
::SetClosable( bool enabled )
{
  m_IsClosable = enabled;

  setEnabled( true );

  if( m_QuitButton!=NULL )
    m_QuitButton->setEnabled( m_IsClosable );
238 239
}

240 241 242 243 244 245 246
/*******************************************************************************/
inline
void
QtWidgetView
::OnProgressReportBegin()
{
  SetClosable( false );
247
}
248 249 250 251 252 253 254 255

/*******************************************************************************/
inline
void
QtWidgetView
::OnProgressReportEnd( int )
{
  SetClosable( true );
256 257
}

258 259 260 261
} // end namespace 'Wrapper'

} // end namespace 'otb'

262
#endif