]> gitweb.hamatoma.de Git - reqt/commitdiff
recommand: nofm and timeconv
authorhama <hama@siduction.net>
Thu, 11 Feb 2016 22:44:46 +0000 (23:44 +0100)
committerhama <hama@siduction.net>
Thu, 11 Feb 2016 22:44:46 +0000 (23:44 +0100)
appl/recommand/CommandProcessor.cpp
appl/recommand/CommandProcessor.hpp
appl/recommand/mainwindow.ui

index 1ffd867fd3a44956ad24da63912a9e4b1bf1fb39..9731c715f1a0937b9b0a7e71cb61826dc8529f50 100644 (file)
@@ -72,6 +72,8 @@ void CommandProcessor::statement(int lineNo, const QString& text){
                        euroJackpot(args);
                } else if (QString("lotto").startsWith(arg0)){
                        lotto(args);
+               } else if (QString("nofm").startsWith(arg0)){
+                       nOfM(args);
                } else if (QString("time").startsWith(arg0)){
                        time(args);
                } else {
@@ -178,12 +180,37 @@ void CommandProcessor::lotto(const QStringList& args){
        if (count > 0){
                QString line;
                for (uint ix = 0; ix < count; ix++){
-                       line = QString::number(ix + 1) + ": " + calcNOfM(5, 50)
+                       line = QString::number(ix + 1) + ": " + calcNOfM(6, 49)
                                        + " | " + calcNOfM(1, 10);
                        out(line);
                }
        }
 }
+/**
+ * Displays proposals for the Euro Jackpot.
+ *
+ * @param args the command arguments
+ */
+void CommandProcessor::nOfM(const QStringList& args){
+       uint n, m;
+       if (args.count() < 3){
+               help("too few parameter: <n> <m> expected", args);
+       } else {
+               QString arg1 = args.at(1);
+               QString arg2 = args.at(2);
+               if (ReQStringUtils::lengthOfUInt(arg1, 0, 10, &n) != arg1.length()){
+                       help("not a number: <n>", args);
+               } else if (ReQStringUtils::lengthOfUInt(arg2, 0, 10, &m) != arg2.length()){
+                       help("not a number: <n>", args);
+               } else if (n < 2){
+                       help(" <n> < 2", args);
+               } else if (m < 2){
+                       help(" <n> < <m>", args);
+               } else {
+                       out(calcNOfM(n, m));
+               }
+       }
+}
 
 /**
  * Displays a time expression
@@ -191,4 +218,19 @@ void CommandProcessor::lotto(const QStringList& args){
  * @param args the command arguments
  */
 void CommandProcessor::time(const QStringList& args){
+       if (args.count() != 2){
+               help("not one argument <time>", args);
+       } else {
+               QString arg1 = args.at(1);
+               uint time;
+               QDateTime date;
+               if (ReQStringUtils::lengthOfUInt(arg1, 0, 10, &time) == arg1.length()){
+                       date = QDateTime::fromMSecsSinceEpoch(time * 1000LL);
+                       out(date.toString("yyyy.MM.dd hh:mm:ss"));
+               } else if (ReQStringUtils::lengthOfDateTime(arg1, 0, false, false, &date) == arg1.length()){
+                       out(QString::number(date.toMSecsSinceEpoch() / 1000L));
+               } else {
+                       help("unknown date/time format", args);
+               }
+       }
 }
index 30424812441c37821c5a741b53feba6f145a0fbd..09c626ac31caf8d58f5319252331c263f04bc000 100644 (file)
@@ -25,6 +25,7 @@ public:
        void help(const QString& errorMessage, const QStringList& args);
        void interpret(const QString& text);
        void lotto(const QStringList& args);
+       void nOfM(const QStringList& args);
        void out(const QString& message);
        void time(const QStringList& args);
        void statement(int lineNo, const QString& text);
index dae72eac6cfe260b165df3bd40c698062ec6a918..3c57d02d7cb9ecce0ae44d0fe1f690062116a457 100644 (file)
             </layout>
            </item>
            <item>
-            <widget class="QListWidget" name="listWidgetResult"/>
+            <widget class="QListWidget" name="listWidgetResult">
+             <property name="font">
+              <font>
+               <family>Monospace</family>
+              </font>
+             </property>
+            </widget>
            </item>
           </layout>
          </item>