allow cloning of events
authorKonrad Rosenbaum <konrad@silmor.de>
Wed, 18 Nov 2015 14:15:04 +0000 (15:15 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Wed, 18 Nov 2015 14:15:04 +0000 (15:15 +0100)
src/dialogs/eventedit.cpp
src/dialogs/eventedit.h
src/mwin/eventstab.cpp
src/mwin/eventstab.h

index 610a2f9..1ab4b9e 100644 (file)
 #include "flagedit.h"
 #include "misc.h"
 
-MEventEditor::MEventEditor(QWidget*pw,qint64 id)
+MEventEditor::MEventEditor(QWidget*pw, OpenMode mode, qint64 id)
        :QDialog(pw)
 {
-       MTGetEvent ge=MTGetEvent::query(id);
-       if(ge.stage()!=ge.Success){
-               QMessageBox::warning(this,tr("Warning"),tr("Unable to load event from server."));
-               //make myself disappear immediately
-               QTimer::singleShot(1,this,SLOT(reject()));
-               //no point in setting up widgets
-               return;
+       if(id>=0){
+               MTGetEvent ge=MTGetEvent::query(id);
+               if(ge.stage()!=ge.Success){
+                       QMessageBox::warning(this,tr("Warning"),tr("Unable to load event from server."));
+                       //make myself disappear immediately
+                       QTimer::singleShot(1,this,SLOT(reject()));
+                       //no point in setting up widgets
+                       return;
+               }
+               event=ge.getevent().value();
        }
-       event=ge.getevent().value();
+       switch(mode){
+               case OpenMode::Auto:
+                       if(id>=0)break;
+                       //else fallthru
+               case OpenMode::Create:
+                       event.setid(Nullable<qint64>());
+                       break;
+               default:break;
+       }
+
        setWindowTitle(tr("Event Editor"));
        
        QGridLayout*gl;
@@ -108,7 +120,7 @@ MEventEditor::MEventEditor(QWidget*pw,qint64 id)
        endtime->setDisplayFormat(tr("ddd MMMM d yyyy, h:mm ap","time format"));
        endtime->setCalendarPopup(true);
        connect(endtime,SIGNAL(dateTimeChanged(const QDateTime&)),this,SLOT(endTimeChanged(const QDateTime&)));
-       if(event.id().isNull()){
+       if(event.id().isNull() && event.start().isNull()){
                QDateTime tt(QDate::currentDate().addDays(1),QTime(20,0));//default: tomorrow 8pm
                starttime->setDateTime(tt);
                endtime->setDateTime(tt.addSecs(3600));
index 61e449b..161fcad 100644 (file)
@@ -33,8 +33,19 @@ class MEventEditor:public QDialog
 {
        Q_OBJECT
        public:
+               ///Mode for opening the editor window
+               enum class OpenMode{
+                       /// Auto-Detect by Event-ID
+                       Auto,
+                       /// Edit the existing event
+                       Edit,
+                       /// Create a new event, if an ID is given use it as template only
+                       Create
+               };
                /**opens the editor, retrieves the event automatically if given*/
-               MEventEditor(QWidget*,qint64 id=-1);
+               MEventEditor(QWidget*w,qint64 id=-1):MEventEditor(w,OpenMode::Auto,id){}
+               /**opens the editor*/
+               MEventEditor(QWidget*,OpenMode,qint64 id=-1);
        private slots:
                /**sends the event back to the database*/
                void writeBack();
index 1017e8a..5297175 100644 (file)
@@ -62,10 +62,14 @@ MEventsTab::MEventsTab(QString pk)
        hl->addSpacing(5);
        hl->addLayout(vl=new QVBoxLayout,0);
        QPushButton*p;
-       vl->addWidget(p=new QPushButton(tr("New Event...")),0);
-       connect(p,SIGNAL(clicked()),this,SLOT(newEvent()));
+       vl->addWidget(p=new QPushButton(tr("New Event")),0);
        p->setEnabled(req->hasRight(req->RCreateEvent));
-       vl->addWidget(p=new QPushButton(tr("Details...")),0);
+        QMenu*m;
+        p->setMenu(m=new QMenu);
+        m->addAction(tr("New Event..."),this,SLOT(newEvent()));
+        m->addAction(tr("Clone Current Event..."),this,SLOT(cloneEvent()));
+
+        vl->addWidget(p=new QPushButton(tr("Details...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(editEvent()));
        p->setEnabled(req->hasRight(req->RGetEvent));
        vl->addSpacing(15);
@@ -170,6 +174,19 @@ void MEventsTab::newEvent()
        updateEvents();
 }
 
+void MEventsTab::cloneEvent()
+{
+       int id;
+       QModelIndexList ilst=eventtable->selectionModel()->selectedIndexes();
+       if(ilst.size()<1)return;
+       QModelIndex idx=eventmodel->index(ilst[0].row(),0);
+       id=eventmodel->data(idx,Qt::UserRole).toInt();
+       if(id<0)return;
+       MEventEditor ed(this,MEventEditor::OpenMode::Create,id);
+       ed.exec();
+       updateEvents();
+}
+
 void MEventsTab::editEvent()
 {
        int id;
index 4c48108..da82521 100644 (file)
@@ -48,6 +48,8 @@ class MEventsTab:public QWidget
        private slots:
                /**create a new event*/
                void newEvent();
+               /**create a new event as copy*/
+               void cloneEvent();
                /**edit existing event*/
                void editEvent();
                /**open event summary*/