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
58 for (int i=0; i< arglist.size(); ++i)
61 if (arglist[i].left(1)=="-")
63 // Compare given option to all defined options
64 for (int j=0; j < optlist.size(); ++j)
66 if (arglist.at(i)==optlist.value(j).getShort() ||
67 arglist.at(i)==optlist.value(j).getLong())
69 optlist[j].setActive();
71 if (optlist[j].getType()==Option::String)
74 if (i==arglist.size())
76 qWarning ("Error: argument to option missing");
79 optlist[j].setArg (arglist[i]);
87 qWarning("Error: Unknown argument ");
91 filelist.append (arglist[i]);
96 void Options::add (Option o)
101 void Options::add (const QString &n, const Option::Type &t=Option::Switch, const QString &s="", const QString &l="")
108 void Options::setHelpText (const QString &s)
113 QString Options::getHelpText ()
118 QString Options::getProgramName()
123 QStringList Options::getFileList ()
128 bool Options::isOn(const QString &s)
130 for (int i=0; i<optlist.size(); ++i)
131 if (optlist[i].getName()==s && optlist[i].isActive() )
136 QString Options::getArg(const QString &s)
138 for (int i=0; i<optlist.size(); ++i)
139 if (optlist[i].getName()==s) return optlist[i].getArg();