ma first plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ma first plugin

cantcode
Made ma first plugin wooohhhoooooo!
I followed the instructions from the wiki (http://wiki.librecad.org/index.php/LibreCAD_Plugin_Development) and used (I think) 2.0.0rc1.
(instead of using the files "document_interface.h" and "qc_plugininterface.h" from the source directory, I copied them over)
There is some stuff that I had to do differently than stated in the wiki:
#1
wiki:
virtual void execComm(Document_Interface *doc, QWidget *parent);
I had to use:
virtual void execComm(Document_Interface *doc, QWidget *parent, QString cmd);

#2
I had to add "#include <QString>" in myplug.cpp

#3
"virtual QString menu() const" is not present in "qc_plugininterface.h "
but I used  "virtual PluginCapabilities getCapabilities() const;" instead (I think this is a replacement for the menu method?)
here is the myplug.cpp file:

01: #include "myplug.h"
02: #include <QMessageBox>
03: #include <QString>
04: #include "document_interface.h"
05: 
06: myplug::myplug(QObject *parent) :
07:     QObject(parent)
08: {
09: }
10: 
11: QString myplug::name() const {
12:     return (tr("My first plugin woooho."));
13: }
14: 
15: //QString myplug::menu() const{
16: //    return("Help");
17: //}
18: 
19: PluginCapabilities myplug::getCapabilities() const{
20:     PluginMenuLocation *pml =  new PluginMenuLocation("Help", "mytestplugin");
21:     PluginCapabilities pc;
22:     pc.menuEntryPoints.append(*pml);
23:     return pc;
24: }
25: 
26: void myplug::execComm(Document_Interface *doc, QWidget *parent, QString cmd){
27:     Q_UNUSED(doc);
28:     QMessageBox::information(parent, "LC rules", "this is my first plugin");
29: 
30: }
31: 
32: Q_EXPORT_PLUGIN2(myplugin, myplug);
33: 
34:

here is how my myplug.h file looks like:

01: #ifndef MYPLUG_H
02: #define MYPLUG_H
03: 
04: //#include <QObject>
05: #include "qc_plugininterface.h"
06: 
07: class myplug : public QObject, QC_PluginInterface
08: {
09:     Q_OBJECT
10:     Q_INTERFACES(QC_PluginInterface)
11: public:
12:     explicit myplug(QObject *parent = 0);
13: 
14: //    virtual QString menu() const;
15:     virtual PluginCapabilities getCapabilities() const;
16:     virtual QString name() const;
17:     virtual void execComm(Document_Interface *doc, QWidget *parent, QString cmd);
18:    
19: signals:
20:    
21: public slots:
22:    
23: };
24: 
25: #endif // MYPLUG_H
26: 
27:

This code may have some bad coding style and some bugs.
Would be nice if someone could tell if there is a better way to do things in a different/better way.

here is the code of both files pasted as plain text:
http://pastebin.com/ESNHZFqp