Commit 10c2768e authored by Cyrille Valladeau's avatar Cyrille Valladeau

ENH: use the new doc generator class to generate the displayed doc

parent abff47ed
......@@ -24,6 +24,7 @@
#include "otbWrapperParameterGroup.h"
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperQtWidgetSimpleProgressReport.h"
#include "otbWrapperApplicationHtmlDocGenerator.h"
#include "itksys/SystemTools.hxx"
......@@ -145,199 +146,17 @@ QWidget* QtWidgetView::CreateDoc()
text->setReadOnly(true);
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>";
if (m_Application->GetDocTags().size() > 0)
{
for (unsigned int i = 0; i < m_Application->GetDocTags().size() - 1; i++)
{
oss << m_Application->GetDocTags()[i] << ", ";
;
}
oss << m_Application->GetDocTags()[m_Application->GetDocTags().size() - 1];
}
oss << "</body>";
oss << "<h3>Long Description</h3>";
oss << "<body>" << m_Application->GetDocLongDescription() << "</body>";
std::string val;
this->SetDocParameters(val);
oss << val;
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);
std::string docContain;
ApplicationHtmlDocGenerator::GenerateDoc( m_Application, docContain);
doc->setHtml(docContain.c_str());
//std::cout<<text->toHtml().toStdString()<<std::endl;
text->setDocument(doc);
return text;
}
void QtWidgetView::SetDocParameters( std::string & val )
{
const std::vector<std::string> appKeyList = m_Application->GetParametersKeys( false );
itk::OStringStream oss;
oss << "<h3>Parameters</h3>";
oss<<"<ul>";
std::string paramDocs("");
this->GetDocParameters( paramDocs );
oss<<paramDocs;
oss<<"</ul>";
val.append(oss.str());
}
void QtWidgetView::GetDocParameters( std::string & val )
{
itk::OStringStream oss;
const std::vector<std::string> appKeyList = m_Application->GetParametersKeys( false );
const unsigned int nbOfParam = appKeyList.size();
std::string paramDocs("");
for( unsigned int i=0; i<nbOfParam; i++ )
{
const std::string key(appKeyList[i]);
Parameter::Pointer param = m_Application->GetParameterByKey( key );
if( m_Application->GetParameterType(key) == ParameterType_Group)
{
oss << "<li><b>[group] "<<param->GetName()<<": </b>";
if(std::string(param->GetDescription()).size()!=0)
{
oss<<param->GetDescription();
}
std::string grDoc;
GetDocParameterGroup( grDoc, key );
oss<<grDoc;
oss<<"</li><br />";
}
else if( m_Application->GetParameterType(key) == ParameterType_Choice )
{
oss << "<li><b> [choice] "<<param->GetName()<<": </b>";
if(std::string(param->GetDescription()).size()!=0)
{
oss<<param->GetDescription();
}
std::string grDoc;
GetDocParameterChoice(grDoc, key);
oss<<grDoc;
oss<<"</li><br />";
}
else
{
oss << "<li><b><code>[param] " << param->GetName() << ": </code></b>";
oss << param->GetDescription()<< "</li>";
}
}
if( oss.str() == "" )
oss << "None";
val = oss.str();
}
void QtWidgetView::GetDocParameterGroup( std::string & val, const std::string & key )
{
Parameter * paramGr = m_Application->GetParameterByKey( key );
if( !dynamic_cast<ParameterGroup *>(paramGr))
{
itkGenericExceptionMacro("Invalid parameter type for key "<<key<<", wait for ParameterGroup...");
}
ParameterGroup * group = dynamic_cast<ParameterGroup *>(paramGr);
const std::vector<std::string> appKeyList = group->GetParametersKeys( false );
unsigned int nbOfParam = appKeyList.size();
itk::OStringStream oss;
oss<<"<ul>";
for( unsigned int i=0; i<nbOfParam; i++ )
{
const std::string fullKey(std::string(key).append(".").append(appKeyList[i]));
Parameter::Pointer param = m_Application->GetParameterByKey( fullKey );
if( m_Application->GetParameterType(fullKey) == ParameterType_Group)
{
oss << "<li><b><code>[group] "<< param->GetName()<<": </code></b>";
if(std::string(param->GetDescription()).size()!=0)
{
oss<<param->GetDescription();
}
std::string grDoc;
GetDocParameterGroup( grDoc, fullKey );
oss<<grDoc;
oss<<"</li>";
}
else if( m_Application->GetParameterType(fullKey) == ParameterType_Choice )
{
oss << "<li><b><code>[choice] "<<param->GetName()<<": </code></b>";
if(std::string(param->GetDescription()).size()!=0)
{
oss<<param->GetDescription();
}
std::string grDoc;
GetDocParameterChoice(grDoc, fullKey );
oss<<grDoc;
oss<<"</li>";
}
else
{
oss << "<li><b><code>[param] "<< param->GetName()<< ": </code></b>";
oss << param->GetDescription()<<"</li>";
}
}
oss<<"</ul>";
val.append(oss.str());
}
void QtWidgetView::GetDocParameterChoice( std::string & val, const std::string & key )
{
Parameter * paramCh = m_Application->GetParameterByKey( key );
if( !dynamic_cast<ChoiceParameter *>(paramCh))
{
itkGenericExceptionMacro("Invalid parameter type for key "<<key<<", wait for ChoiceParameter...");
}
ChoiceParameter * choice = dynamic_cast<ChoiceParameter *>(paramCh);
const std::vector<std::string> appKeyList = choice->GetChoiceKeys();
unsigned int nbOfParam = choice->GetNbChoices();
itk::OStringStream oss;
oss<<"<ul>";
for( unsigned int i=0; i<nbOfParam; i++ )
{
const std::string fullKey(std::string(key).append(".").append(appKeyList[i]));
ParameterGroup * group = choice->GetChoiceParameterGroupByIndex(i);
std::string grDoc;
oss << "<li><b><code>[group] "<< group->GetName()<<": </code></b>";
if(std::string(group->GetDescription()).size()!=0)
{
oss<<group->GetDescription();
}
GetDocParameterGroup( grDoc, fullKey );
oss<<grDoc;
oss<<"</li>";
}
oss<<"</ul>";
val.append(oss.str());
}
void QtWidgetView::CloseSlot()
{
// Close the widget
......
......@@ -66,18 +66,6 @@ private:
QWidget* CreateDoc();
/** Add the parameter description in the flux of the documentation tab. */
void SetDocParameters( std::string & val );
/** Get the parameter description of one parameter. */
void GetDocParameters( std::string & val );
/** generate the documentation associated to a group.*/
void GetDocParameterGroup( std::string & val, const std::string & key );
/** generate the documentation associated to a choice.*/
void GetDocParameterChoice( std::string & val, const std::string & key );
Application::Pointer m_Application;
QtWidgetModel* m_Model;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment