修改插件模块逻辑,模块中自定义生成QAction
平台获取模块中定义的QAction显示在ToolBar, 点击QAction, 加载插件插入到tab中 getPrjAllSlf封装到Slfio中,可以在插件模块中使用。
This commit is contained in:
parent
2cc2765790
commit
5e750f0529
|
|
@ -79,5 +79,38 @@ void CallPlugin::setPluginParams(QString strPluginName, QString strParams)
|
|||
{
|
||||
return pluInter->setParams(strParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction *> CallPlugin::getPluginActionList(QWidget *parent)
|
||||
{
|
||||
QList<QAction *> ret;
|
||||
foreach (HPLUGIN_INFO *pluItem, HPluginManage::getInstance()->getPluginList())
|
||||
{
|
||||
HPluginInterface *pluInter = reinterpret_cast<HPluginInterface *>(pluItem->pluClass);
|
||||
QWidget *pWidget = pluInter->createWindow(parent);
|
||||
if(pWidget)
|
||||
pWidget->hide();
|
||||
QAction *p = pluInter->createAction(parent);
|
||||
if(p)
|
||||
ret << p;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QAction *CallPlugin::getPluginAction(QString strPluginName, QWidget *parent)
|
||||
{
|
||||
if (strPluginName == "")
|
||||
return nullptr;
|
||||
|
||||
foreach (HPLUGIN_INFO *pluItem, HPluginManage::getInstance()->getPluginList())
|
||||
{
|
||||
HPluginInterface *pluInter = reinterpret_cast<HPluginInterface *>(pluItem->pluClass);
|
||||
if (pluItem->pluName == strPluginName)
|
||||
{
|
||||
QAction *pAct = pluInter->createAction(parent);
|
||||
return pAct;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -25,6 +25,13 @@ public:
|
|||
QString getPluginParams(QString strPluginName);
|
||||
void setPluginParams(QString strPluginName, QString strParams);
|
||||
|
||||
// 从插件模块中获取所有需要显示在平台的按钮
|
||||
QList<QAction*> getPluginActionList(QWidget *parent = Q_NULLPTR);
|
||||
|
||||
//根据插件名称获取平台显示按钮
|
||||
QAction *getPluginAction(QString strPluginName, QWidget *parent = Q_NULLPTR);
|
||||
|
||||
|
||||
public:
|
||||
Q_DISABLE_COPY(CallPlugin)
|
||||
};
|
||||
|
|
|
|||
59
Plugin/PluginUnit/PluginUnit.cpp
Normal file
59
Plugin/PluginUnit/PluginUnit.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include "PluginUnit.h"
|
||||
#include "PluginName.h"
|
||||
|
||||
#include "myunitui.h"
|
||||
MyUnitUI *_window = nullptr;
|
||||
|
||||
PluginUnit::PluginUnit(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString PluginUnit::getPluName() const
|
||||
{
|
||||
QString pluName = tr(PLUGINUNIT);
|
||||
return pluName;
|
||||
}
|
||||
|
||||
QIcon PluginUnit::icon() const
|
||||
{
|
||||
return QIcon(":/logo.png");
|
||||
}
|
||||
|
||||
int PluginUnit::windowType() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QWidget *PluginUnit::createWindow(QWidget *parent) const
|
||||
{
|
||||
if (_window == nullptr)
|
||||
{
|
||||
_window = new MyUnitUI(parent);
|
||||
}
|
||||
return _window;
|
||||
}
|
||||
|
||||
QString PluginUnit::getParams() const
|
||||
{
|
||||
if (_window != nullptr)
|
||||
return _window->getParams();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void PluginUnit::setParams(QString &strParams)
|
||||
{
|
||||
if (_window != nullptr)
|
||||
return _window->setParams(strParams);
|
||||
}
|
||||
|
||||
QAction *PluginUnit::createAction(QWidget *parent) const
|
||||
{
|
||||
if (_window == nullptr)
|
||||
createWindow(parent);
|
||||
|
||||
return _window->createAction();
|
||||
}
|
||||
|
||||
31
Plugin/PluginUnit/PluginUnit.h
Normal file
31
Plugin/PluginUnit/PluginUnit.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef PLUGINUNIT_H
|
||||
#define PLUGINUNIT_H
|
||||
|
||||
#include "HPluginInterface.h"
|
||||
|
||||
class PluginUnit : public QObject, public HPluginInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_INTERFACES(HPluginInterface)
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.HPluginInterface")
|
||||
#endif // QT_VERSION >= 0x050000
|
||||
|
||||
public:
|
||||
explicit PluginUnit(QObject *parent = 0);
|
||||
|
||||
virtual QString getPluName() const;
|
||||
virtual QIcon icon() const;
|
||||
virtual int windowType() const;
|
||||
virtual QWidget *createWindow(QWidget *parent) const;
|
||||
virtual QString getParams() const;
|
||||
virtual void setParams(QString &strParams);
|
||||
|
||||
virtual QAction *createAction(QWidget *parent) const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
#endif // PLUGINUNIT_H
|
||||
50
Plugin/PluginUnit/PluginUnit.pro
Normal file
50
Plugin/PluginUnit/PluginUnit.pro
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += c++17
|
||||
|
||||
HEADERS = \
|
||||
PluginUnit.h \
|
||||
myunitui.h
|
||||
|
||||
SOURCES = \
|
||||
PluginUnit.cpp \
|
||||
myunitui.cpp
|
||||
|
||||
|
||||
FORMS += \
|
||||
myunitui.ui
|
||||
|
||||
|
||||
INCLUDEPATH += $$PWD/../../include \
|
||||
$$PWD/../../HPluginManage \
|
||||
$$PWD/../../CallPlugin
|
||||
INCLUDEPATH += $$PWD/../../Slfio/include
|
||||
|
||||
# Default rules for deployment.
|
||||
CONFIG(debug, debug|release){
|
||||
TARGET = PluginUnitd
|
||||
DESTDIR = $$PWD/../../Bin/customPlugind
|
||||
MOC_DIR = ../tmp/PluginUnitd
|
||||
UI_DIR = ../tmp/PluginUnitd
|
||||
OBJECTS_DIR = ../tmp/PluginUnitd
|
||||
LIBS += -L$$PWD/../../Bin/ -lCallPlugind -lHPluginManaged -lslfiod
|
||||
} else {
|
||||
TARGET = PluginUnit
|
||||
DESTDIR = $$PWD/../../Bin/customPlugin
|
||||
MOC_DIR = ../tmp/PluginUnit
|
||||
UI_DIR = ../tmp/PluginUnit
|
||||
OBJECTS_DIR = ../tmp/PluginUnit
|
||||
LIBS += -L$$PWD/../../Bin/ -lCallPlugin -lHPluginManage -lslfio
|
||||
}
|
||||
|
||||
RESOURCES += \
|
||||
res.qrc
|
||||
BIN
Plugin/PluginUnit/image/zfu.png
Normal file
BIN
Plugin/PluginUnit/image/zfu.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 479 B |
221
Plugin/PluginUnit/myunitui.cpp
Normal file
221
Plugin/PluginUnit/myunitui.cpp
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
#include "myunitui.h"
|
||||
#include "ui_myunitui.h"
|
||||
#include "PluginName.h"
|
||||
#include "MemRdWt.h"
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
//固井结构体(注:此处为表格输出示例)
|
||||
typedef struct ss_struct
|
||||
{
|
||||
int GNO;
|
||||
float GSDEP,GEDEP;
|
||||
int GRESULT;
|
||||
} GUJING;
|
||||
|
||||
MyUnitUI::MyUnitUI(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::MyUnitUI)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
//保存logplus窗口句柄
|
||||
m_mainParentWindow = (QMainWindow *)parent;
|
||||
|
||||
//绑定logplus信号槽
|
||||
connect(this, SIGNAL(sig_PluginMsg(QString)), m_mainParentWindow, SLOT(s_PluginMsg(QString)));
|
||||
|
||||
//测试用
|
||||
//点击按钮
|
||||
connect(ui->pushButton, &QPushButton::clicked, this, [ = ]()
|
||||
{
|
||||
s_ButtonClick();
|
||||
});
|
||||
}
|
||||
|
||||
MyUnitUI::~MyUnitUI()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString MyUnitUI::getParams()
|
||||
{
|
||||
return ui->lineEdit->text();
|
||||
}
|
||||
|
||||
void MyUnitUI::setParams(QString &strParams)
|
||||
{
|
||||
if (strParams.length() <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QJsonParseError err_rpt;
|
||||
QJsonDocument root_Doc = QJsonDocument::fromJson(strParams.toStdString().c_str(), &err_rpt);//字符串格式化为JSON
|
||||
if (err_rpt.error != QJsonParseError::NoError)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QJsonObject root_Obj = root_Doc.object();
|
||||
if (root_Obj.contains("prjname"))
|
||||
{
|
||||
// 获取当前项目名称
|
||||
m_strPrjName = root_Obj.value("prjname").toString();
|
||||
ui->lineEdit->setText(m_strPrjName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QAction *MyUnitUI::createAction()
|
||||
{
|
||||
//下面, 平台显示按钮, 如需要平台显示解开注释
|
||||
m_pAction = new QAction();
|
||||
m_pAction->setText("直方图");
|
||||
m_pAction->setToolTip("直方图");
|
||||
m_pAction->setIcon( QIcon(":/image/zfu.png"));
|
||||
m_pAction->setProperty("PluginName", PLUGINUNIT);
|
||||
|
||||
return m_pAction;
|
||||
}
|
||||
|
||||
//测试按钮
|
||||
void MyUnitUI::s_ButtonClick()
|
||||
{
|
||||
QVector<QString> vecSlfList;
|
||||
QVector<QString> vecWellList;
|
||||
// 根据当前项目名称获取当前项目的slf文件,获取当前项目井文件
|
||||
bool bret = CMemRdWt::getPrjAllSlf(m_strPrjName, vecSlfList, vecWellList);
|
||||
|
||||
if(vecSlfList.size() > 0)
|
||||
{
|
||||
CMemRdWt *pMemRdWt=new CMemRdWt();
|
||||
//(1)初始化参数、输入
|
||||
pMemRdWt->Const();
|
||||
pMemRdWt->In();
|
||||
|
||||
if(!pMemRdWt->Open(vecSlfList.at(6).toStdString().c_str(),CMemRdWt::modeReadWrite)) {
|
||||
delete pMemRdWt;
|
||||
return;
|
||||
}
|
||||
|
||||
//(2)波形类型的输出数据初始化检查
|
||||
char outname[2][16];
|
||||
int OUTindex = 0, WaveIndex = 0;
|
||||
pMemRdWt->GetOutCurveName(OUTindex, outname[OUTindex]);//获取输出数据名称,参数1是序列值(从0开始)(注:波形/曲线均使用GetOutCurveName函数)
|
||||
|
||||
float fSdep = 2900; //设置起始深度
|
||||
float fEdep = 3000; //设置结束深度
|
||||
float fRlev = 0.0; //设置采样间隔
|
||||
|
||||
int index1 = pMemRdWt->OpenWave(outname[OUTindex]);//检查是否存在outname[OUTindex]波形
|
||||
if(index1 < 0) //返回索引小于0说明没有该波形,需要创建
|
||||
{
|
||||
//创建方式:
|
||||
Slf_WAVE myWave;
|
||||
strcpy(myWave.Name, outname[OUTindex]);
|
||||
strcpy(myWave.AliasName, outname[OUTindex]);
|
||||
strcpy(myWave.DepthUnit, "m");
|
||||
myWave.CodeLen = 4;
|
||||
myWave.RepCode = 4;
|
||||
myWave.DefVal = 0;
|
||||
myWave.StartDepth = fSdep;
|
||||
myWave.EndDepth = fEdep;
|
||||
myWave.DepLevel = fRlev;
|
||||
strcpy(myWave.DepthUnit, "m");
|
||||
myWave.StartTime = 0; //起始记录时间
|
||||
myWave.TimeLevel = 5; //时间采样间隔
|
||||
myWave.ArrayNum = 1; //阵列数
|
||||
myWave.TimeSamples = 36; //时间采样总数
|
||||
strcpy(myWave.TimeUnit, "ns"); //时间单位
|
||||
|
||||
index1 = pMemRdWt->OpenWave((Slf_WAVE *)&myWave); //创建波形(注:此时返回索引应>1,代表创建成功)
|
||||
}
|
||||
if(index1 < 0)
|
||||
{
|
||||
return;
|
||||
}else
|
||||
{
|
||||
WaveIndex = index1;
|
||||
}
|
||||
|
||||
//(3)曲线类型的输出数据初始化检查
|
||||
OUTindex = 1;//按extern "C"中定义的输出数据顺序设置
|
||||
pMemRdWt->GetOutCurveName(OUTindex, outname[OUTindex]);//获取输出数据名称,参数1是序列值(从0开始)
|
||||
index1 = pMemRdWt->OpenCurve(outname[1]);//index1 = MemRdWt.OpenCurve("EEE");//检查数据是否存在//outname[OUTindex]
|
||||
if(index1 < 0) //返回索引小于0说明没有这条曲线,需要创建
|
||||
{
|
||||
//创建方式:
|
||||
Slf_CURVE myCurve; //定义曲线对象
|
||||
strcpy(myCurve.Name, outname[1]); //设置名称
|
||||
strcpy(myCurve.AliasName, outname[1]); //设置别名
|
||||
strcpy(myCurve.Unit, "m"); //设置数据单位
|
||||
myCurve.CodeLen = 4; //设置字节长度(注:4float)
|
||||
myCurve.RepCode = 4; //设置数据类型(注:4float)
|
||||
myCurve.DefVal = 0; //设置默认值
|
||||
myCurve.StartDepth = fSdep; //设置起始深度
|
||||
myCurve.EndDepth = fEdep; //设置结束深度
|
||||
myCurve.DepLevel = fRlev; //设置采样间隔
|
||||
strcpy(myCurve.DepthUnit, "m"); //设置深度单位
|
||||
|
||||
index1 = pMemRdWt->OpenCurve((Slf_CURVE *)&myCurve); //创建曲线(注:此时返回索引应>1,代表创建成功)
|
||||
|
||||
}
|
||||
if(index1 < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*************************************************向平台写表格示例*************************************************************
|
||||
*****************************begin****************************/
|
||||
|
||||
//(1)固井结论表格
|
||||
int itable1 = pMemRdWt->OpenOG_RESULT("固井质量");//例如表格取名为“固井质量”
|
||||
pMemRdWt->SetTableRecordCount(itable1, 0); //清空原有表格数据
|
||||
|
||||
GUJING *CCNN2 = new GUJING[5];
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
CCNN2[i].GNO = i + 1;
|
||||
CCNN2[i].GSDEP = 2000 + i * 10;
|
||||
CCNN2[i].GEDEP = 2000 + (i + 1) * 10;
|
||||
CCNN2[i].GRESULT = 1;
|
||||
|
||||
int temp = pMemRdWt->WriteTable(itable1, i + 1, &CCNN2[i]);
|
||||
}
|
||||
|
||||
//(2)其他表格
|
||||
struct Slf_RST{
|
||||
int Order;
|
||||
float Depth;
|
||||
float CorrDepth;
|
||||
};
|
||||
struct Slf_RST m_Result;
|
||||
itable1 = pMemRdWt->OpenTable("ABCD");
|
||||
if (itable1 < 0)
|
||||
{
|
||||
itable1 = pMemRdWt->Open_Set_Table("ABCD",0,3,
|
||||
"NO,DEPTH,DDEP",
|
||||
"4,4,4",//字段长度
|
||||
"1,4,4",//字段类型
|
||||
"0,0,0");//字段备注,1-枚举
|
||||
}
|
||||
pMemRdWt->SetTableRecordCount(itable1,3); //设置表格有3行数据
|
||||
for(int j = 0; j < 3; j++)
|
||||
{
|
||||
memset(&m_Result, 0, sizeof(Slf_RST));
|
||||
m_Result.Order = j + 1;
|
||||
m_Result.Depth = 10;
|
||||
m_Result.CorrDepth = 20 + j;
|
||||
pMemRdWt->WriteTable(itable1, j + 1, &m_Result);
|
||||
|
||||
}
|
||||
pMemRdWt->CloseTable(itable1);
|
||||
|
||||
delete pMemRdWt;
|
||||
}
|
||||
|
||||
//
|
||||
QString strMsg = ui->lineEdit->text();
|
||||
|
||||
//插件给平台发消息
|
||||
emit sig_PluginMsg("插件给平台发了消息:" + strMsg);
|
||||
}
|
||||
44
Plugin/PluginUnit/myunitui.h
Normal file
44
Plugin/PluginUnit/myunitui.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef MYUNITUI_H
|
||||
#define MYUNITUI_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMainWindow>
|
||||
#include <QAction>
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
namespace Ui {
|
||||
class MyUnitUI;
|
||||
}
|
||||
|
||||
class MyUnitUI : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MyUnitUI(QWidget *parent = nullptr);
|
||||
~MyUnitUI();
|
||||
|
||||
private:
|
||||
Ui::MyUnitUI *ui;
|
||||
QAction* m_pAction = nullptr;
|
||||
QString m_strPrjName = "";
|
||||
|
||||
public:
|
||||
QString getParams();
|
||||
void setParams(QString &strParams);
|
||||
|
||||
// 创建在平台显示的QAction按钮
|
||||
QAction *createAction();
|
||||
|
||||
public:
|
||||
QMainWindow *m_mainParentWindow;
|
||||
|
||||
signals:
|
||||
void sig_PluginMsg(QString msg);
|
||||
|
||||
public slots:
|
||||
void s_ButtonClick();
|
||||
};
|
||||
|
||||
#endif // MYUNITUI_H
|
||||
65
Plugin/PluginUnit/myunitui.ui
Normal file
65
Plugin/PluginUnit/myunitui.ui
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MyUnitUI</class>
|
||||
<widget class="QWidget" name="MyUnitUI">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>367</width>
|
||||
<height>331</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QWidget#widget{
|
||||
background-color: rgb(225, 170, 255);
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>80</y>
|
||||
<width>211</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>我是插件-直方图</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>发送消息</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
5
Plugin/PluginUnit/res.qrc
Normal file
5
Plugin/PluginUnit/res.qrc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>image/zfu.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -124,6 +124,9 @@ public:
|
|||
CMemRdWt();
|
||||
CMemRdWt(const char *wellname,bool mconst=FALSE,int FileType=0);
|
||||
~CMemRdWt();
|
||||
|
||||
static bool getPrjAllSlf(QString prjname, QVector<QString> &vecSlfList, QVector<QString> &vecWellList);//直方图,获取当前工程下的slf
|
||||
|
||||
void Initialize(bool mconst=FALSE);
|
||||
void BackData();
|
||||
void RestoreData();
|
||||
|
|
|
|||
30
Slfio/include/commonutils.h
Normal file
30
Slfio/include/commonutils.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef COMMONUTILS_H
|
||||
#define COMMONUTILS_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStatusBar>
|
||||
#include <QComboBox>
|
||||
#include <QUuid>
|
||||
#include <QDir>
|
||||
#include<cmath>
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
class CCommonUtils
|
||||
{
|
||||
//函数定义
|
||||
public:
|
||||
//构造函数
|
||||
CCommonUtils();
|
||||
//析构函数
|
||||
virtual ~CCommonUtils();
|
||||
|
||||
static bool getAllSlf(QString prjname, QVector<QString> &vecSlfList, QVector<QString> &vecWellList);//直方图,获取当前工程下的slf
|
||||
static QString GetLogdataPath();
|
||||
static int chakan(QString path, QStringList &wellfs, QString strSuffix);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // COMMONUTILS_H
|
||||
|
|
@ -52,11 +52,13 @@ HEADERS += \
|
|||
../include/LogIO.h \
|
||||
../include/MemRdWt.h \
|
||||
../include/SlfioExport.h \
|
||||
../include/commonutils.h \
|
||||
../include/slf.h
|
||||
|
||||
SOURCES += \
|
||||
CStringType.cpp \
|
||||
LogIO.cpp \
|
||||
commonutils.cpp \
|
||||
memrdwt.cpp \
|
||||
slf.cpp
|
||||
|
||||
|
|
|
|||
203
Slfio/src/commonutils.cpp
Normal file
203
Slfio/src/commonutils.cpp
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
#include "commonutils.h"
|
||||
#include "LogIO.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
CCommonUtils::CCommonUtils()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCommonUtils::~CCommonUtils()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CCommonUtils::getAllSlf(QString prjname, QVector<QString> &vecSlfList, QVector<QString> &vecWellList)
|
||||
{
|
||||
//Logdata
|
||||
QString folderPath;
|
||||
folderPath = GetLogdataPath();
|
||||
folderPath = folderPath + prjname;
|
||||
folderPath = folderPath + "/";
|
||||
|
||||
//-------------------
|
||||
QStringList listFolders;
|
||||
QFileInfo mfi(folderPath);
|
||||
if(!mfi.isDir())
|
||||
{
|
||||
//井文件 *.wwl
|
||||
if(!mfi.isFile())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//listFiles.append(folderPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
//井目录
|
||||
//取当前当前目录内容
|
||||
QDir dir(folderPath);
|
||||
dir.setFilter(QDir::Dirs |QDir::NoDotAndDotDot |QDir::Files | QDir::NoSymLinks);
|
||||
QFileInfoList list = dir.entryInfoList();
|
||||
int file_count = list.count();
|
||||
if(file_count <= 0)//判断目录是否为空,空目录返回
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//取当前目录内容,符合后缀文件
|
||||
QStringList string_list;
|
||||
for(int i=0; i<list.size();i++)
|
||||
{
|
||||
QFileInfo file_info = list.at(i);
|
||||
if(file_info.isDir())
|
||||
{
|
||||
//#JPH-307
|
||||
QString absolute_file_path = file_info.absoluteFilePath();
|
||||
if(absolute_file_path.at(absolute_file_path.length()-1)==' ') {
|
||||
dir.rmdir(absolute_file_path);
|
||||
continue;
|
||||
}
|
||||
listFolders.append(absolute_file_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
QStringList wellfiles;
|
||||
foreach(QString wellFolder, listFolders )
|
||||
{
|
||||
QFileInfo w(wellFolder);//#JPH-307
|
||||
if(w.isDir())
|
||||
{
|
||||
chakan(wellFolder, wellfiles, "*.well");
|
||||
}
|
||||
}
|
||||
|
||||
QStringList wellNames;
|
||||
foreach(QString wellFile1, wellfiles )
|
||||
{
|
||||
QString filename=wellFile1;
|
||||
//----------------
|
||||
CLogIO * logio=new CLogIO();
|
||||
if(!logio->Open(filename.toStdString().c_str(),CSlfIO::modeRead))
|
||||
{
|
||||
delete logio;
|
||||
QString aa=filename+"文件打开失败,请检查!";
|
||||
//qDebug() << aa;
|
||||
//AppendConsole(pai::log::PAI_ERROR,aa);
|
||||
continue;
|
||||
}
|
||||
//
|
||||
QString wellname="";
|
||||
Slf_FILE_MESSAGE mssage;
|
||||
logio->GetFileMessage(mssage);
|
||||
wellname=mssage.WellName;
|
||||
wellname=wellname.toUpper();
|
||||
if (wellname.isEmpty()||wellname.length()>64||wellname.indexOf('&')>-1)
|
||||
{
|
||||
//辨别井名是否有效,无效则采用文件名
|
||||
QFileInfo fileInfo(filename);
|
||||
QString strWellName = fileInfo.completeBaseName();
|
||||
strWellName=strWellName.toUpper();
|
||||
//
|
||||
wellname=strWellName.toStdString().c_str();
|
||||
int len=strlen(strWellName.toStdString().c_str());
|
||||
if(len>sizeof(mssage.WellName)) len=sizeof(mssage.WellName);
|
||||
strncpy(mssage.WellName,strWellName.toStdString().c_str(),len);
|
||||
mssage.WellName[len]=0;
|
||||
logio->SetFileMessage(mssage);
|
||||
}
|
||||
wellname=wellname.toUpper();
|
||||
|
||||
//查找是否已经存在该井和井次
|
||||
if(wellNames.contains(wellname))
|
||||
{
|
||||
delete logio;
|
||||
continue;
|
||||
}
|
||||
wellNames.append(wellname);
|
||||
//
|
||||
vecWellList.append(wellname);
|
||||
|
||||
//加载*.slf
|
||||
QStringList slffiles;
|
||||
QString pathTmp=GetLogdataPath();
|
||||
pathTmp+=prjname+"/#"+wellname;
|
||||
chakan(pathTmp, slffiles, "*.slf");
|
||||
foreach(QString slfFile1, slffiles )
|
||||
{
|
||||
CLogIO * logioSLf=new CLogIO();
|
||||
if(!logioSLf->Open(slfFile1.toStdString().c_str(),CSlfIO::modeRead))
|
||||
{
|
||||
delete logioSLf;
|
||||
//QString aa=fileFull+"文件打开失败,请检查!";
|
||||
//qDebug() << aa;
|
||||
//AppendConsole(pai::log::PAI_ERROR,aa);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Slf_FILE_MESSAGE mssageSlf;
|
||||
logioSLf->GetFileMessage(mssageSlf);
|
||||
|
||||
if(wellname != QString(mssageSlf.WellName))
|
||||
{
|
||||
delete logioSLf;
|
||||
continue;
|
||||
}
|
||||
QString wellnameSLf=mssageSlf.Item;
|
||||
if (wellnameSLf.isEmpty()||wellnameSLf.length()>64||wellnameSLf.indexOf('&')>-1)
|
||||
{
|
||||
QFileInfo fileinfo;
|
||||
fileinfo = QFileInfo(slfFile1);
|
||||
wellnameSLf = fileinfo.completeBaseName();
|
||||
}
|
||||
if(wellnameSLf != wellname)
|
||||
{
|
||||
//井次名称不一致
|
||||
//qDebug() << "井次名称不一致";
|
||||
delete logioSLf;
|
||||
continue;
|
||||
}
|
||||
|
||||
vecSlfList.append(slfFile1);
|
||||
delete logioSLf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString CCommonUtils::GetLogdataPath()
|
||||
{
|
||||
// 1.获取当前运行程序的目录路径
|
||||
QString applicationDirPath = QCoreApplication::applicationDirPath();
|
||||
//获取上级目录
|
||||
int index = applicationDirPath.lastIndexOf("/");
|
||||
int index1 = applicationDirPath.lastIndexOf("\\");
|
||||
if(index1 > index)
|
||||
{
|
||||
index = index1;
|
||||
}
|
||||
//
|
||||
QString strImagePath;
|
||||
strImagePath = applicationDirPath.mid(0,index+1) + "Logdata/";
|
||||
//
|
||||
QDir dir(strImagePath);
|
||||
if( !dir.exists( strImagePath ) )
|
||||
{
|
||||
dir.mkdir(strImagePath);
|
||||
}
|
||||
|
||||
return strImagePath;
|
||||
}
|
||||
|
||||
int CCommonUtils::chakan(QString path, QStringList &wellfs, QString strSuffix)
|
||||
{
|
||||
QDir dir(path);
|
||||
QFileInfoList fileInfos = dir.entryInfoList(QStringList() << strSuffix, QDir::Files);
|
||||
foreach(QFileInfo fileInfo, fileInfos)
|
||||
{
|
||||
wellfs.append(fileInfo.absoluteFilePath());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#include "MemRdWt.h"
|
||||
#include "math.h"
|
||||
#include <QString>
|
||||
#include "commonutils.h"
|
||||
|
||||
CMemRdWt ::CMemRdWt(const char *wellname,bool bconst,int FileType):CLogIO(wellname,FileType)
|
||||
{
|
||||
Initialize(bconst);
|
||||
|
|
@ -409,8 +411,14 @@ QString getStrValue(char *stryy,int pos)//stryy 输入字符串缓冲器,pos
|
|||
|
||||
CMemRdWt ::~CMemRdWt()
|
||||
{
|
||||
Close();
|
||||
Close();
|
||||
}
|
||||
|
||||
bool CMemRdWt::getPrjAllSlf(QString prjname, QVector<QString> &vecSlfList, QVector<QString> &vecWellList)
|
||||
{
|
||||
return CCommonUtils::getAllSlf(prjname, vecSlfList, vecWellList);
|
||||
}
|
||||
|
||||
int CMemRdWt::GetInCurveName(int CurveNo,char *InName)
|
||||
{
|
||||
if(!INC) return 0;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
#include "LogIO.h"
|
||||
#include "MemRdWt.h"
|
||||
|
||||
float mLineWidth=0.75;
|
||||
QString OilField;
|
||||
|
|
@ -700,157 +701,7 @@ bool SystemExiting(){return SystemIsExiting;}
|
|||
//直方图,获取当前工程下的slf
|
||||
bool getAllSlf(QString prjname, QVector<QString> &vecSlfList, QVector<QString> &vecWellList)
|
||||
{
|
||||
//Logdata
|
||||
QString folderPath;
|
||||
folderPath = GetLogdataPath();
|
||||
folderPath = folderPath + prjname;
|
||||
folderPath = folderPath + "/";
|
||||
|
||||
//-------------------
|
||||
QStringList listFolders;
|
||||
QFileInfo mfi(folderPath);
|
||||
if(!mfi.isDir())
|
||||
{
|
||||
//井文件 *.wwl
|
||||
if(!mfi.isFile())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//listFiles.append(folderPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
//井目录
|
||||
//取当前当前目录内容
|
||||
QDir dir(folderPath);
|
||||
dir.setFilter(QDir::Dirs |QDir::NoDotAndDotDot |QDir::Files | QDir::NoSymLinks);
|
||||
QFileInfoList list = dir.entryInfoList();
|
||||
int file_count = list.count();
|
||||
if(file_count <= 0)//判断目录是否为空,空目录返回
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//取当前目录内容,符合后缀文件
|
||||
QStringList string_list;
|
||||
for(int i=0; i<list.size();i++)
|
||||
{
|
||||
QFileInfo file_info = list.at(i);
|
||||
if(file_info.isDir())
|
||||
{
|
||||
//#JPH-307
|
||||
QString absolute_file_path = file_info.absoluteFilePath();
|
||||
if(absolute_file_path.at(absolute_file_path.length()-1)==' ') {
|
||||
dir.rmdir(absolute_file_path);
|
||||
continue;
|
||||
}
|
||||
listFolders.append(absolute_file_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
QStringList wellfiles;
|
||||
foreach(QString wellFolder, listFolders )
|
||||
{
|
||||
QFileInfo w(wellFolder);//#JPH-307
|
||||
if(w.isDir())
|
||||
{
|
||||
chakan(wellFolder, wellfiles, "*.well");
|
||||
}
|
||||
}
|
||||
|
||||
QStringList wellNames;
|
||||
foreach(QString wellFile1, wellfiles )
|
||||
{
|
||||
QString filename=wellFile1;
|
||||
//----------------
|
||||
CLogIO * logio=new CLogIO();
|
||||
if(!logio->Open(filename.toStdString().c_str(),CSlfIO::modeRead))
|
||||
{
|
||||
delete logio;
|
||||
QString aa=filename+"文件打开失败,请检查!";
|
||||
//qDebug() << aa;
|
||||
//AppendConsole(pai::log::PAI_ERROR,aa);
|
||||
continue;
|
||||
}
|
||||
//
|
||||
QString wellname="";
|
||||
Slf_FILE_MESSAGE mssage;
|
||||
logio->GetFileMessage(mssage);
|
||||
wellname=mssage.WellName;
|
||||
wellname=wellname.toUpper();
|
||||
if (wellname.isEmpty()||wellname.length()>64||wellname.indexOf('&')>-1)
|
||||
{
|
||||
//辨别井名是否有效,无效则采用文件名
|
||||
QFileInfo fileInfo(filename);
|
||||
QString strWellName = fileInfo.completeBaseName();
|
||||
strWellName=strWellName.toUpper();
|
||||
//
|
||||
wellname=strWellName.toStdString().c_str();
|
||||
int len=strlen(strWellName.toStdString().c_str());
|
||||
if(len>sizeof(mssage.WellName)) len=sizeof(mssage.WellName);
|
||||
strncpy(mssage.WellName,strWellName.toStdString().c_str(),len);
|
||||
mssage.WellName[len]=0;
|
||||
logio->SetFileMessage(mssage);
|
||||
}
|
||||
wellname=wellname.toUpper();
|
||||
|
||||
//查找是否已经存在该井和井次
|
||||
if(wellNames.contains(wellname))
|
||||
{
|
||||
delete logio;
|
||||
continue;
|
||||
}
|
||||
wellNames.append(wellname);
|
||||
//
|
||||
vecWellList.append(wellname);
|
||||
|
||||
//加载*.slf
|
||||
QStringList slffiles;
|
||||
QString pathTmp=GetLogdataPath();
|
||||
pathTmp+=prjname+"/#"+wellname;
|
||||
chakan(pathTmp, slffiles, "*.slf");
|
||||
foreach(QString slfFile1, slffiles )
|
||||
{
|
||||
CLogIO * logioSLf=new CLogIO();
|
||||
if(!logioSLf->Open(slfFile1.toStdString().c_str(),CSlfIO::modeRead))
|
||||
{
|
||||
delete logioSLf;
|
||||
//QString aa=fileFull+"文件打开失败,请检查!";
|
||||
//qDebug() << aa;
|
||||
//AppendConsole(pai::log::PAI_ERROR,aa);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Slf_FILE_MESSAGE mssageSlf;
|
||||
logioSLf->GetFileMessage(mssageSlf);
|
||||
|
||||
if(wellname != QString(mssageSlf.WellName))
|
||||
{
|
||||
delete logioSLf;
|
||||
continue;
|
||||
}
|
||||
QString wellnameSLf=mssageSlf.Item;
|
||||
if (wellnameSLf.isEmpty()||wellnameSLf.length()>64||wellnameSLf.indexOf('&')>-1)
|
||||
{
|
||||
QFileInfo fileinfo;
|
||||
fileinfo = QFileInfo(slfFile1);
|
||||
wellnameSLf = fileinfo.completeBaseName();
|
||||
}
|
||||
if(wellnameSLf != wellname)
|
||||
{
|
||||
//井次名称不一致
|
||||
//qDebug() << "井次名称不一致";
|
||||
delete logioSLf;
|
||||
continue;
|
||||
}
|
||||
|
||||
vecSlfList.append(slfFile1);
|
||||
delete logioSLf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return CMemRdWt::getPrjAllSlf(prjname, vecSlfList, vecWellList);
|
||||
}
|
||||
|
||||
int GetCurvInfo(QString strSlfName, QString strLineName, double &sdep, double &edep, double &rlev)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QtCore/QString>
|
||||
#include <QtGui/QIcon>
|
||||
#include <QString>
|
||||
#include <QAction>
|
||||
|
||||
#include "HPluginDefine.h"
|
||||
|
||||
|
|
@ -20,6 +21,8 @@ public:
|
|||
virtual QWidget *createWindow(QWidget *parent) const = 0;
|
||||
virtual QString getParams() const = 0;
|
||||
virtual void setParams(QString &strParams) = 0;
|
||||
|
||||
virtual QAction *createAction(QWidget *parent) const = 0;
|
||||
};
|
||||
|
||||
#define HPluginInterface_iid "org.qt-project.HPluginInterface"
|
||||
|
|
|
|||
|
|
@ -71,9 +71,12 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
initTitleBar(); //菜单栏
|
||||
initToolBar(); //工具栏
|
||||
initPluginTool(); //插件QAction
|
||||
|
||||
initProjectView(); //左侧-项目区 初始化在前
|
||||
initWorkSpaceView(); //中间-工作区 初始化在后
|
||||
dockLayout();
|
||||
|
||||
//
|
||||
this->setStatusBar(::GetStatusBar());//状态栏
|
||||
|
||||
|
|
@ -243,6 +246,17 @@ void MainWindow::initToolBar()
|
|||
// connect(m_loadAc, &QAction::triggered, this, &MainWindow::s_DrawLine);
|
||||
}
|
||||
|
||||
//初始化插件QAction
|
||||
void MainWindow::initPluginTool()
|
||||
{
|
||||
QList<QAction *> listTool = CallPlugin::getInstance()->getPluginActionList(this);
|
||||
foreach (QAction *pAct, listTool)
|
||||
{
|
||||
ui->mainToolBar->addAction(pAct);
|
||||
connect(pAct, &QAction::triggered, this, &MainWindow::slot_PluginActionFunc);
|
||||
}
|
||||
}
|
||||
|
||||
//左侧
|
||||
void MainWindow::initProjectView()
|
||||
{
|
||||
|
|
@ -367,6 +381,34 @@ void MainWindow::s_SaveProject()
|
|||
// emit CallManage::getInstance()->sig_testPlugin("hello");
|
||||
}
|
||||
|
||||
void MainWindow::slot_PluginActionFunc()
|
||||
{
|
||||
QAction* pAction = qobject_cast<QAction*>(sender());
|
||||
if(pAction == nullptr)
|
||||
return;
|
||||
|
||||
if (g_prjname == "")
|
||||
{
|
||||
QMessageBox::information(nullptr, "提示", "请先打开项目!");
|
||||
return;
|
||||
}
|
||||
|
||||
QString strPluginName = pAction->property("PluginName").toString();
|
||||
QWidget * pMyWidget = CallPlugin::getInstance()->getPluginWidget(strPluginName, (QWidget *)this);
|
||||
if (pMyWidget != nullptr)
|
||||
{
|
||||
QJsonObject rootObject;
|
||||
rootObject.insert("prjname", g_prjname);
|
||||
//----------------------
|
||||
QJsonDocument doc;
|
||||
doc.setObject(rootObject);
|
||||
|
||||
CallPlugin::getInstance()->setPluginParams(strPluginName, doc.toJson(QJsonDocument::Compact));
|
||||
m_centerWidgets->addTab(pMyWidget, pAction->text());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//收到插件消息
|
||||
void MainWindow::s_PluginMsg(QString msg)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public:
|
|||
|
||||
void initTitleBar(); //初始化菜单
|
||||
void initToolBar(); //初始化工具栏
|
||||
void initPluginTool(); //初始化插件QAction
|
||||
void initProjectView(); //初始化左侧工程区
|
||||
void initWorkSpaceView(); //初始化工作区
|
||||
void dockLayout(); //停靠
|
||||
|
|
@ -95,6 +96,8 @@ public slots:
|
|||
void s_ShowWave(QString strSlfName, QString strName); //波列数据查看
|
||||
void s_WelllogInformation(QString strSlfName);//编辑测井信息
|
||||
|
||||
void slot_PluginActionFunc();
|
||||
|
||||
//插件消息
|
||||
void s_PluginMsg(QString msg);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user