otbWrapperQtWidgetView.cxx 5.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "otbWrapperQtWidgetView.h"

#include "otbWrapperQtWidgetParameterGroup.h"
Julien Malik's avatar
Julien Malik committed
21
#include "otbWrapperQtWidgetParameterFactory.h"
22
#include "otbWrapperQtWidgetProgressReport.h"
23
#include "otbWrapperOutputImageParameter.h"
24
#include "otbWrapperChoiceParameter.h"
25
#include "otbWrapperQtWidgetSimpleProgressReport.h"
26
#include "otbWrapperApplicationHtmlDocGenerator.h"
27

28 29
#include "itksys/SystemTools.hxx"

30 31 32 33 34 35 36 37
namespace otb
{
namespace Wrapper
{

QtWidgetView::QtWidgetView(Application* app)
{
  m_Model = new QtWidgetModel(app);
38
  m_Application = app;
39 40 41 42
}

QtWidgetView::~QtWidgetView()
{
43
  delete m_Model;
44 45 46 47 48
}

void QtWidgetView::CreateGui()
{
  // Create a VBoxLayout with the header, the input widgets, and the footer
Cyrille Valladeau's avatar
Cyrille Valladeau committed
49
  QVBoxLayout *mainLayout = new QVBoxLayout();
50
  m_TabWidget = new QTabWidget();
51

52 53 54 55
  m_TabWidget->addTab(CreateInputWidgets(), "Parameters");
  m_LogText = new QTextEdit();
  connect( m_Model->GetLogOutput(), SIGNAL(NewContentLog(QString)), m_LogText, SLOT(append(QString) ) );
  m_TabWidget->addTab(m_LogText, "Logs");
56 57
  QtWidgetProgressReport* prog =  new QtWidgetProgressReport(m_Model);
  prog->SetApplication(m_Application);
58 59 60
  m_TabWidget->addTab(prog, "Progress");
  m_TabWidget->addTab(CreateDoc(), "Documentation");
  mainLayout->addWidget(m_TabWidget);
61

Cyrille Valladeau's avatar
Cyrille Valladeau committed
62 63 64 65
  m_Message = new QLabel("<center><font color=\"#FF0000\">Select parameters</font></center>");
  connect( m_Model, SIGNAL(SetApplicationReady(bool)), this, SLOT(UpdateMessageAfterApplicationReady(bool)) );
  mainLayout->addWidget(m_Message);

66 67
  QtWidgetSimpleProgressReport * progressReport =  new QtWidgetSimpleProgressReport(m_Model);
  progressReport->SetApplication(m_Application);
68

69 70 71 72
  QHBoxLayout *footLayout = new QHBoxLayout;
  footLayout->addWidget(progressReport);
  footLayout->addWidget(CreateFooter());
  mainLayout->addLayout(footLayout);
73

Cyrille Valladeau's avatar
Cyrille Valladeau committed
74
  QGroupBox *mainGroup = new QGroupBox();
75 76
  mainGroup->setLayout(mainLayout);

77 78
  QVBoxLayout  *finalLayout = new QVBoxLayout();
  finalLayout->addWidget(mainGroup);
79

80 81
  // Make the final layout to the widget
  this->setLayout(finalLayout);
82 83
}

84
void QtWidgetView::UpdateMessageAfterExecuteClicked()
Cyrille Valladeau's avatar
Cyrille Valladeau committed
85 86 87 88 89 90 91 92 93 94 95
{
  m_Message->setText("<center><font color=\"#FF0000\">Running</font></center>");
}

void QtWidgetView::UpdateMessageAfterApplicationReady( bool val )
{
  if(val == true)
    m_Message->setText("<center><font color=\"#00FF00\">Ready to run</font></center>");
  else
    m_Message->setText("<center><font color=\"#FF0000\">Select parameters</font></center>");
}
96 97 98

QWidget* QtWidgetView::CreateInputWidgets()
{
99 100 101 102 103 104 105 106
  QScrollArea *scrollArea = new QScrollArea;
  // Put the main group inside a scroll area
  scrollArea->setWidget(QtWidgetParameterFactory::CreateQtWidget(m_Model->GetApplication()->GetParameterList(), m_Model));
  scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  scrollArea->setWidgetResizable(true);

  return scrollArea;
107 108
}

109

110 111 112 113 114
QWidget* QtWidgetView::CreateFooter()
{
  // an HLayout with two buttons : Execute and Quit
  QGroupBox *footerGroup = new QGroupBox;
  QHBoxLayout *footerLayout = new QHBoxLayout;
115

116
  footerGroup->setFixedHeight(40);
OTB Bot's avatar
STYLE  
OTB Bot committed
117 118
  footerGroup->setContentsMargins(0, 0, 0, 0);
  footerLayout->setContentsMargins(5, 5, 5, 5);
119

120 121
  m_ExecButton = new QPushButton(footerGroup);
  m_ExecButton->setDefault(true);
122
  m_ExecButton->setEnabled(false);
123
  m_ExecButton->setText(QObject::tr("Execute"));
124
  connect( m_ExecButton, SIGNAL(clicked()), m_Model, SLOT(ExecuteAndWriteOutputSlot() ) );
125
  connect( m_Model, SIGNAL(SetApplicationReady(bool)), m_ExecButton, SLOT(setEnabled(bool)) );
126
  connect( m_ExecButton, SIGNAL(clicked()), this, SLOT(UpdateMessageAfterExecuteClicked() ) );
127 128 129

  m_QuitButton = new QPushButton(footerGroup);
  m_QuitButton->setText(QObject::tr("Quit"));
Cyrille Valladeau's avatar
Cyrille Valladeau committed
130
  connect( m_QuitButton, SIGNAL(clicked()), this, SLOT(CloseSlot()) );
131 132 133 134 135

  // Put the buttons on the right
  footerLayout->addStretch();
  footerLayout->addWidget(m_ExecButton);
  footerLayout->addWidget(m_QuitButton);
136

137 138 139 140 141
  footerGroup->setLayout(footerLayout);

  return footerGroup;
}

Cyrille Valladeau's avatar
Cyrille Valladeau committed
142 143 144
QWidget* QtWidgetView::CreateDoc()
{
  QTextEdit *text = new QTextEdit;
145
  text->setReadOnly(true);
Cyrille Valladeau's avatar
Cyrille Valladeau committed
146 147 148

  QTextDocument * doc = new QTextDocument();

149 150
  std::string docContain;
  ApplicationHtmlDocGenerator::GenerateDoc( m_Application, docContain);
Cyrille Valladeau's avatar
Cyrille Valladeau committed
151

152
  doc->setHtml(docContain.c_str());
Cyrille Valladeau's avatar
Cyrille Valladeau committed
153

154
  text->setDocument(doc);
Cyrille Valladeau's avatar
Cyrille Valladeau committed
155

Cyrille Valladeau's avatar
Cyrille Valladeau committed
156 157 158
  return text;
}

Cyrille Valladeau's avatar
Cyrille Valladeau committed
159 160
void QtWidgetView::CloseSlot()
{
OTB Bot's avatar
STYLE  
OTB Bot committed
161
  // Close the widget
Cyrille Valladeau's avatar
Cyrille Valladeau committed
162
  this->close();
163 164 165

  // Emit a signal to close any widget that this gui belonging to
  emit QuitSignal();
Cyrille Valladeau's avatar
Cyrille Valladeau committed
166
}
167

168 169 170 171 172 173
void QtWidgetView::UnhandledException(QString message)
{
  m_TabWidget->setCurrentIndex(1);
  m_LogText->append(message);
}

174 175
}
}