changeset 6:1a17dc714510

Added missing signal for options which take multiple values. ti: -
author John Schneiderman <JohnMS@CodeGNU.com>
date Sat, 14 Jun 2014 16:10:46 +0000
parents d051e4094072
children 49efa3ecaa98
files src/UNIT_TESTS/qargsut.hpp src/qargs.h
diffstat 2 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/UNIT_TESTS/qargsut.hpp	Sat Jun 14 15:26:18 2014 +0000
+++ b/src/UNIT_TESTS/qargsut.hpp	Sat Jun 14 16:10:46 2014 +0000
@@ -549,6 +549,7 @@
 		{
 			const char* argvValue[5] = { shortValueTest, "1", "2", "3", "4" };
 			QArgs args(5, argvValue);
+			QSignalSpy valueSignal(&args, SIGNAL(argumentValues(QChar,QList<QVariant>)));
 			args.addSupported('v', "values", "Multiple values short test.",
 						   true);
 			try
@@ -559,6 +560,15 @@
 				QVERIFY(2 == values.at(1));
 				QVERIFY(3 == values.at(2));
 				QVERIFY(4 == values.at(3));
+				QVERIFY(valueSignal.isValid());
+				QVERIFY(valueSignal.count() == 1);
+				QList< QVariant > arguments(valueSignal.takeAt(0));
+				QVERIFY(arguments.count() == 2);
+				QVERIFY(arguments.at(0).toString() == "v");
+				QVERIFY(arguments.at(1).toList().at(0) == "1");
+				QVERIFY(arguments.at(1).toList().at(1) == "2");
+				QVERIFY(arguments.at(1).toList().at(2) == "3");
+				QVERIFY(arguments.at(1).toList().at(3) == "4");
 			}
 			catch (runtime_error& error)
 			{
@@ -1246,7 +1256,6 @@
 			const char* argvValue[2] = { shortValueTest, "-2" };
 			QArgs args(2, argvValue);
 			QSignalSpy valueSignal(&args, SIGNAL(argumentValue(QChar,qint32)));
-
 			args.addSupported('v', "value", "32-bit value short test", true);
 			QVERIFY(static_cast<qint32>(args.value('v', value)) ==
 				   static_cast<qint32>(-2));
--- a/src/qargs.h	Sat Jun 14 15:26:18 2014 +0000
+++ b/src/qargs.h	Sat Jun 14 16:10:46 2014 +0000
@@ -205,6 +205,15 @@
 	*                       value is used.
 	*/
     void argumentValue(const QChar& argument, const QString& value) const;
+    /**
+	* @brief Provided String Argument Values
+	* @details The signal that is fired when an argument is provided by a user
+	*  with multiple consecutive values.
+	*
+	* @param[in] argument  The short name option that was provided.
+	* @param[in] values     The contents supplied by the user.
+	*/
+    void argumentValues(const QChar& argument, const QList<QVariant>& values) const;
     //}
 
 
@@ -506,11 +515,12 @@
     /**
 	* @brief Argument Option Values
 	* @details Provides access to the values from a short or long named
-	*  argument supplied by the user from the command-line. In addition, all
-	*  argument values provided by the user are verified for both being valid
-	*  and required. The default support for the expected types are: signed
-	*  integers, unsigned integers, single precision, double precision,
-	*  characters, and strings.
+	*  argument supplied by the user from the command-line. Once the value for
+	*  the option is determined the signal for the argument values is fired. In
+	*  addition, all argument values provided by the user are verified for both
+	*  being valid and required. The default support for the expected types
+	*  are: signed integers, unsigned integers, single precision,
+	*  double precision, characters, and strings.
 	*
 	* @param[in] shortName     The short-name of the argument option.
 	* @param[in] defaultValue  The value to use when an argument is not
@@ -674,6 +684,14 @@
     if (values.isEmpty())
 	   values.append(defaultValue);
 
+    if (NULL != QCoreApplication::instance())
+    {
+	    QList<QVariant> suppliedValues;
+	    for (auto value : values)
+		    suppliedValues.append(value);
+	    emit argumentValues(shortName, suppliedValues);
+    }
+
     return values;
 }