configurable entrance
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 3 Jan 2011 08:00:50 +0000 (08:00 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 3 Jan 2011 08:00:50 +0000 (08:00 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@703 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/mwin/entrancetab.cpp
src/mwin/entrancetab.h
src/mwin/overview.cpp

index 1c978cb..f8c3e0a 100644 (file)
 #include <QComboBox>
 #include <QLabel>
 #include <QLineEdit>
+#include <QMenuBar>
 #include <QMessageBox>
 #include <QPushButton>
 #include <QSettings>
 #include <QStandardItemModel>
 #include <QTimer>
+#include <QFormLayout>
+#include <QSpinBox>
 
 MEntranceTab::MEntranceTab(QString pk)
 {
@@ -82,6 +85,14 @@ MEntranceTab::MEntranceTab(QString pk)
        tm->start(10000);
 }
 
+QMenuBar* MEntranceTab::menu() const
+{
+       QMenuBar *mb=new QMenuBar;
+       QMenu*m=mb->addMenu("&Entrance");
+       m->addAction("&Configure...",this,SLOT(configure()));
+       m->addAction("&Recheck events",this,SLOT(initialize()));
+       return mb;
+}
 
 /**while the object lives the tab handed to it is disabled, it automatically reenables when the disable object dies; it also refocuses the scan line*/
 class METUtility
@@ -116,7 +127,7 @@ void MEntranceTab::entranceValidate()
        METUtility mdis(this);
        //avoid double scans
        QDateTime now=QDateTime::currentDateTime();
-       if(tid==lastbarcode && lastbcscan.addSecs(20)>=now)
+       if(tid==lastbarcode && lastbcscan.addSecs(10)>=now)
                return;
        lastbarcode=tid;
        lastbcscan=now;
@@ -172,22 +183,34 @@ void MEntranceTab::entranceValidate()
                orderbtn->setEnabled(false);
 }
 
-void MEntranceTab::initialize()
+static bool eventIsEarlier(const MOEvent&e1,const MOEvent&e2)
+{
+       return e1.start()<e2.start();
+}
+
+void MEntranceTab::initialize(bool force)
 {
        METUtility mdis(this);
        //check whether an update should be forced
        QDateTime now=QDateTime::currentDateTime();
-       if(lasteventupdate.addSecs(3600)>now)return;
+       if(!force)
+               if(lasteventupdate.addSecs(3600)>now)return;
        //get currently displayed event
        int ci=entranceevent->currentIndex();
        int cev=-1;
        if(ci>=0)cev=entranceevent->itemData(ci).toInt();
        ci=-1;
        //get event list
-       MTGetEntranceEvents gee=MTGetEntranceEvents::query();
+       QSettings set;
+       set.beginGroup("profiles/"+profilekey+"/entrance");
+       MTGetEntranceEvents gee=MTGetEntranceEvents::query(
+               set.value("maxstart",24).toInt()*3600,
+               set.value("maxend",0).toInt()*3600
+       );
        if(gee.hasError())return;
        lasteventupdate=now;
        QList<MOEvent>evlst=gee.getevents();
+       qSort(evlst.begin(),evlst.end(),eventIsEarlier);
        //fill combobox from eventmodel
        entranceevent->clear();
        for(int i=0;i<evlst.size();i++){
@@ -236,4 +259,38 @@ void MEntranceTab::resetAmounts()
        amused->setText("0");
        amopen->setText("0");
 //     amreserved->setText("0");
-}
\ No newline at end of file
+}
+
+void MEntranceTab::configure()
+{
+       QSettings set;
+       set.beginGroup("profiles/"+profilekey+"/entrance");
+       QDialog d(this);
+       d.setWindowTitle(tr("Entrance Configuration"));
+       QVBoxLayout*vl;
+       d.setLayout(vl=new QVBoxLayout);
+       QFormLayout*fl;
+       vl->addLayout(fl=new QFormLayout,1);
+       QSpinBox*maxstart,*maxend;
+       fl->addRow(tr("Show events that start within hours:"),maxstart=new QSpinBox);
+       maxstart->setRange(0,10000);
+       maxstart->setValue(set.value("maxstart",24).toInt());
+       fl->addRow(tr("Show events a maximum of hours after they end:"),maxend=new QSpinBox);
+       maxend->setRange(0,1000);
+       maxend->setValue(set.value("maxend",0).toInt());
+       fl->addRow(tr("Use Cache:"),new QLabel);
+       fl->addRow(tr("Cache update interval:"),new QLabel);
+       QHBoxLayout*hl;
+       vl->addLayout(hl=new QHBoxLayout,0);
+       hl->addStretch(1);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("Ok")));
+       connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+       hl->addWidget(p=new QPushButton(tr("Cancel")));
+       connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+       //show
+       if(d.exec()!=QDialog::Accepted)return;
+       //save
+       set.setValue("maxstart",maxstart->value());
+       set.setValue("maxend",maxend->value());
+}
index 3b15279..013c70d 100644 (file)
@@ -16,6 +16,7 @@
 #include <QDateTime>
 #include <QWidget>
 
+class QMenuBar;
 class QComboBox;
 class QLabel;
 class QLineEdit;
@@ -31,9 +32,13 @@ class MEntranceTab:public QWidget
        public:
                /**construct the window with web-request/session handler and QSettings-key for current profile*/
                MEntranceTab(QString);
+               
+               ///creates a menu for the entrance tab
+               QMenuBar*menu()const;
        public slots:
-               /**initializes the tab*/
-               void initialize();
+               /**initializes the tab
+               \param force if true an update is forced, if false the update is only done if the last update has been more than an hour in the past*/
+               void initialize(bool force=true);
        private slots:
                /**react on entry in Entrance tab*/
                void entranceValidate();
@@ -43,6 +48,8 @@ class MEntranceTab:public QWidget
                void openOrder();
                /**resets the amount labels*/
                void resetAmounts();
+               /**configure the entrance*/
+               void configure();
        private:
                friend class METUtility;
                //the profile associated with this session
index 19224cf..971807f 100644 (file)
@@ -134,7 +134,8 @@ MOverview::MOverview(QString pk)
        connect(ordertab,SIGNAL(eventModel()), eventtab,SLOT(eventModel()), Qt::DirectConnection);
        
        //Entrance Control Tab
-       addTab(entrancetab=new MEntranceTab(pk),tr("Entrance"));
+       entrancetab=new MEntranceTab(pk);
+       addTab(entrancetab,tr("Entrance"),entrancetab->menu());
        
 
        //unused tab disabling...
@@ -217,7 +218,7 @@ void MOverview::tabChanged(int idx)
        MTabWin::tabChanged(idx);
        QWidget*w=currentTab();
        if(w==entrancetab){
-               entrancetab->initialize();
+               entrancetab->initialize(false);
        }
 }