fix search result
authornicola <nicola@nicola-x910.(none)>
Thu, 4 Mar 2010 14:09:52 +0000 (15:09 +0100)
committernicola <nicola@nicola-x910.(none)>
Thu, 4 Mar 2010 14:09:52 +0000 (15:09 +0100)
badgedata.cpp
badgedata.h
badgewindow.cpp
dialogday.cpp
dialogsearch.cpp
dialogsearch.h
main.cpp

index 442c5d0..001d9f2 100644 (file)
@@ -13,7 +13,7 @@ bool BadgeData::setTimetable(TimeTable tt)
     QFile data;
     TimeTable dum;
     qint64 pos = 0;
-
+    //qDebug() << "setTimetable TIME " << tt.entrance.toString(Qt::TextDate) << endl;
     data.setFileName(QDir::homePath() + QDir::separator() + "badge.data");
     data.open(QIODevice::ReadWrite);
     QDataStream out(&data);
@@ -47,6 +47,7 @@ bool BadgeData::getTimetable(TimeTable &tt)
         out >> dum;
         if (dum.day == tt.day) {
             tt = dum;
+            //qDebug() << "getTimetable TIME " << tt.entrance.toString(Qt::TextDate) << endl;
             data.close();
             return true;
         }
@@ -55,7 +56,7 @@ bool BadgeData::getTimetable(TimeTable &tt)
     return false;
 }
 
-QTime BadgeData::totalTime(QDate begin, QDate end)
+int BadgeData::totalTime(QDate begin, QDate end)
 {
     QFile data;
     TimeTable dum;
@@ -67,9 +68,12 @@ QTime BadgeData::totalTime(QDate begin, QDate end)
     data.open(QIODevice::ReadOnly);
     QDataStream out(&data);
     while (!data.atEnd()) {
+        //qDebug() << "NEL WHILE\n";
         out >> dum;
+        //qDebug() << "day " << dum.day.toString(Qt::TextDate) << " BEGIN " << begin.toString("yyyy-M-d") << " END " << end.toString("yyyy-M-d") << endl;
         if (dum.day >=  begin && dum.day <= end) {
             totalInSeconds += dum.entrance.secsTo(dum.exit);
+            //qDebug() << "FOUND " << totalInSeconds << endl;
             if (dum.firstPause != dum.endFirstPause) {
                 totalInSeconds -= dum.firstPause.secsTo(dum.endFirstPause);
             }
@@ -78,12 +82,12 @@ QTime BadgeData::totalTime(QDate begin, QDate end)
                 totalInSeconds -= dum.secondPause.secsTo(dum.endSecondPause);
             }
 
-
+                //qDebug() << "TOT SEC = " << totalInSeconds << endl;
 
         }
 
     }
     data.close();
-    total.setHMS((int)(totalInSeconds / 3600), (int) ((totalInSeconds % 3600) / 60), 0);
-    return total;
+    //total.setHMS((int)(totalInSeconds / 3600), (int) ((totalInSeconds % 3600) / 60), 0);
+    return totalInSeconds;
 }
index 0a30168..8704c62 100644 (file)
@@ -11,7 +11,7 @@ public:
     BadgeData();
     bool setTimetable(TimeTable in);
     bool getTimetable(TimeTable &out);
-    QTime totalTime(QDate begin, QDate end);
+    int totalTime(QDate begin, QDate end);
 };
 
 #endif // BADGEDATA_H
