initial commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#include "cimportdigikey.h"
|
||||
|
||||
|
||||
QString cImportDigikey::pluginName()
|
||||
{
|
||||
return(PLUGIN_NAME);
|
||||
}
|
||||
qint16 cImportDigikey::pluginVersion()
|
||||
{
|
||||
return(PLUGIN_VERSION);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef CIMPORTDIGIKEY_H
|
||||
#define CIMPORTDIGIKEY_H
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QtPlugin>
|
||||
#include "cimportinterface.h"
|
||||
|
||||
#define PLUGIN_NAME "Import DigiKey"
|
||||
#define PLUGIN_VERSION 1
|
||||
|
||||
|
||||
class cImportDigikey : public QObject, cImportInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "at.windesign.importInterface" FILE "importDigiKey.json")
|
||||
Q_INTERFACES(cImportInterface)
|
||||
|
||||
public:
|
||||
QString pluginName() override;
|
||||
qint16 pluginVersion() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "importDigiKey.h"
|
||||
|
||||
//! [0]
|
||||
QString cImportDigiKey::echo(const QString &message)
|
||||
{
|
||||
return message;
|
||||
}
|
||||
//! [0]
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef IMPORTDIGIKEY_H
|
||||
#define IMPORTDIGIKEY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtPlugin>
|
||||
#include "inventryPartsInterface.h"
|
||||
|
||||
//! [0]
|
||||
class importDigikey : public QObject, inventryPartsInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "at.windesign.inventryPartsInterface" FILE "importDigiKey.json")
|
||||
Q_INTERFACES(inventryPartsInterface)
|
||||
|
||||
public:
|
||||
QString echo(const QString &message) override;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif
|
||||
@@ -3,8 +3,10 @@ TEMPLATE = lib
|
||||
CONFIG += plugin
|
||||
QT += widgets
|
||||
INCLUDEPATH += ../inventryParts
|
||||
HEADERS = importDigiKey.h
|
||||
SOURCES = importDigiKey.cpp
|
||||
HEADERS = \
|
||||
cimportdigikey.h
|
||||
SOURCES = \
|
||||
cimportdigikey.cpp
|
||||
TARGET = $$qtLibraryTarget(importDigiKey)
|
||||
DESTDIR = ../plugins
|
||||
#! [0]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#! [0]
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS = inventryParts \
|
||||
importDigiKey
|
||||
#! [0]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef CIMPORTINTERFACE_H
|
||||
#define CIMPORTINTERFACE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class cImportInterface {
|
||||
public:
|
||||
virtual ~cImportInterface() = default;
|
||||
virtual QString pluginName() = 0;
|
||||
virtual qint16 pluginVersion() = 0;
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#define cImportInterface_iid "at.windesign.importInterface"
|
||||
|
||||
Q_DECLARE_INTERFACE(cImportInterface, cImportInterface_iid)
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // CIMPORTINTERFACE_H
|
||||
@@ -1,15 +1,77 @@
|
||||
#include "cmainwindow.h"
|
||||
#include "ui_cmainwindow.h"
|
||||
|
||||
cMainWindow::cMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::cMainWindow)
|
||||
#include <QDir>
|
||||
#include <QPluginLoader>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
cMainWindow::cMainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::cMainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
createGUI();
|
||||
|
||||
if(!loadPlugin())
|
||||
{
|
||||
QMessageBox::information(this, "Error", "Could not load the plugin");
|
||||
}
|
||||
}
|
||||
|
||||
cMainWindow::~cMainWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void cMainWindow::createGUI()
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
bool cMainWindow::loadPlugin()
|
||||
{
|
||||
QDir pluginsDir(QCoreApplication::applicationDirPath());
|
||||
|
||||
qDebug() << pluginsDir.absolutePath();
|
||||
#if defined(Q_OS_WIN)
|
||||
if(pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
|
||||
{
|
||||
pluginsDir.cdUp();
|
||||
pluginsDir.cdUp();
|
||||
}
|
||||
#elif defined(Q_OS_MAC)
|
||||
if (pluginsDir.dirName() == "MacOS")
|
||||
{
|
||||
pluginsDir.cdUp();
|
||||
pluginsDir.cdUp();
|
||||
pluginsDir.cdUp();
|
||||
}
|
||||
#endif
|
||||
pluginsDir.cd("plugins");
|
||||
|
||||
const QStringList entries = pluginsDir.entryList(QDir::Files);
|
||||
|
||||
for(const QString &fileName : entries)
|
||||
{
|
||||
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
||||
QObject* plugin = pluginLoader.instance();
|
||||
|
||||
if(plugin)
|
||||
{
|
||||
m_importInterface = qobject_cast<cImportInterface *>(plugin);
|
||||
|
||||
if(m_importInterface)
|
||||
{
|
||||
qDebug() << m_importInterface->pluginName();
|
||||
qDebug() << m_importInterface->pluginVersion();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
pluginLoader.unload();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
#ifndef CMAINWINDOW_H
|
||||
#define CMAINWINDOW_H
|
||||
|
||||
|
||||
#include "cimportinterface.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class cMainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class cMainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
cMainWindow(QWidget *parent = nullptr);
|
||||
~cMainWindow();
|
||||
cMainWindow(QWidget *parent = nullptr);
|
||||
~cMainWindow();
|
||||
|
||||
private:
|
||||
Ui::cMainWindow *ui;
|
||||
Ui::cMainWindow* ui;
|
||||
cImportInterface* m_importInterface;
|
||||
|
||||
void createGUI();
|
||||
bool loadPlugin();
|
||||
};
|
||||
#endif // CMAINWINDOW_H
|
||||
|
||||
@@ -13,6 +13,7 @@ SOURCES += \
|
||||
cmainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
cimportinterface.h \
|
||||
cmainwindow.h
|
||||
|
||||
FORMS += \
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "cmainwindow.h"
|
||||
#include "cimportinterface.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user