All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Classes | Public Member Functions | Static Public Member Functions
QGpCoreTools::ApplicationHelp Class Reference

Brief description of class still missing. More...

#include <ApplicationHelp.h>

List of all members.

Classes

struct  Example
struct  Option
struct  OptionGroup

Public Member Functions

void addExample (QString command, QString comments)
void addGroup (QString title, QByteArray section)
void addOption (QString option, QString comments)
 ApplicationHelp ()
void exec (const char *group=0)
QList< QByteArray > sections ()
void setComments (QString comments)
void setOptionSummary (QString optionSummary)
void setSeeAlso (QString seeAlso)
 ~ApplicationHelp ()

Static Public Member Functions

static QString encodeToHtml (QString str)
static QString encodeToLatex (QString str)
static QString getLine (QString &text, int maxLength, bool *newLine=0)
static void print (QString p, QString linePrefix=QString::null, int indent=0)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

Description of constructor still missing

References TRACE.

{
  TRACE;
}

Description of destructor still missing

References TRACE.

{
  TRACE;
}

Member Function Documentation

void QGpCoreTools::ApplicationHelp::addExample ( QString  command,
QString  comments 
)

References TRACE.

Referenced by ArrayPlugin::setHelp(), and HVPlugin::setHelp().

{
  TRACE;
  Example o;
  o.command=command;
  o.comments=comments;
  _examples.append(o);
}
void QGpCoreTools::ApplicationHelp::addGroup ( QString  title,
QByteArray  section 
)
void QGpCoreTools::ApplicationHelp::addOption ( QString  option,
QString  comments 
)

References TRACE.

Referenced by ArrayPlugin::setHelp(), DampingPlugin::setHelp(), QGpGuiTools::Application::setHelp(), HVPlugin::setHelp(), StructureRatiosPlugin::setHelp(), and QGpCoreTools::CoreApplicationPrivate::setHelp().

{
  TRACE;
  OptionGroup& g=_options.last();
  Option o;
  o.option=option;
  o.comments=comments;
  g.options.append(o);
}
QString QGpCoreTools::ApplicationHelp::encodeToHtml ( QString  str) [static]

References str.

{
  str.replace("&","&amp;");
  str.replace("'","&apos;");
  str.replace("\"","&quot;");
  str.replace("<","&lt;");
  str.replace(">","&gt;");
  str.replace("\n  ","<li/>");
  str.replace("\n","<br/>");
  return str;
}
QString QGpCoreTools::ApplicationHelp::encodeToLatex ( QString  str) [static]

References str.

{
  str.replace("\\","\\\\");
  str.replace("_","\\_");
  str.replace("$","\\$");
  str.replace("\n","\\\\\n");
  str.replace("<","\\textless ");
  str.replace(">","\\textgreater ");
  str.replace("#","\\#");
  str.replace("^","\\textasciicircum");
  str.replace("|","\\textbar");
  return str;
}
void QGpCoreTools::ApplicationHelp::exec ( const char *  group = 0)

References QGpCoreTools::CoreApplicationPrivate::authors(), QGpCoreTools::flush(), print(), QGpCoreTools::App::setStream(), QGpCoreTools::App::stream(), QGpCoreTools::tr(), and TRACE.

Referenced by QGpCoreTools::CoreApplicationPrivate::showHelp().