index 395d1d0..77f346d 100644 (file)
@@ -55,7 +55,7 @@ void BadgeWindow::selectedDay(QDate date)
 void BadgeWindow::search()
 {
     DialogSearch searchDialog;
-    QTime total;
+    int total;
     QString message;
     QString hours;
     QString minutes;
@@ -63,8 +63,9 @@ void BadgeWindow::search()
 
     total = searchDialog.totalHours(ok);
     if (ok) {
-        hours.setNum(total.hour());
-        minutes.setNum(total.minute());
+            qDebug() << "TIME " << total;
+        hours.setNum((int)(total / 3600));
+        minutes.setNum((int) ((total % 3600) / 60));
         message = "Total time is: " + hours + " hours and " + minutes + " minutes";
         QMessageBox::information(this, tr("Badge"), tr(message.toLatin1()));
     }
index 13ad4a8..2f170ff 100644 (file)
@@ -181,29 +181,29 @@ void DialogDay::enableSecond(bool enable)
 
 TimeTable DialogDay::getTimes(TimeTable timetable)
 {
-    qDebug () << "ENT " << timetable.entrance.toString("hh:mm") << endl;
-    timeEditEntrance->setValueText(timetable.entrance.toString("hh:mm") + ":00");
-    timeEditExit->setValueText(timetable.exit.toString("hh:mm") + ":00");
-    timeEditFBegin->setValueText(timetable.firstPause.toString("hh:mm") + ":00" );
-    timeEditEndF->setValueText(timetable.endFirstPause.toString("hh:mm") + ":00" );
-    timeEditSBegin->setValueText(timetable.secondPause.toString("hh:mm") + ":00");
-    timeEditEndS->setValueText(timetable.endSecondPause.toString("hh:mm") + ":00");
+    //qDebug () << "ENT " << timetable.entrance.toString("hh:mm") << endl;
+    timeEditEntrance->setValueText(timetable.entrance.toString("hh:mm") /*+ ":00"*/);
+    timeEditExit->setValueText(timetable.exit.toString("hh:mm")/* + ":00"*/);
+    timeEditFBegin->setValueText(timetable.firstPause.toString("hh:mm") /*+ ":00" */);
+    timeEditEndF->setValueText(timetable.endFirstPause.toString("hh:mm")/* + ":00"*/ );
+    timeEditSBegin->setValueText(timetable.secondPause.toString("hh:mm") /*+ ":00"*/);
+    timeEditEndS->setValueText(timetable.endSecondPause.toString("hh:mm")/* + ":00"*/);
 
     checkBoxFirst->setChecked(false);
     checkBoxSecond->setChecked(false);
 
     if (timetable.firstPause != timetable.endFirstPause) {
         checkBoxFirst->setChecked(true);
-        timeEditFBegin->setValueText(timetable.firstPause.toString("hh:mm") + ":00");
+        timeEditFBegin->setValueText(timetable.firstPause.toString("hh:mm")/* + ":00"*/);
         timeEditFBegin->setEnabled(true);
-        timeEditEndF->setValueText(timetable.endFirstPause.toString("hh:mm") + ":00");
+        timeEditEndF->setValueText(timetable.endFirstPause.toString("hh:mm") /*+ ":00"*/);
         timeEditEndF->setEnabled(true);
     }
     if (timetable.secondPause != timetable.endSecondPause) {
         checkBoxSecond->setChecked(true);
-        timeEditSBegin->setValueText(timetable.secondPause.toString("hh:mm") + ":00");
+        timeEditSBegin->setValueText(timetable.secondPause.toString("hh:mm") /*+ ":00"*/);
         timeEditSBegin->setEnabled(true);
-        timeEditEndS->setValueText(timetable.endSecondPause.toString("hh:mm") + ":00");
+        timeEditEndS->setValueText(timetable.endSecondPause.toString("hh:mm")/* + ":00"*/);
         timeEditEndS->setEnabled(true);
     }
 
@@ -211,16 +211,16 @@ TimeTable DialogDay::getTimes(TimeTable timetable)
     if (this->exec() == QDialog::Accepted) {
 
 
-        timetable.entrance =  QTime::fromString(timeEditEntrance->valueText(), "hh:mm:ss");
-        timetable.exit =  QTime::fromString(timeEditExit->valueText(), "hh:mm:ss");
+        timetable.entrance =  QTime::fromString(timeEditEntrance->valueText(), "hh:mm");
+        timetable.exit =  QTime::fromString(timeEditExit->valueText(), "hh:mm");
         if (checkBoxFirst->isChecked()) {
 
-            timetable.firstPause = QTime::fromString(timeEditFBegin->valueText(), "hh:mm:ss");
-            timetable.endFirstPause = QTime::fromString(timeEditEndF->valueText(), "hh:mm:ss");
+            timetable.firstPause = QTime::fromString(timeEditFBegin->valueText(), "hh:mm");
+            timetable.endFirstPause = QTime::fromString(timeEditEndF->valueText(), "hh:mm");
         }
         if (checkBoxSecond->isChecked()) {
-            timetable.secondPause = QTime::fromString(timeEditSBegin->valueText(), "hh:mm:ss");
-            timetable.endSecondPause = QTime::fromString(timeEditEndS->valueText(), "hh:mm:ss");
+            timetable.secondPause = QTime::fromString(timeEditSBegin->valueText(), "hh:mm");
+            timetable.endSecondPause = QTime::fromString(timeEditEndS->valueText(), "hh:mm");
         }
         return timetable;
     }
index c47a79e..81c340e 100644 (file)
@@ -118,7 +118,7 @@ void DialogSearch::changeEvent(QEvent *e)
 
 
 
-QTime DialogSearch::totalHours(bool &ok)
+int DialogSearch::totalHours(bool &ok)
 {
 
 
@@ -134,12 +134,13 @@ QTime DialogSearch::totalHours(bool &ok)
         ok = true;
         //qDebug() << "FORM " << locale.dateFormat(QLocale::LongFormat) << endl;
         //qDebug() << "STR " << pushButtonStart->valueText() << " DATE " << QDate::fromString(begin, "dddd d MMMM yyyy").toString() << endl;
+        //qDebug() << "STR " << pushButtonEnd->valueText() << " DATE " << QDate::fromString(end, "dddd d MMMM yyyy").toString() << endl;
         return data.totalTime(QDate::fromString(begin, "dddd d MMMM yyyy"), QDate::fromString(end, "dddd d MMMM yyyy"));
     }
     ok = false;
 
 
-    return QTime(0, 0, 0, 0);
+    return 0;
 }
 
 void DialogSearch::accept()
index 4dbbe73..f63e993 100644 (file)
@@ -29,7 +29,7 @@ class DialogSearch : public QDialog {
 public:
     DialogSearch(QWidget *parent = 0);
     ~DialogSearch();
-    QTime totalHours(bool &ok);
+    int totalHours(bool &ok);
 protected:
     void changeEvent(QEvent *e);
 
index 1177caa..7eed133 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,8 +1,6 @@
 #include <QtGui/QApplication>
 #include "badgewindow.h"
 
-//
-
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);