GPL V2. Added settings to documentation
4 #include <QApplication>
20 Option::Option (const QString &n, const Type &t, const QString &s, const QString &l)
28 void Option::set(const QString &n, const Type &t, const QString &s, const QString &l)
36 QString Option::getName () { return name; }
37 QString Option::getShort () { return sName; }
38 QString Option::getLong() { return lName; }
39 Option::Type Option::getType() { return type; }
40 void Option::setArg(const QString& s) { sarg=s; }
41 QString Option::getArg() { return sarg; }
42 void Option::setActive() { active=true; }
43 bool Option::isActive() { return active; }
45 ///////////////////////////////////////////////////////////////
52 while ( i < qApp->argc())
54 arglist.append (qApp->argv()[i]);
59 progname=arglist.first();
62 // Work through rest of options
64 for (i=0; i< arglist.size(); ++i)
67 if (arglist[i].left(1)=="-")
69 // Compare given option to all defined options
70 for (int j=0; j < optlist.size(); ++j)
72 if (arglist.at(i)==optlist.value(j).getShort() ||
73 arglist.at(i)==optlist.value(j).getLong())
75 optlist[j].setActive();
77 if (optlist[j].getType()==Option::String)
80 if (i==arglist.size())
82 qWarning ("Error: argument to option missing");
85 optlist[j].setArg (arglist[i]);
93 qWarning("Error: Unknown argument ");
97 filelist.append (arglist[i]);
102 void Options::add (Option o)
107 void Options::add (const QString &n, const Option::Type &t=Option::Switch, const QString &s="", const QString &l="")
114 void Options::setHelpText (const QString &s)
119 QString Options::getHelpText ()
124 QString Options::getProgramName()
129 QStringList Options::getFileList ()
134 bool Options::isOn(const QString &s)
136 for (int i=0; i<optlist.size(); ++i)
137 if (optlist[i].getName()==s && optlist[i].isActive() )
142 QString Options::getArg(const QString &s)
144 for (int i=0; i<optlist.size(); ++i)
145 if (optlist[i].getName()==s) return optlist[i].getArg();