From 5aa0b5d12ff8feadfbe39a099bf13b401910fd9b Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Thu, 17 Mar 2016 09:41:13 +0100 Subject: [PATCH] draft of editor plugins, not stable yet --- src/dialogs/dialogs.pri | 8 ++- src/dialogs/editreg.cpp | 23 ++++++++++ src/dialogs/editreg.h | 19 ++++++++ src/dialogs/eventedit.h | 6 +- src/main.cpp | 2 + src/main.h | 8 +--- src/misc/barcode-plugin.h | 8 +--- src/misc/editor-plugin.cpp | 81 ++++++++++++++++++++++++++++++++++++ src/misc/editor-plugin.h | 99 ++++++++++++++++++++++++++++++++++++++++++++ src/misc/misc.pri | 6 ++- src/mwin/carttab.cpp | 13 ++++-- src/mwin/carttab.h | 6 ++- src/mwin/eventstab.cpp | 14 +++++- src/smoke-export.h | 22 ++++++++++ wob/transact/backup.wolf | 2 +- 15 files changed, 289 insertions(+), 28 deletions(-) create mode 100644 src/dialogs/editreg.cpp create mode 100644 src/dialogs/editreg.h create mode 100644 src/misc/editor-plugin.cpp create mode 100644 src/misc/editor-plugin.h create mode 100644 src/smoke-export.h diff --git a/src/dialogs/dialogs.pri b/src/dialogs/dialogs.pri index 52975ea..2ead568 100644 --- a/src/dialogs/dialogs.pri +++ b/src/dialogs/dialogs.pri @@ -14,7 +14,8 @@ HEADERS += \ dialogs/orderauditdlg.h \ dialogs/orderauditdlg_p.h \ dialogs/backupdlg.h \ - dialogs/payedit.h + dialogs/payedit.h \ + dialogs/editreg.h SOURCES += \ dialogs/configdialog.cpp \ @@ -31,8 +32,9 @@ SOURCES += \ dialogs/wizard.cpp \ dialogs/orderauditdlg.cpp \ dialogs/backupdlg.cpp \ - dialogs/payedit.cpp + dialogs/payedit.cpp \ + dialogs/editreg.cpp RESOURCES += dialogs/dialogfiles.qrc -INCLUDEPATH += ./dialogs \ No newline at end of file +INCLUDEPATH += ./dialogs diff --git a/src/dialogs/editreg.cpp b/src/dialogs/editreg.cpp new file mode 100644 index 0000000..fe680dd --- /dev/null +++ b/src/dialogs/editreg.cpp @@ -0,0 +1,23 @@ +// +// C++ Interface: Editor Registering +// +// Description: registers all standard dialogs +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "editreg.h" +#include "editor-plugin.h" + +#include "eventedit.h" + + +void registerEditors() +{ + MEditorPlugin::registerEditor(MEditorPlugin::EditorType::EventEdit,MEditorPlugin::GuiMode::Expert); + MEditorPlugin::registerEditor(MEditorPlugin::EditorType::EventView,MEditorPlugin::GuiMode::Expert); +} diff --git a/src/dialogs/editreg.h b/src/dialogs/editreg.h new file mode 100644 index 0000000..18643d7 --- /dev/null +++ b/src/dialogs/editreg.h @@ -0,0 +1,19 @@ +// +// C++ Interface: Editor Registering +// +// Description: registers all standard dialogs +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_EDITREG_H +#define MAGICSMOKE_EDITREG_H + +void registerEditors(); + + +#endif diff --git a/src/dialogs/eventedit.h b/src/dialogs/eventedit.h index 161fcad..63f0b34 100644 --- a/src/dialogs/eventedit.h +++ b/src/dialogs/eventedit.h @@ -4,7 +4,7 @@ // Description: // // -// Author: Konrad Rosenbaum , (C) 2007-2011 +// Author: Konrad Rosenbaum , (C) 2007-2016 // // Copyright: See README/COPYING.GPL files that come with this distribution // @@ -43,9 +43,9 @@ class MEventEditor:public QDialog Create }; /**opens the editor, retrieves the event automatically if given*/ - MEventEditor(QWidget*w,qint64 id=-1):MEventEditor(w,OpenMode::Auto,id){} + Q_INVOKABLE MEventEditor(QWidget*w,qint64 id=-1):MEventEditor(w,OpenMode::Auto,id){} /**opens the editor*/ - MEventEditor(QWidget*,OpenMode,qint64 id=-1); + Q_INVOKABLE MEventEditor(QWidget*,OpenMode,qint64 id=-1); private slots: /**sends the event back to the database*/ void writeBack(); diff --git a/src/main.cpp b/src/main.cpp index f92e056..c48d8ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,7 @@ #include "misc.h" #include #include "boxwrapper.h" +#include "editreg.h" QString choseLanguage(bool warn) { @@ -412,6 +413,7 @@ void MApplication::initialize() initUpdater(); //init plugins MBarcodeHub::instance()->initialize(); + registerEditors(); } void MApplication::initUpdater() diff --git a/src/main.h b/src/main.h index 020a189..ef464b2 100644 --- a/src/main.h +++ b/src/main.h @@ -4,7 +4,7 @@ // Description: // // -// Author: Konrad Rosenbaum , (C) 2007-2014 +// Author: Konrad Rosenbaum , (C) 2007-2016 // // Copyright: See README/COPYING.GPL files that come with this distribution // @@ -19,11 +19,7 @@ /**show a dialog to change the language*/ QString choseLanguage(bool warn=true); -#ifdef MAGICSMOKE_LIB_BUILD -#define MAGICSMOKE_EXPORT Q_DECL_EXPORT -#else -#define MAGICSMOKE_EXPORT Q_DECL_IMPORT -#endif +#include "smoke-export.h" class QMenu; class EFilter; diff --git a/src/misc/barcode-plugin.h b/src/misc/barcode-plugin.h index dbeb6b3..05a91cd 100644 --- a/src/misc/barcode-plugin.h +++ b/src/misc/barcode-plugin.h @@ -4,7 +4,7 @@ // Description: // // -// Author: Konrad Rosenbaum , (C) 2013-2014 +// Author: Konrad Rosenbaum , (C) 2013-2016 // // Copyright: See README/COPYING.GPL files that come with this distribution // @@ -13,11 +13,7 @@ #ifndef MAGICSMOKE_BARCODE_PLUGIN_H #define MAGICSMOKE_BARCODE_PLUGIN_H -#ifdef MAGICSMOKE_LIB_BUILD -#define MAGICSMOKE_EXPORT Q_DECL_EXPORT -#else -#define MAGICSMOKE_EXPORT Q_DECL_IMPORT -#endif +#include "../smoke-export.h" #include #include diff --git a/src/misc/editor-plugin.cpp b/src/misc/editor-plugin.cpp new file mode 100644 index 0000000..2c2187a --- /dev/null +++ b/src/misc/editor-plugin.cpp @@ -0,0 +1,81 @@ +// +// C++ Interface: plugin base for editors +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "editor-plugin.h" + +#include +#include + +MEditorPlugin::~MEditorPlugin() +{ +} + + +static QMap,QList>editormap; + +const QMetaObject* MEditorPlugin::getEditorMetaObject(MEditorPlugin::EditorType et, MEditorPlugin::GuiMode gm) +{ + QPairkey(et,gm); + if(editormap.contains(key)){ + //find the default + for(auto info:editormap[key]) + if(info.isDefault)return info.metaObject; + //no default: use first + if(editormap[key].size()>0)return editormap[key][0].metaObject; + } + //fallback: none + return nullptr; +} + +void MEditorPlugin::registerEditor(MEditorPlugin::EditorType type, MEditorPlugin::GuiMode mode, const QMetaObject*meta,QString description) +{ + if(mode==GuiMode::None || type==EditorType::NoEditor)return; + QPairkey(type,mode); + if(!editormap.contains(key)) + editormap.insert(key,QList()); + EditorInfo info; + info.editorType=type; + info.guiMode=mode; + info.metaObject=meta; + if(description.isEmpty()){ + if(meta){ + for(int i=meta->classInfoOffset();iclassInfoCount();i++) + if(meta->classInfo(i).name()==QString("description")) + info.description=meta->classInfo(i).value(); + } + }else + info.description=description; + editormap[key].prepend(info); +} + +QList< MEditorPlugin::EditorInfo > MEditorPlugin::getEditorClassInfo(MEditorPlugin::EditorType et, MEditorPlugin::GuiMode gm) +{ + QPairkey(et,gm); + if(editormap.contains(key))return editormap[key]; + //fallback: none + return QList(); +} + +void MEditorPlugin::setEditorDefault(MEditorPlugin::EditorType et, MEditorPlugin::GuiMode gm, const QMetaObject*meta) +{ + QPairkey(et,gm); + if(!editormap.contains(key))return; + bool found=false; + for(auto info:editormap[key]) + if(info.metaObject==meta){ + found=true; + break; + } + if(!found)return; + for(auto info:editormap[key]) + info.isDefault=info.metaObject==meta; +} diff --git a/src/misc/editor-plugin.h b/src/misc/editor-plugin.h new file mode 100644 index 0000000..914fef3 --- /dev/null +++ b/src/misc/editor-plugin.h @@ -0,0 +1,99 @@ +// +// C++ Interface: plugin base for editors +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_EDITOR_PLUGIN_H +#define MAGICSMOKE_EDITOR_PLUGIN_H + +#include "../smoke-export.h" + +#include +#include +#include +#include +#include +#include +#include + +///base class of editor plugins +class MAGICSMOKE_EXPORT MEditorPlugin +{ + public: + virtual ~MEditorPlugin(); + + enum class EditorType{ + NoEditor, + EventView, + EventEdit, + OrderView, + OrderEdit, + }; + + enum class GuiMode{ + None=0, + Expert=1, + Wizard=2, + }; + + struct EditorInfo{ + EditorType editorType=EditorType::NoEditor; + GuiMode guiMode=GuiMode::None; + bool isDefault=false; + const QMetaObject*metaObject=nullptr; + QString description; + }; + + ///called by plugins to register a new editor +// static void registerEditor(EditorType type,GuiMode mode,const char*className,QString description=QString()) +// {registerEditor(type,mode,QMetaType::type(className),description);} + ///called by plugins to register a new editor + template + static void registerEditor(EditorType type,GuiMode mode,QString d=QString()) + { + registerEditor(type,mode,&T::staticMetaObject,d); + } + ///called by plugins to register a new editor + static void registerEditor(EditorType type,GuiMode mode,const QMetaObject*,QString d=QString()); + + ///called by configuration dialog to set a specific editor as default of its class + template + static void setEditorDefault(EditorType et,GuiMode gm) + { + setEditorDefault(et,gm,&T::staticMetaObject); + } + ///called by configuration dialog to set a specific editor as default of its class + static void setEditorDefault(EditorType,GuiMode,const QMetaObject*); + + ///Returns the configured ID of the Editor. + static const QMetaObject* getEditorMetaObject(EditorType,GuiMode); + + ///Returns all editors registered to a specific + static QList getEditorClassInfo(EditorType,GuiMode); + + ///called whenever a specific editor is needed + template + static QWidget* createEditor(EditorType et,GuiMode gm,Args...args) + { + const QMetaObject*mobj=getEditorMetaObject(et,gm); + qDebug()<<"meta"<<(int)mobj; + if(!mobj)return nullptr; + QObject*obj=mobj->newInstance(Q_ARG(Args,args)...); + qDebug()<<"obj"<<(int)obj; + return qobject_cast< QWidget* >(obj); + } +}; + +#define MEditorPlugin_IID "de.silmor.MagicSmoke.EditorPlugin/1.0" + +Q_DECLARE_INTERFACE(MEditorPlugin, MEditorPlugin_IID); + + +#endif diff --git a/src/misc/misc.pri b/src/misc/misc.pri index 565a3d5..978d20d 100644 --- a/src/misc/misc.pri +++ b/src/misc/misc.pri @@ -3,7 +3,8 @@ HEADERS += \ $$PWD/waitcursor.h \ $$PWD/sclock.h \ $$PWD/dommodel.h \ - $$PWD/barcode-plugin.h + $$PWD/barcode-plugin.h \ + $$PWD/editor-plugin.h SOURCES += \ $$PWD/code39.cpp \ @@ -11,6 +12,7 @@ SOURCES += \ $$PWD/waitcursor.cpp \ $$PWD/sclock.cpp \ $$PWD/dommodel.cpp \ - $$PWD/barcode-plugin.cpp + $$PWD/barcode-plugin.cpp \ + $$PWD/editor-plugin.cpp INCLUDEPATH += $$PWD diff --git a/src/mwin/carttab.cpp b/src/mwin/carttab.cpp index 60307a6..5e3a974 100644 --- a/src/mwin/carttab.cpp +++ b/src/mwin/carttab.cpp @@ -337,16 +337,21 @@ void MCartTab::addTicketForEvent(qint64 id, qint64 prcid) pcidx=box->currentIndex(); } //copy to cart + addTicketForEvent(ev,ep[pcidx]); +} + +void MCartTab::addTicketForEvent ( const MOEvent&ev, const MOEventPrice& prc) +{ int cr=cartmodel->rowCount(); cartmodel->insertRows(cr,1); cartmodel->setData(cartmodel->index(cr,0),1); - cartmodel->setData(cartmodel->index(cr,0),id,CART_IDROLE); + cartmodel->setData(cartmodel->index(cr,0),ev.id().value(),CART_IDROLE); cartmodel->setData(cartmodel->index(cr,0),CART_TICKET,CART_TYPEROLE); - cartmodel->setData(cartmodel->index(cr,0),ep[pcidx].pricecategoryid().value(),CART_PRICEIDROLE); - cartmodel->setData(cartmodel->index(cr,0),ep[pcidx].price().value(),CART_PRICEROLE); + cartmodel->setData(cartmodel->index(cr,0),prc.pricecategoryid().value(),CART_PRICEIDROLE); + cartmodel->setData(cartmodel->index(cr,0),prc.price().value(),CART_PRICEROLE); cartmodel->setData(cartmodel->index(cr,1),ev.title().value()); cartmodel->setData(cartmodel->index(cr,2),ev.startTimeString()); - QString pcn=cent2str(ep[pcidx].price())+" ("+ep[pcidx].pricecategory().value().name().value()+")"; + QString pcn=cent2str(prc.price())+" ("+prc.pricecategory().value().name().value()+")"; cartmodel->setData(cartmodel->index(cr,3),pcn); carttable->resizeColumnsToContents(); } diff --git a/src/mwin/carttab.h b/src/mwin/carttab.h index 9a48a7d..51687ed 100644 --- a/src/mwin/carttab.h +++ b/src/mwin/carttab.h @@ -4,7 +4,7 @@ // Description: // // -// Author: Konrad Rosenbaum , (C) 2007-2011 +// Author: Konrad Rosenbaum , (C) 2007-2016 // // Copyright: See README/COPYING.GPL files that come with this distribution // @@ -39,6 +39,8 @@ class MOCartOrder; class MOCartItem; class MOCartTicket; class MOCartVoucher; +class MOEvent; +class MOEventPrice; class MOOrder; /**Main Overview Window: cart tab*/ @@ -136,6 +138,8 @@ class MCartTab:public QWidget /**helper for cartAddTicket and eventOrderTicket: choses a price category and then adds the ticket*/ void addTicketForEvent(qint64,qint64 prcid=-1); + /**helper for cartAddTicket and eventOrderTicket: choses a price category and then adds the ticket*/ + void addTicketForEvent(const MOEvent&,const MOEventPrice&); }; /**Helper class for shopping cart: allow editing amount, but nothing else*/ diff --git a/src/mwin/eventstab.cpp b/src/mwin/eventstab.cpp index 4afafe8..912c63d 100644 --- a/src/mwin/eventstab.cpp +++ b/src/mwin/eventstab.cpp @@ -18,6 +18,8 @@ #include "msinterface.h" #include "pricecatdlg.h" +#include "editor-plugin.h" + #include "eventstab.h" #include "MTGetAllEvents" @@ -304,8 +306,12 @@ void MEventsTab::eventOrderTicketUrl(const QUrl &url) void MEventsTab::newEvent() { - MEventEditor ed(this); - ed.exec(); +// MEventEditor ed(this); + QDialog *ed=qobject_cast(MEditorPlugin::createEditor(MEditorPlugin::EditorType::EventEdit,MEditorPlugin::GuiMode::Expert,this)); + if(ed==nullptr)qDebug()<<"OUCH"; + ed->exec(); + ed->deleteLater(); +// ed.exec(); updateEvents(); } @@ -428,6 +434,10 @@ void MEventsTab::selectEventIds(QList< int >& eids, bool multi) const connect(tv,SIGNAL(doubleClicked(const QModelIndex&)),&dlg,SLOT(accept())); hl->addWidget(p=new QPushButton(tr("Cancel")),0); connect(p,SIGNAL(clicked()),&dlg,SLOT(reject())); + //adjust size + dlg.setMinimumSize(400,300); + dlg.resize(topLevelWidget()->size()*0.66); + dlg.setSizeGripEnabled(true); //wait for it if(dlg.exec()!=QDialog::Accepted)return; //get selection diff --git a/src/smoke-export.h b/src/smoke-export.h new file mode 100644 index 0000000..9a87359 --- /dev/null +++ b/src/smoke-export.h @@ -0,0 +1,22 @@ +// +// C++ Interface: definition of symbol export +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2013-2014 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_EXPORT_H +#define MAGICSMOKE_EXPORT_H + +#ifdef MAGICSMOKE_LIB_BUILD +#define MAGICSMOKE_EXPORT Q_DECL_EXPORT +#else +#define MAGICSMOKE_EXPORT Q_DECL_IMPORT +#endif + +#endif diff --git a/wob/transact/backup.wolf b/wob/transact/backup.wolf index 0225a48..780ad98 100644 --- a/wob/transact/backup.wolf +++ b/wob/transact/backup.wolf @@ -32,7 +32,7 @@ The name of the table to be backed up. First integer element to back up. Last integer element to back up. - List of string keys to back up. + List of string keys to back up. -- 1.7.2.5