From 48245e494ab3f730ed300bcde994d0d8b6a6de06 Mon Sep 17 00:00:00 2001 From: Cyrille Valladeau <cyrille.valladeau@c-s.fr> Date: Fri, 21 Oct 2011 11:19:53 +0200 Subject: [PATCH] ENH: add Qt doc --- Applications/Util/otbConvert.cxx | 6 +- .../ApplicationEngine/otbWrapperApplication.h | 4 + .../otbApplicationLauncherQt.cxx | 11 +- ...otbWrapperQtWidgetSimpleProgressReport.cxx | 2 +- .../QtWidget/otbWrapperQtWidgetView.cxx | 119 ++++++++++++------ .../QtWidget/otbWrapperQtWidgetView.h | 7 +- .../otbWrapperApplicationDocTests.cxx | 10 ++ 7 files changed, 107 insertions(+), 52 deletions(-) diff --git a/Applications/Util/otbConvert.cxx b/Applications/Util/otbConvert.cxx index 8310f9d9b2..f92fa05d46 100644 --- a/Applications/Util/otbConvert.cxx +++ b/Applications/Util/otbConvert.cxx @@ -81,13 +81,13 @@ private: SetName("Convert"); SetDescription("Convert an image to a different format, eventually rescaling the data" " and/or changing the pixel type."); - // Documentation + SetDocName("Image Conversion Application"); SetDocLongDescription("This application performs an image pixel type conversion (short, ushort, char, uchar, int, uint, float and double types are handled). The output image is written in the specified format (ie. taht corresponds to the given extension).\n The convertion can include a rescale usiong the image 2% minimum and maximum values. The rescale can be linear or log2."); SetDocLimitations("None"); - SetDocAuthors("CS-OTB Team"); + SetDocAuthors("Otmane Lahlou"); SetDocSeeAlso("Rescale application"); - SetDocCLExample("otbApplicationLauncherCommandLine Convert ${OTB-BIN} --il ${OTB-Data} "); + SetDocCLExample("otbApplicationLauncherCommandLine Convert ${OTB-BIN}/bin --in ${OTB-Data}/Input/QB_Toulouse_Ortho_XS.tif --out otbConvertWithScalingOutput.png uchar --type linear"); AddDocTag("Conversion"); AddDocTag("Image Dynamic"); diff --git a/Code/ApplicationEngine/otbWrapperApplication.h b/Code/ApplicationEngine/otbWrapperApplication.h index aa9f091d60..5c6d2b0b4b 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.h +++ b/Code/ApplicationEngine/otbWrapperApplication.h @@ -419,6 +419,8 @@ public: /** Doc element accessors. */ + itkSetStringMacro(DocName); + itkGetStringMacro(DocName); itkSetStringMacro(DocLongDescription); itkGetStringMacro(DocLongDescription); itkSetStringMacro(DocCLExample); @@ -541,6 +543,8 @@ private: itk::ProcessObject::Pointer m_ProgressSource; std::string m_ProgressSourceDescription; + /** Long name of the application (thatcan be displayed...) */ + std::string m_DocName; /** Long and precise application description . */ std::string m_DocLongDescription; /** Commanline example. Use ${OTB-DATA} for OTB-Data directory diff --git a/Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx b/Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx index 1ee8c1fc5b..d7be70a65a 100644 --- a/Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx +++ b/Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx @@ -79,6 +79,8 @@ int main(int argc, char* argv[]) // MainWidget : that contains the view and any other widget // (progress, logs...) QMainWindow* mainWindow = new QMainWindow(); + mainWindow->setWindowIcon(QIcon( ":/otb_small.png" )); + mainWindow->setWindowTitle(QString(app->GetDocName()).append(" - version ").append(OTB_VERSION_STRING)); // Create GUI based on module QtWidgetView* gui = new QtWidgetView(app); @@ -87,18 +89,9 @@ int main(int argc, char* argv[]) // Connect the View "Quit" signal, to the mainWindow close slot QObject::connect(gui, SIGNAL(QuitSignal()), mainWindow, SLOT(close())); - // Create a progressReport object - //QtWidgetSimpleProgressReport * progressReport = new QtWidgetSimpleProgressReport(gui->GetModel()); - //progressReport->SetApplication(app); - - // Create a dock widget containg the progress widget - //QDockWidget* qdock = new QDockWidget("Progress Reporting ...", mainWindow); - //qdock->setWidget(progressReport); - // build the main window, central widget is the plugin view, other // are docked widget (progress, logs...) mainWindow->setCentralWidget(gui); - //mainWindow->addDockWidget(Qt::BottomDockWidgetArea, qdock); // Show the main window mainWindow->show(); diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetSimpleProgressReport.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetSimpleProgressReport.cxx index cb8fd87a28..2cd8d1145e 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetSimpleProgressReport.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetSimpleProgressReport.cxx @@ -42,7 +42,7 @@ QtWidgetSimpleProgressReport::QtWidgetSimpleProgressReport(QtWidgetModel * model m_AddProcessCommand->SetCallbackFunction( this, &QtWidgetSimpleProgressReport::ProcessEvent ); m_Bar = new itk::QtProgressBar(this); - m_Label = new QLabel("No process..."); + m_Label = new QLabel("No process"); connect( m_Bar, SIGNAL(SetValueChanged(int)), m_Bar, SLOT(setValue(int)) ); connect( m_Model, SIGNAL(SetProgressReportDone()), m_Bar, SLOT(reset()) ); diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx index 29f6ded1f2..3d3091910a 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx @@ -47,7 +47,6 @@ void QtWidgetView::CreateGui() QVBoxLayout *mainLayout = new QVBoxLayout(); QTabWidget *tab = new QTabWidget(); - mainLayout->addWidget(CreateHeader()); tab->addTab(CreateInputWidgets(), "Parameters"); QTextEdit *log = new QTextEdit(); connect( m_Model->GetLogOutput(), SIGNAL(NewContentLog(QString)), log, SLOT(append(QString) ) ); @@ -55,9 +54,9 @@ void QtWidgetView::CreateGui() QtWidgetProgressReport* prog = new QtWidgetProgressReport(m_Model); prog->SetApplication(m_Application); tab->addTab(prog, "Progress Reporting ..."); + tab->addTab(CreateDoc(), "Documentation"); mainLayout->addWidget(tab); - QtWidgetSimpleProgressReport * progressReport = new QtWidgetSimpleProgressReport(m_Model); progressReport->SetApplication(m_Application); QHBoxLayout *footLayout = new QHBoxLayout; @@ -80,44 +79,9 @@ void QtWidgetView::CreateGui() // Make the scroll layout the main layout this->setLayout(scrollLayout); - this->setWindowIcon(QIcon( ":/otb_small.png" )); - this->setWindowTitle(QString(m_Model->GetApplication()->GetName()).append(" - version ").append(OTB_VERSION_STRING)); } -QWidget* QtWidgetView::CreateHeader() -{ - // an HLayout with the description of the application, and two icons - QHBoxLayout *headerLayout = new QHBoxLayout; - - QGroupBox *headerGroup = new QGroupBox; - headerGroup->setStyleSheet("border: 1px solid gray"); - - headerGroup->setFixedHeight(50); - headerGroup->setContentsMargins(0, 0, 0, 0); - headerLayout->setContentsMargins(5, 5, 5, 5); - - QLabel *iconOTBLabel = new QLabel; - iconOTBLabel->setStyleSheet("border-style: none"); - //iconOTBLabel->setPixmap(QIcon( ":/otb_big.png" ).pixmap(32, QIcon::Normal, QIcon::On)); - - QLabel *descriptionLabel = new QLabel; - descriptionLabel->setStyleSheet("border-style: none"); - QString descriptionLabelText(m_Model->GetApplication()->GetDescription()); - descriptionLabel->setText(descriptionLabelText); - - QLabel *iconCNESLabel = new QLabel; - iconCNESLabel->setStyleSheet("border-style: none"); - //iconCNESLabel->setPixmap(QIcon( ":/cnes.png" ).pixmap(32, QIcon::Normal, QIcon::On)); - - headerLayout->addWidget(iconOTBLabel); - headerLayout->addStretch(); - headerLayout->addWidget(descriptionLabel); - headerLayout->addStretch(); - headerLayout->addWidget(iconCNESLabel); - headerGroup->setLayout(headerLayout); - return headerGroup; -} QWidget* QtWidgetView::CreateInputWidgets() { @@ -157,6 +121,87 @@ QWidget* QtWidgetView::CreateFooter() return footerGroup; } +QWidget* QtWidgetView::CreateDoc() +{ + // an HLayout with two buttons : Execute and Quit + QTextEdit *text = new QTextEdit; + + QTextDocument * doc = new QTextDocument(); + itk::OStringStream oss; + oss << "<center><h2>"<<m_Application->GetDocName()<<"</center></h2>"; + oss << "<h3>Brief Description</h3>"; + oss << "<body>"<<m_Application->GetDescription()<<"</body>"; + oss << "<h3>Tags</h3>"; + oss << "<body>"; + for(unsigned int i=0; i<m_Application->GetDocTags().size(); i++) + { + oss << m_Application->GetDocTags()[i]<<" ";; + } + oss <<"</body>"; + + oss << "<h3>Long Description</h3>"; + oss << "<body>"<<m_Application->GetDocLongDescription()<<"</body>"; + + oss << this->SetDocParameters(); + + oss << "<h3>Limitations</h3>"; + oss << "<body>"<<m_Application->GetDocLimitations()<<"</body>"; + oss << "<h3>Authors</h3>"; + oss << "<body>"<<m_Application->GetDocAuthors()<<"</body>"; + oss << "<h3>See also</h3>"; + oss << "<body>"<<m_Application->GetDocSeeAlso()<<"</body>"; + oss << "<h3>Command line example</h3>"; + oss << "<code>"<<m_Application->GetDocCLExample()<<"</code>"; + + doc->setHtml( oss.str().c_str()); + + + text->setDocument( doc ); + return text; +} + +const char * QtWidgetView::SetDocParameters() +{ + const std::vector<std::string> appKeyList = m_Application->GetParametersKeys( true ); + const unsigned int nbOfParam = appKeyList.size(); + + itk::OStringStream oss; + oss << "<h3>Parameters</h3>"; + // Mandatory parameters + oss << "<h2>Mandatory parameters</h2>"; + oss << "<li>"; + + for( unsigned int i=0; i<nbOfParam; i++ ) + { + Parameter::Pointer param = m_Application->GetParameterByKey( appKeyList[i] ); + // Check if mandatory parameter are present and have value + if( param->GetMandatory() == true ) + { + oss << "<body><i>"<< param->GetName() << "</i>: "<<param->GetDescription()<<"</body>"; + } + } + oss << "</body></li>"; +// Optionnal parameters + oss << "<h2>Optionnal parameters</h2>"; + oss << "<body><li>"; + bool found = false; + for( unsigned int i=0; i<nbOfParam; i++ ) + { + Parameter::Pointer param = m_Application->GetParameterByKey( appKeyList[i] ); + // Check if mandatory parameter are present and have value + if( param->GetMandatory() == false ) + { + oss << "<body><i>" <<param->GetName() << "</i>: "<<param->GetDescription()<<"</body>"; + found = true; + } + } + if( !found ) + oss << "None"; + oss << "</li>"; + + return oss.str().c_str(); +} + void QtWidgetView::CloseSlot() { // Close the widget diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h index 69fe4436a2..9d25edfcd4 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h @@ -56,12 +56,15 @@ private: QtWidgetView(const QtWidgetView&); //purposely not implemented void operator=(const QtWidgetView&); //purposely not implemented - QWidget* CreateHeader(); - QWidget* CreateFooter(); QWidget* CreateInputWidgets(); + QWidget* CreateDoc(); + + /** Add the parameter description in the flux of the documentation tab. */ + const char * SetDocParameters(); + Application::Pointer m_Application; QtWidgetModel* m_Model; diff --git a/Testing/Applications/otbWrapperApplicationDocTests.cxx b/Testing/Applications/otbWrapperApplicationDocTests.cxx index 1ff0361878..2280401123 100644 --- a/Testing/Applications/otbWrapperApplicationDocTests.cxx +++ b/Testing/Applications/otbWrapperApplicationDocTests.cxx @@ -46,6 +46,16 @@ int otbWrapperApplicationDocTest(int argc, char* argv[]) bool isOK = true; // Check doc element... + if( app->GetName() == "" ) + { + std::cout<<"Missing Name."<<std::endl; + isOK = false; + } + if( app->GetDocName() == "" ) + { + std::cout<<"Missing Doc Name."<<std::endl; + isOK = false; + } if( app->GetDescription() == "" ) { std::cout<<"Missing Description."<<std::endl; -- GitLab