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 ///////////////////////////////////////////////////////////////
50 QStringList arglist=qApp->arguments();
53 progname=arglist.first();
56 // Work through rest of options
59 for (i=0; i< arglist.size(); ++i)
62 if (arglist[i].left(1)=="-")
64 // Compare given option to all defined options
65 for (int j=0; j < optlist.size(); ++j)
67 if (arglist.at(i)==optlist.value(j).getShort() ||
68 arglist.at(i)==optlist.value(j).getLong())
70 optlist[j].setActive();
72 if (optlist[j].getType()==Option::String)
75 if (i==arglist.size())
77 qWarning ("Error: argument to option missing");
80 optlist[j].setArg (arglist[i]);
88 qWarning("Error: Unknown argument ");
92 filelist.append (arglist[i]);
97 void Options::add (Option o)
102 void Options::add (const QString &n, const Option::Type &t=Option::Switch, const QString &s="", const QString &l="")
109 void Options::setHelpText (const QString &s)
114 QString Options::getHelpText ()
119 QString Options::getProgramName()
124 QStringList Options::getFileList ()
129 bool Options::isOn(const QString &s)
131 for (int i=0; i<optlist.size(); ++i)
132 if (optlist[i].getName()==s && optlist[i].isActive() )
137 QString Options::getArg(const QString &s)
139 for (int i=0; i<optlist.size(); ++i)
140 if (optlist[i].getName()==s) return optlist[i].getArg();