Editing Mbarcode Plugin Tutorial
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 76: | Line 76: | ||
#define SHOWDIALOGACTION_H | #define SHOWDIALOGACTION_H | ||
- | |||
#include <mbarcode-qt/plugininterfaces.h> | #include <mbarcode-qt/plugininterfaces.h> | ||
#include <mbarcode-qt/pluginaction.h> | #include <mbarcode-qt/pluginaction.h> | ||
- | class ShowDialogAction : public PluginAction | + | class ShowDialogAction : public QObject, public PluginAction |
{ | { | ||
Q_OBJECT | Q_OBJECT | ||
public: | public: | ||
ShowDialogAction(const PluginInterface *interface); | ShowDialogAction(const PluginInterface *interface); | ||
- | QString getName() { return " | + | |
+ | QString getName() { return "My Plugin Action"; } // This name is just for convenience | ||
QString getText(); // This is the text that will show in the list | QString getText(); // This is the text that will show in the list | ||
+ | bool isReady() { return ready; } // Tells the list wether this plugin is ready to be shown or not | ||
void clickAction(QWidget *parentWindow); // The action which is called whenever we are clicked | void clickAction(QWidget *parentWindow); // The action which is called whenever we are clicked | ||
- | + | ||
- | + | ||
private slots: | private slots: | ||
void barcodeAnalysed(QString barcodeType, QString barcodeData); // The slot where all the processing goes down | void barcodeAnalysed(QString barcodeType, QString barcodeData); // The slot where all the processing goes down | ||
+ | |||
private: | private: | ||
+ | bool ready; | ||
QString barcodeType; | QString barcodeType; | ||
QString barcodeData; | QString barcodeData; | ||
}; | }; | ||
- | |||
- | |||
#endif // SHOWDIALOGACTION_H | #endif // SHOWDIALOGACTION_H | ||
Line 112: | Line 112: | ||
{ | { | ||
// Do your initialization here. | // Do your initialization here. | ||
+ | // Remember to set ready to false. | ||
+ | // This keeps the plugin from appearing in the list before it is ready | ||
+ | |||
+ | ready = false; | ||
} | } | ||
+ | |||
QString ShowDialogAction::getText() { | QString ShowDialogAction::getText() { | ||
// This is the text which will show in the list of results. | // This is the text which will show in the list of results. | ||
+ | |||
return "Show Dialog"; | return "Show Dialog"; | ||
} | } | ||
+ | |||
void ShowDialogAction::clickAction(QWidget* parentWindow) | void ShowDialogAction::clickAction(QWidget* parentWindow) | ||
{ | { | ||
// This is what happens when the user clicks our button. | // This is what happens when the user clicks our button. | ||
- | QMessageBox | + | // In this example we only show a message box |
- | + | ||
- | + | QMessageBox *msgBox = new QMessageBox(parentWindow); | |
- | + | msgBox->setWindowTitle("My Plugin"); | |
+ | msgBox->setText("The barcode was of type " + barcodeType + " and contained the data " + barcodeData); | ||
+ | msgBox->exec(); | ||
} | } | ||
+ | |||
void ShowDialogAction::barcodeAnalysed(QString barcodeType, QString barcodeData) { | void ShowDialogAction::barcodeAnalysed(QString barcodeType, QString barcodeData) { | ||
+ | |||
// In this function you process the data. This could be used for early web lookups or whatever. | // In this function you process the data. This could be used for early web lookups or whatever. | ||
// We just store the data in memory for now. | // We just store the data in memory for now. | ||
+ | |||
this->barcodeType = barcodeType; | this->barcodeType = barcodeType; | ||
this->barcodeData = barcodeData; | this->barcodeData = barcodeData; | ||
+ | |||
// We've done what we need to and are ready to show ourselves | // We've done what we need to and are ready to show ourselves | ||
- | + | ||
+ | ready = true; | ||
} | } | ||
</source> | </source> |
Learn more about Contributing to the wiki.