From c3bbfba2aaa06baa7fa8a52d03e0b8a4ef490a37 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Wed, 18 Nov 2015 15:15:04 +0100 Subject: [PATCH] allow cloning of events --- src/dialogs/eventedit.cpp | 32 ++++++++++++++++++++++---------- src/dialogs/eventedit.h | 13 ++++++++++++- src/mwin/eventstab.cpp | 23 ++++++++++++++++++++--- src/mwin/eventstab.h | 2 ++ 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/dialogs/eventedit.cpp b/src/dialogs/eventedit.cpp index 610a2f9..1ab4b9e 100644 --- a/src/dialogs/eventedit.cpp +++ b/src/dialogs/eventedit.cpp @@ -46,18 +46,30 @@ #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()); + 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)); diff --git a/src/dialogs/eventedit.h b/src/dialogs/eventedit.h index 61e449b..161fcad 100644 --- a/src/dialogs/eventedit.h +++ b/src/dialogs/eventedit.h @@ -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(); diff --git a/src/mwin/eventstab.cpp b/src/mwin/eventstab.cpp index 1017e8a..5297175 100644 --- a/src/mwin/eventstab.cpp +++ b/src/mwin/eventstab.cpp @@ -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; diff --git a/src/mwin/eventstab.h b/src/mwin/eventstab.h index 4c48108..da82521 100644 --- a/src/mwin/eventstab.h +++ b/src/mwin/eventstab.h @@ -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*/ -- 1.7.2.5