ossp-pkg/as/as-gui/as_amount.cpp 1.1 -> 1.2
--- as_amount.cpp 2002/11/25 15:45:56 1.1
+++ as_amount.cpp 2002/11/26 19:33:36 1.2
@@ -1,8 +1,7 @@
#include <qregexp.h>
#include "titamount.h"
-
-#define HOURAMOUNT 60
+#include "titconst.h"
// Sets a text formatted representation
@@ -11,12 +10,16 @@
int nTotal = 0; // The total amount of minutes
QRegExp Strexpr("(\\d+):(\\d+)"); // Pattern in amount text
QString Stramount = QRegExp::escape(Strval); // Incoming string escaped
- Strexpr.search(Stramount);
-
- nTotal = Strexpr.cap(Strexpr.numCaptures() - 1).toInt() * HOURAMOUNT; // Calculate hours
- nTotal += Strexpr.cap(Strexpr.numCaptures()).toInt(); // Calculate minutes
- this->setValue(nTotal);
+ if (Strval.isEmpty()) { // Shortcircuit in the
+ this->setValue(0); // case of empty string
+ }
+ else { // Do the real work then
+ Strexpr.search(Stramount);
+ nTotal = Strexpr.cap(Strexpr.numCaptures() - 1).toInt() * TITRAQ_MINSINHOUR;
+ nTotal += Strexpr.cap(Strexpr.numCaptures()).toInt();
+ this->setValue(nTotal);
+ }
}
// Return a text formatted representation
@@ -26,8 +29,8 @@
int nHours = 0;
int nMins = this->value();
- nHours = nMins / HOURAMOUNT; // Calculate total hours
- nMins = nMins % HOURAMOUNT; // Calculate total minutes
+ nHours = nMins / TITRAQ_MINSINHOUR; // Calculate total hours
+ nMins = nMins % TITRAQ_MINSINHOUR; // Calculate total minutes
Strout = trUtf8("%1:%2").arg(nHours).arg(nMins); // Format string
return Strout;
|
|