You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Src/nmNum/nmSubWnd/nmSubWndDemo.cpp

726 lines
17 KiB
C++


#include "zxLogInstance.h"
#include "ZxBaHelper.h"
#include "ZxResolutionHelper.h"
#include "zxSysUtils.h"
#include "ZxPtyDock.h"
#include "iDockBaseWx.h"
#include "ZxMainWindow.h"
#include "iWxRibbon.h"
#include "ZxSubAxisX.h"
#include "ZxSubAxisY.h"
#include "ZxPlot.h"
#include "ZxObjCurve.h"
#include "ZxSubTitle.h"
#include "nmPlotScene.h"
#include "nmPlotView.h"
#include "ZxTableView.h"
#include "ZxTableModel.h"
#include "mModuleDefines.h"
#include "ZxDataWell.h"
#include "ZxDataProject.h"
#include "ZxRstWnd.h"
#ifdef QT_DEBUG
#include "ZxDataGaugeP.h"
#endif
#ifdef QT_DEBUG
#include "nmXmlHelper.h"
#endif
#include "iWxBase.h"
#include "iAnalRun.h"
#include "nmGuiPlot.h"
#include "nmWxParaProperty.h"
#include "nmSubWndDemo.h"
nmSubWndDemo::nmSubWndDemo(QWidget *parent, QString sExt) :
iSubWndBaseFit(parent, sExt)
{
m_pWxPlot = nullptr;
m_pWxDockParas = nullptr;
m_pWxParas = nullptr;
m_pWxDockData1 = nullptr;
m_pTableView1 = nullptr;
m_pWxDockData2 = nullptr;
m_pTableView2 = nullptr;
#ifdef QT_DEBUG
m_pWxDockTemp = nullptr;
m_pListWxTemp = nullptr;
#endif
// 为了后续支持多井提供方便
if (m_pDataWell == nullptr)
{
m_pDataWell = zxCurWell;
}
// m_sMdiWndType = s_MdiType_DataNum;
m_sMdiWndType = s_MdiType_DataAnal;
setWindowTitle(tr("nmSubWndDemo"));
}
nmSubWndDemo::~nmSubWndDemo()
{
#ifdef QT_DEBUG
// 坚持谁创建谁析构原则,删除(首先需要去除绑定)
if (nullptr != m_pWxDockTemp)
{
//QObject* pParent = m_pWxDockTemp->parent();
//ZxMainWindow* p = dynamic_cast<ZxMainWindow*>(pParent);
ZxMainWindow* p = m_pMainWindow;
if (nullptr != p)
{
p->detachOuterDockWx(m_pWxDockTemp);
}
delete m_pWxDockTemp;
m_pWxDockTemp = nullptr;
}
#endif
}
void nmSubWndDemo::configWnd(QString sPrevInfo)
{
iSubWndBaseFit::configWnd(sPrevInfo);
if (nullptr != m_pMainWindow)
{
setAllAnalRuns(m_pMainWindow->getVecAnalRunPtrs());
createRunWizardWxs();
initRunWizardWxUIs();
iAnalRun* pCurAnalRun = zxCurAnalRun;
if (nullptr != pCurAnalRun && nullptr == getAnalRun())
{
setAnalRun(pCurAnalRun, true);
}
disconnect(this, SIGNAL(sigAppendDock2Main(iDockBaseWx*,Qt::DockWidgetArea)), \
m_pMainWindow, SLOT(slotAppendDock2Main(iDockBaseWx*,Qt::DockWidgetArea)));
connect(this, SIGNAL(sigAppendDock2Main(iDockBaseWx*,Qt::DockWidgetArea)), \
m_pMainWindow, SLOT(slotAppendDock2Main(iDockBaseWx*,Qt::DockWidgetArea)));
}
initUI();
}
void nmSubWndDemo::initUI()
{
// iSubWndBaseFit::initUI();
#ifdef QT_DEBUG
// 示例演示增加Dock并且追加至程序主窗口
initUiTop();
#endif
// 主布局:定义
initUiMain();
// 外围布局DockWx
{
initUiDockWxs();
initUiDockPtys();
}
#ifdef QT_DEBUG
// 示例如何加载xml文件
if (_nmXmlHelper->loadXmlDefines())
{
foreach (nmXmlData* pData, *(_nmXmlHelper->getVecNmXmlDataPtrs()))
{
Q_ASSERT (nullptr != pData);
zxLogRunD(QString("%1: %2").arg(pData->m_sName).arg(pData->m_sAlias));
}
}
// 演示如何显示背景图片
if (nullptr != m_pWxPlot)
{
QString sFile = "E:/Temp/LogSpider.png";
ZxPlot* pPlot = m_pWxPlot->m_pPlot;
pPlot->setBkImgFile(sFile);
QImage* pBkImg = pPlot->getBkImg();
Q_ASSERT (nullptr != pBkImg);
int w = pBkImg->width();
int h = pBkImg->height();
if (w > 0 && h > 0)
{
pPlot->getMainAxisX()->setRangeMinMax(0, w, true);
pPlot->getMainAxisY()->setRangeMinMax(0, h, true);
}
// pPlot->setMinimizeAxisX(true);
// pPlot->setMinimizeAxisY(true);
}
#endif
}
QWidget* nmSubWndDemo::initUiMainWx()
{
QSplitter* pSplitter = new QSplitter(Qt::Vertical);
Q_ASSERT (nullptr != pSplitter);
nmGuiPlot* pWxPlot = new nmGuiPlot();
m_pWxPlot = pWxPlot;
{
// 建立信号,以便在此处增加新的工具
connect(pWxPlot, SIGNAL(sigToolbarBuilt(QToolBar*)),
this, SLOT(slotToolbarBuilt(QToolBar*)));
QSize sz = QSize(265, 203);
pWxPlot->initUI("TestGui", sz);
bindChartSignals(pWxPlot);
pSplitter->addWidget(pWxPlot);
}
return pSplitter;
}
void nmSubWndDemo::initUiDockWxs()
{
// 基础参数Dock
{
m_pWxDockParas = new iDockBaseWx(tr("Parameters"));
Q_ASSERT (nullptr != m_pWxDockParas);
addDockWidget(Qt::LeftDockWidgetArea, m_pWxDockParas);
m_pWxParas = new nmWxParaProperty();
Q_ASSERT (nullptr != m_pWxParas);
m_pWxParas->initUI();
m_pWxDockParas->setWidget(m_pWxParas);
m_pWxDockParas->setMinimumWidth(_resoSizeW(200));
}
// 表格数据Dock
{
QStringList listTitles;
listTitles << tr("Name1");
iDockBaseWx* pDockWx1 = new iDockBaseWx(tr("Data1"));
Q_ASSERT (nullptr != pDockWx1);
{
addDockWidget(Qt::RightDockWidgetArea, pDockWx1);
m_pWxDockData1 = pDockWx1;
ZxTableView* pTableView = new ZxTableView();
Q_ASSERT (nullptr != pTableView);
{
ZxTableModel* pTableModel = new ZxTableModel(1, 1, listTitles);
Q_ASSERT (nullptr != pTableModel);
pTableView->setModel(pTableModel);
pTableView->setMenuMode(ZxTableView::MTM_Edit_Without_Col);
pTableView->setSelectionBehavior(ZxTableView::SelectRows);
pTableView->fuzzyUiOfQt5();
}
pDockWx1->setWidget(pTableView);
m_pTableView1 = pTableView;
}
iDockBaseWx* pDockWx2 = new iDockBaseWx(tr("Data2"));
Q_ASSERT (nullptr != pDockWx2);
{
addDockWidget(Qt::RightDockWidgetArea, pDockWx2);
tabifyDockWidget(pDockWx1, pDockWx2);
m_pWxDockData2 = pDockWx2;
ZxTableView* pTableView = new ZxTableView();
Q_ASSERT (nullptr != pTableView);
{
ZxTableModel* pTableModel = new ZxTableModel(1, 1, listTitles);
Q_ASSERT (nullptr != pTableModel);
pTableView->setModel(pTableModel);
pTableView->setMenuMode(ZxTableView::MTM_Readonly);
pTableView->fuzzyUiOfQt5();
}
pDockWx2->setWidget(pTableView);
m_pTableView2 = pTableView;
}
}
}
void nmSubWndDemo::initUiDockPtys()
{
iSubWndBaseFit::initUiDockPtys();
// 属性Dock
{
Q_ASSERT (nullptr != m_pDockPty);
m_pDockPty->setMinimumWidth(_resoSizeW(250));
}
}
#ifdef QT_DEBUG
// 示例演示增加Dock并且追加至程序主窗口
void nmSubWndDemo::initUiTop()
{
return;
// 基础参数Dock
{
iDockBaseWx* pDockWx = new iDockBaseWx(tr("TODO:Demo"));
Q_ASSERT (nullptr != pDockWx);
QListWidget* pListWx = new QListWidget();
Q_ASSERT (nullptr != pListWx);
pDockWx->setWidget(pListWx);
m_pListWxTemp = pListWx;
pDockWx->setMinimumWidth(_resoSizeW(200));
emit sigAppendDock2Main(pDockWx, Qt::LeftDockWidgetArea);
m_pWxDockTemp = pDockWx;
}
}
#endif
void nmSubWndDemo::bindChartSignals(iGuiPlot* pWxPlot)
{
nmGuiPlot* p = dynamic_cast<nmGuiPlot*>(pWxPlot);
if (nullptr != p)
{
connect(p, SIGNAL(sigObjSelChanged(ZxObjBase*, bool)), \
this, SLOT(slotObjSelChanged(ZxObjBase*, bool)));
connect(p, SIGNAL(sigObjPtsChanged(ZxObjBase*)),
this, SLOT(slotObjPtsChanged(ZxObjBase*)));
}
iSubWndBaseFit::bindChartSignals(pWxPlot);
}
void nmSubWndDemo::setAnalRun(iAnalRun* p, bool bFuzzyPit /*= false*/)
{
iSubWndBaseFit::setAnalRun(p, bFuzzyPit);
}
bool nmSubWndDemo::runActionOf(QString sAction)
{
if (iSubWndBaseFit::runActionOf(sAction))
{
return true;
}
// 数据加载
QString s = sAction;
if (_isSame(s, "LoadP"))
{
return true;
}
#ifdef QT_DEBUG
if (_isSame(s, "setLocked"))
{
// yours own dealing
// Fresh other binding butons
QStringList listIDs;
listIDs << "5125" << "5809";
// Method1:
emit sigFreshRnStates(listIDs);
// Method2:
Q_ASSERT (nullptr != m_pMainWindow);
m_pMainWindow->slotFreshRnStates(listIDs);
// Method2:
Q_ASSERT (nullptr != m_pMainWindow);
iWxRibbon* pWxRibbon = m_pMainWindow->getMainRibbon();
Q_ASSERT (nullptr != pWxRibbon);
foreach (QString sID, listIDs)
{
QWidget* pWxSubCtrl = pWxRibbon->getSubCtrl(sID);
if (nullptr != pWxSubCtrl)
{
pWxSubCtrl->setEnabled(false); //yours own codes here
}
}
}
#endif
return false;
}
bool nmSubWndDemo::runCmdBy(QString sName, QString sID)
{
if (iSubWndBaseFit::runCmdBy(sName, sID))
{
return true;
}
QString s = sName;
if (_isSame(s, "RunGrid"))
{
if (nullptr != m_pWxPlot)
{
//m_pWxPlot->refreshGrid(true);
}
return true;
}
return false;
}
void nmSubWndDemo::reAdjustToolbar(QToolBar* pToolBar)
{
iSubWndBaseFit::reAdjustToolbar(pToolBar);
}
void nmSubWndDemo::firstLoadAndUpdate()
{
iSubWndBaseFit::firstLoadAndUpdate();
}
void nmSubWndDemo::finalDeals()
{
iSubWndBaseFit::finalDeals();
#ifdef QT_DEBUG
updatePlots();
updateDockWxs();
Q_ASSERT (nullptr != m_pWxDockData1);
m_pWxDockData1->raise();
#endif
}
void nmSubWndDemo::onActivated()
{
#ifdef QT_DEBUG
// 当前窗体激活时可以做些事情比如把隐藏的Dock显示出来
if (nullptr != m_pWxDockTemp)
{
if (!m_pWxDockTemp->isVisible())
{
m_pWxDockTemp->setVisible(true);
}
}
#endif
}
#ifdef QT_DEBUG
void nmSubWndDemo::updatePlots()
{
return;
// 说明:以从当前井获取一条压力数据进行绘图为例
QString sType = iDataModelType::sTypeDataGaugeP;
QString sCodeP = ""; //如果已知压力数据Code可以直接引用
ZxDataGaugeP* pDataObjP = dynamic_cast<ZxDataGaugeP*>(getDataObjOf(sType, sCodeP));
if (nullptr == pDataObjP)
{
zxLogRunW(tr("Failed to get data of type '%1'").arg(sType));
return;
}
VecDouble vecX, vecY;
QByteArray ba = pDataObjP->getGaugeDataOf(0);
if (!ZxBaHelper::convertBa2VecXY(vecX, vecY, ba))
{
zxLogRunW(tr("Failed to get x-y data of dataobj '%1'").arg(pDataObjP->getCode()));
return;
}
nmGuiPlot* pWxPlot = m_pWxPlot;
Q_ASSERT (nullptr != pWxPlot);
QString sName = tr("CurveName");
ZxObjBase* pObj = pWxPlot->updatePlotObjBy(sName, vecX, vecY, true);
if (nullptr != pObj)
{
pObj->setLockPos(true); //可以调整属性
// pObj->setReadOnly(true);
pWxPlot->freshAxisScales(true);//刷新坐标轴刻度
// 设置标题+坐标轴等
pWxPlot->setAxisX(tr("Time"), s_Axis_UnitX);
pWxPlot->setAxisY(tr("Pressure"), s_Axis_UnitY_P);
pWxPlot->setAxisXYLog(false, 0);
pWxPlot->setAxisXYLog(false, 1);
pWxPlot->m_pPlot->setLegendVisible(false);
pWxPlot->m_pPlot->getTitle()->setName(tr("Demo"));
}
}
ZxDataObject* nmSubWndDemo::getDataObjOf(QString sType, QString sCode /*= ""*/)
{
ZxDataWell* pDataWell = zxCurWell;
Q_ASSERT (nullptr != pDataWell);
ZxDataObject* pDataObj = nullptr;
if (!sCode.isEmpty())
{
pDataObj = pDataWell->getChild(sType, sCode);
}
else
{
ZxDataObjectList vecObjs = pDataWell->getChildren(sType);
if (!vecObjs.isEmpty())
{
pDataObj = vecObjs[0];
}
}
return pDataObj;
}
void nmSubWndDemo::updateDockWxs()
{
// 左侧参数窗体
Q_ASSERT (nullptr != m_pWxParas);
QStringList listParas;
listParas << "K" << "S" << "rw" << "Miuo" << "Bo" << "phi";
m_pWxParas->refreshUIs(listParas);
// 表格数据1
Q_ASSERT (nullptr != m_pTableView1);
ZxTableModel* pTableModel = m_pTableView1->getModel();
Q_ASSERT (nullptr != pTableModel);
QStringList listTitles;
listTitles << tr("Col1") << tr("Col2\n(MPa)");
VVecDouble vvec;
{
VecDouble vec;
vec << 0.2 << 3.4;
vvec << vec;
}
{
VecDouble vec;
vec << 5.6 << 0.456;
vvec << vec;
}
pTableModel->setTitles(listTitles);
pTableModel->setData(vvec);
if (nullptr != m_pListWxTemp)
{
m_pListWxTemp->clear();
for (int i = 0; i < 10; i++)
{
QString sItem = tr("Demo Item %1").arg(i + 1);
QListWidgetItem* pItem = new QListWidgetItem(sItem);
Q_ASSERT (nullptr != pItem);
pItem->setIcon(zxLoadIcon("Open"));
m_pListWxTemp->addItem(pItem);
}
}
}
void nmSubWndDemo::updateTableByCurve(ZxObjCurve* pObjCurve, ZxTableView* pTableView)
{
Q_ASSERT (nullptr != pObjCurve);
Q_ASSERT (nullptr != pTableView);
// 刷新表格标题
{
QString sNameX = pObjCurve->getAxisX()->getName();
QString sUnit = pObjCurve->getAxisX()->getUnit();
if (!sUnit.isEmpty())
{
sNameX += QString("\n(%1)").arg(sUnit);
}
QString sNameY = pObjCurve->getAxisY()->getName();
sUnit = pObjCurve->getAxisY()->getUnit();
if (!sUnit.isEmpty())
{
sNameY += QString("\n(%1)").arg(sUnit);
}
QStringList listTitles;
listTitles << sNameX << sNameY;
pTableView->getModel()->setTitles(listTitles);
}
// 刷新表格数据
{
VVecDouble vvec;
QVector<QPointF> vecValues = pObjCurve->getAllValues();
for (int i = 0; i < vecValues.count(); i++)
{
VecDouble vec;
vec << vecValues.at(i).x() * 1.0;
vec << vecValues.at(i).y() * 1.0;
vvec << vec;
}
pTableView->getModel()->setData(vvec);
}
}
#endif
void nmSubWndDemo::slotObjSelChanged(ZxObjBase* p, bool b)
{
#ifdef QT_DEBUG
// 如果选中了一条曲线则把其数据显示在数据表格2中
ZxObjCurve* pObjCurve = dynamic_cast<ZxObjCurve*>(p);
if (nullptr != pObjCurve && b)
{
Q_ASSERT (nullptr != m_pWxDockData2);
m_pWxDockData2->raise();
updateTableByCurve(pObjCurve, m_pTableView2);
}
#endif
}
void nmSubWndDemo::slotObjPtsChanged(ZxObjBase* p)
{
}
void nmSubWndDemo::onSerialize(ZxSerializer* ser)
{
iSubWndBaseFit::onSerialize(ser);
if (nullptr != m_pWxPlot)
{
m_pWxPlot->setModified(false);
}
}
void nmSubWndDemo::onDeserialize(ZxSerializer* ser)
{
iSubWndBaseFit::onDeserialize(ser);
if (nullptr != m_pWxPlot)
{
m_pWxPlot->setModified(false);
}
}
void nmSubWndDemo::onDeserialized()
{
if (nullptr != m_pWxPlot)
{
m_pWxPlot->resetAfterDeserialized();
}
}
bool nmSubWndDemo::loadRsts()
{
// 存为文件
QString sDir = ZxBaseUtil::getCurWellDirOf("Nm");
//...
return true;//
/*
ZxRstWnd* pRstWnd = getRstUtilWnd();
Q_ASSERT (nullptr != pRstWnd);
// 基础信息
if (!loadRstBase(pRstWnd))
{
return false;
}
// 图形
if (nullptr != m_pWxPlot)
{
QByteArray v = QByteArray();
pRstWnd->loadSubPlotContent(v);
ZxPlot* pPlot = nullptr;
loadOnePlotFromBa(pPlot, v);
if (nullptr != pPlot)
{
m_pWxPlot->m_pPlotScene->freshToPlot(pPlot,
m_pWxPlot->m_pPlotView);
m_pWxPlot->m_pPlot = m_pWxPlot->m_pPlotScene->m_pPlot;
pPlot->resetTools(m_pWxPlot->m_pPlotView);
m_pWxPlot->resetAfterDeserialized();
}
m_pWxPlot->runUpdate();
}//*/
return true;
}
bool nmSubWndDemo::saveRsts()
{
// ZxRstWnd* pRstWnd = getRstUtilWnd();
// if (nullptr == pRstWnd)
// {
// return false;
// }
// 存为文件
QString sDir = ZxBaseUtil::getCurWellDirOf("Nm");
//...
return true;//
// // 基础信息
// if (!saveRstBase(pRstWnd))
// {
// return false;
// }
// // 图形
// if (nullptr != m_pWxPlot)
// {
// ZxPlot* pPlot = m_pWxPlot->m_pPlot;
// {
// QByteArray v1;
// if (saveOnePlotToBa(pPlot, v1))
// {
// pRstWnd->saveSubPlotContent(v1);
// }
// }
// }
// return pRstWnd->save();
return true;
}
bool nmSubWndDemo::slotSaveAll()
{
ZxRstWnd* pRstWnd = getRstUtilWnd();
Q_ASSERT (nullptr != pRstWnd);
return saveRsts();
}
bool nmSubWndDemo::onConfirmClosing()
{
return iSubWndBaseFit::onConfirmClosing();
}
bool nmSubWndDemo::checkCmdEnable(bool &b, \
QString sName, int nID, \
bool bLicensed)
{
bool b1 = (nullptr != zxCurProject);
bool b2 = (nullptr != m_pDataWell);
if (nID == 5102) //RunGrid
{
b =(b1 && b2 && bLicensed && !isReadonly() && nullptr != m_pWxPlot);
return true;
}
return iSubWndBaseFit::checkCmdEnable(b, sName, nID, bLicensed);
}