{
  TRACE;
  // make sure stdout is used for output
  App::setStream(new StandardStream(stdout));

  if(group) {
    if(strcmp(group,"html")==0) {
      execHtml();
      return;
    }
    if(strcmp(group,"latex")==0) {
      execLatex();
      return;
    }
  }

  print(tr("Usage: %1 %2\n\n").arg(QCoreApplication::applicationName()).arg(_optionSummary), QString::null, 0);
  print(_comments, QString::null, 2);
  if(group) {
    QByteArray helpOption(group);
    if(helpOption=="all") {
      for(QList<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) {
        print( *it);
      }
    } else if(helpOption.startsWith("no-")) {
      helpOption=helpOption.mid(3);
      for(QList<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) {
        if(it->section!=helpOption) {
          print( *it);
        }
      }
    } else {
      for(QList<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) {
        if(it->section==helpOption) {
          print( *it);
        }
      }
    }
  } else if(!_options.isEmpty()) {
    print(_options.first());
    if(_options.count()>1) {
      print("\nMore options are available. Use '-h all' to display all of them.", QString::null, 2);
    }
  }
  if( !_examples.isEmpty()) {
    App::stream() << "\nExamples:\n";
    for(QList<Example>::iterator it=_examples.begin(); it!=_examples.end(); it++ ) {
      Example& o=*it;
      App::stream() << "\n";
      print(o.command, QString::null, 9);
      App::stream() << "\n";
      print(o.comments, QString::null, 2);
    }
  }
  App::stream() << "\nSee also:\n";
  if( !_seeAlso.isEmpty()) {
    print(_seeAlso, QString::null, 2);
  }
  print("More information at http://www.geopsy.org", QString::null, 2);
  App::stream() << "\nAuthors:\n";
  print(CoreApplication::authors(), QString::null, 2);
  App::stream() << flush;
}
QString QGpCoreTools::ApplicationHelp::getLine ( QString &  text,
int  maxLength,
bool *  newLine = 0 
) [static]

Returns the first line of text. The first line is removed from text. newLine is set to true if a '
' is encountered else it is set to false.

References TRACE.

Referenced by print(), and QGpCoreTools::ConsoleProgress::setCaption().

{
  TRACE;
  if(maxLength<10) {
    QString line=text;
    text="";
    return line;
  }
  QString line=text;
  int index=text.indexOf("\n");
  if(index>-1) {
    if(index<=maxLength) {
      text=text.mid(index+1);
      line.truncate(index);
      if(newLine) *newLine=true;
      return line;
    }
  }
  if(text.length()<=maxLength) {
    text.clear();
    if(newLine) *newLine=false;
    return line;
  }
  line.truncate(maxLength);
  index=line.lastIndexOf(" ");
  if(maxLength>20 && index>maxLength-20) {
    text=text.mid(index+1); // skip the blank
    line.truncate(index);
    if(newLine) *newLine=false;
    return line;
  }
  text=text.mid(maxLength);
  if(newLine) *newLine=false;
  return line;
}
void QGpCoreTools::ApplicationHelp::print ( QString  p,
QString  linePrefix = QString::null,
int  indent = 0 
) [static]

Print string p to stdout. Prefix linePrefix and indent indent are inserted before each line. app.terminalCols() is the maximum number of characters per line.

References getLine(), QGpCoreTools::CoreApplication::instance(), QGpCoreTools::App::stream(), and TRACE.

Referenced by exec().

{
  TRACE;
  QString line;
  QString mainIndentStr, customIndentStr;
  bool newLine=true;
  mainIndentStr.fill(' ',indent);
  while(!p.isEmpty()) {
    bool lastNewLine=newLine;
    line=getLine(p, CoreApplication::instance()->terminalCols()-indent-linePrefix.count()-customIndentStr.count(),
                   &newLine);
    App::stream() << linePrefix << mainIndentStr << customIndentStr << line << "\n";
    if(lastNewLine && !newLine) {
      // Set indent by the position of the last double space
      customIndentStr=getCustomIndent(line);
      newLine=false;
    } else if(newLine) {
      customIndentStr="";
    }
  }
}
QList< QByteArray > QGpCoreTools::ApplicationHelp::sections ( )

Returns the list of sections

Referenced by QGpCoreTools::CoreApplicationPrivate::setHelp().

{
  QList<QByteArray> l;
  for(QList<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) {
    l << it->section;
  }
  if( !_examples.isEmpty()) {
    l << "examples";
  }
  return l;
}
void QGpCoreTools::ApplicationHelp::setComments ( QString  comments) [inline]
{_comments=comments;}
void QGpCoreTools::ApplicationHelp::setOptionSummary ( QString  optionSummary) [inline]
{_optionSummary=optionSummary;}
void QGpCoreTools::ApplicationHelp::setSeeAlso ( QString  seeAlso) [inline]
{_seeAlso=seeAlso;}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines