From 12b712c35d1e477e3978ea65ddbada2f5a73f523 Mon Sep 17 00:00:00 2001 From: jiayulong Date: Thu, 18 Jun 2026 09:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E5=A4=B4=EF=BC=8C=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E5=85=AC=E5=BC=8F=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PropertyWidget.cpp | 533 +++++++++++- logPlus/PropertyWidget.h | 12 + logPlus/mainwindow.cpp | 3 + qtpropertybrowser/QtFormulaDialogfactory.cpp | 870 +++++++++++++++++++ qtpropertybrowser/QtFormulaDialogfactory.h | 197 +++++ qtpropertybrowser/qtpropertybrowser.pro | 2 + 6 files changed, 1611 insertions(+), 6 deletions(-) create mode 100644 qtpropertybrowser/QtFormulaDialogfactory.cpp create mode 100644 qtpropertybrowser/QtFormulaDialogfactory.h diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index a61b109..43aa3d7 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -7,10 +7,10 @@ #include "CallManage.h" #include "geometryutils.h" #include "DrawTvd.h" +#include "qtprojectwidgets.h" extern double g_dPixelPerCm;//每厘米像素数 -//extern int m_iY1; -//extern int m_iY2; +extern QtProjectWidgets *g_projectWidgets; //左侧工程区 PropertyWidget::PropertyWidget(const QString &title, QWidget *parent , Qt::WindowFlags flags ) :QDockWidget(title,parent,flags) @@ -35,6 +35,14 @@ PropertyWidget::PropertyWidget(const QString &title, QWidget *parent , Qt::Windo m_pPropertyBrowser->setFactoryForManager(m_pColorSchemeManager, colorSchemeComboBoxFactory); connect(m_pColorSchemeManager, SIGNAL(valueChanged(QtProperty *, const int &, bool)), this, SLOT(SlotPropertyChanged(QtProperty *, const int &, bool))); + + CQtFormulaDialogFactory *formulaDlgFactory= new CQtFormulaDialogFactory(); + m_pFormulaDialogPropertyManager =new CQtFormulaDialogPropertyManager(); + m_pPropertyBrowser->setFactoryForManager(m_pFormulaDialogPropertyManager,formulaDlgFactory); + connect( m_pFormulaDialogPropertyManager,SIGNAL(valueChanged(QtProperty *, const QVariant &)), + this,SLOT(SlotPropertyChanged(QtProperty *, const QVariant &)) ); + connect( m_pFormulaDialogPropertyManager,SIGNAL(tableChanged(const QString &)), + this,SLOT(onTableChanged(const QString &)) ); } PropertyWidget::~PropertyWidget() @@ -2817,6 +2825,36 @@ QtProperty* PropertyWidget::_CreateColorSchemePropertyItem(QString strGroup, QSt return colorSchemeProperty; } +QtProperty* PropertyWidget::_CreateFormulaPropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue) +{ + QtProperty *pGroupItem = NULL; + { + QMap::Iterator it = m_mapGroupItem.find(strGroup); + if (it != m_mapGroupItem.end()) + { + pGroupItem = it.value(); + } + else + { + pGroupItem = m_pVariantManager->addProperty(QtVariantPropertyManager::groupTypeId(), strGroup); + m_mapGroupItem[strGroup] = pGroupItem; + m_pPropertyBrowser->addProperty(pGroupItem); + } + } + + QtProperty * formulaDlgProperty = m_pFormulaDialogPropertyManager->addProperty(strPropertyCaption); + if (formulaDlgProperty) + { + m_propertyData[formulaDlgProperty] = strPropertyCaption; + pGroupItem->addSubProperty(formulaDlgProperty); + m_pFormulaDialogPropertyManager->setValue(formulaDlgProperty,vtPropertyValue.toString()); + m_pFormulaDialogPropertyManager->setTableDataList(tableList); + m_pFormulaDialogPropertyManager->setFieldDataList(fieldList); + m_pFormulaDialogPropertyManager->setTableModelData(m_tableModelData); + } + return formulaDlgProperty; +} + void PropertyWidget::initWidgetProperty(QString strUuid, int iScale) { //初始化,清空 @@ -3165,6 +3203,10 @@ void PropertyWidget::initHeadProperty(FormHead *formHead, QTableWidget *tableWid _CreateVariantPropertyItem("单元格", "图例", imagePath, VariantManager::filePathTypeId()); //"./image/胜利符号库/岩性符号/砂岩.png" _CreateVariantPropertyItem("单元格", "图例宽(cm)", m_colWidth_Img, QVariant::Double, 0, 100); _CreateVariantPropertyItem("单元格", "图例高(cm)", m_rowHeight_Img, QVariant::Double, 0, 100); + + //读取图头公式 + ReadWellRoundDataToFormula(); + _CreateFormulaPropertyItem("单元格", "公式", ""); _CreateVariantPropertyItem("单元格", "背景颜色", m_item->background().color(), QVariant::Color); _CreateVariantPropertyItem("文本", "内容", item->text(), QVariant::String); @@ -6144,11 +6186,490 @@ void PropertyWidget::changedDcaProperty(QString strProperty, QVariant varVal) emit CallManage::getInstance()->sig_changeDcaProperty(variantMap); } +} +void ReadWellMessageData(CLogIO *logio ,ViewData &tableData) +{ + if (!logio) + { + return; + } + + //fieldList + QVector rowData; + Slf_FILE_MESSAGE msg; + logio->GetFileMessage(msg); + logio->Close(); +// delete logio; + + QList valueList; + //////////////////////////////////////1//////////////////////////////////// + QStringList partRow; + int i=0; + partRow <i) + { + rowList=valueList.at(i); + ////////////////////////////////////////////////////////////////////////// + for (int j=0;jgetLeftTreeString_Import(); + if(strLeft.length() > 0) + { + QStringList list = strLeft.split("#@@#");//QString字符串分割函数 + if (list.size() > 3) + { + strSlfName = list[0]; + strWellName = list[1]; + } + } + else { + QMessageBox::warning(this, "提示", "请先选中待处理井或井次!"); + return; + } + + // + if(strWellName != "") + { + QString wellFile = strSlfName; + + if(!wellFile.isEmpty()) + { + //获得表格头 + CLogIO *logio=new CLogIO; + QString logFileName=wellFile; + if(tableName ==QString("Well_Message")) + { +// logFileName=logFileName.replace(".slf",".well"); + } + + if(!logio->Open(logFileName.toStdString().c_str(),CLogIO::modeRead)) { + delete logio; + return ; + } + if (tableName == "CARD") + { + fieldList.clear(); + int count=logio->GetObjectCount(); + char* curvename=new char[65]; + curvename[64]='\0'; + char* aliasname=new char[65]; + aliasname[64]='\0'; + QVector rowData; + for(int i=0;iGetObjectStatus(i)!=OBJECT_NORMAL) continue; + logio->GetObjectName(i,curvename,NULL,aliasname); + short objectType=logio->GetObjectType(i); + //表格 + if(objectType==CARD_OBJECT) + { + QString tbName= QString::fromLocal8Bit(curvename); + fieldList << tbName; + rowData<<"CARD"; + } + } + delete curvename; + delete aliasname; + m_tableModelData.clear(); + m_tableModelData<OpenTable(name); + if (iIndex >=0) + { + //读取数据 + char buf[513]; + memset(buf,0,513); + int fc=logio->GetTableFieldCount(iIndex); + int rows= logio->GetTableRecordCount(iIndex); + + Slf_TABLE_FIELD *field=new Slf_TABLE_FIELD[fc+1]; + logio->GetTableFieldInfo(iIndex,field); + for(int j=0;jGetTableRecordLength(iIndex)+1; + char *Buffer=new char[buffSize]; + + QTime time; + time.start(); + int rIndex=0; + float yy; + + for (int r=0;r rowData; + rIndex=r+1; + memset(Buffer,0,buffSize); + logio->ReadTable(iIndex,rIndex,Buffer); + int ty=0; + int len=0; + for (int c=0;cGetData(ty,&Buffer[len],&yy); + ////////////////////////////////////////////////////////////////////////// + if(field[c].Reserved) { + ty=sizeof(RepSize)+1; + if(field[c].Reserved>0&&field[c].Reservedm_MenuNumber) + { + logio->GetReservedValue(yy,field[c].Reserved,Buffer,buf,buffSize-1); + } + else sprintf(buf,"%f",yy); + }else + sprintf(buf,"%f",yy);/**/ + }else + { + strncpy(buf,&Buffer[len],field[c].Length); + buf[field[c].Length]='\0';/**/ + } + if(strlen(buf)>512) + { + buf[512]=0; + } + rowData.append(toString(buf)); + len+=field[c].Length; + } + m_tableModelData.append(rowData); + if (r > 2&&tableName!="测井信息表"&&tableName.indexOf("_TT")<1) + { + //break; + } + } + delete Buffer; + delete[] field; + qDebug()<<"time:==========="<CloseTable(iIndex); + } + delete logio; + } + } + if (tableName == QString("测井信息表")) + { + QStringList tempFields; + for(int i=0;isetTableDataList(tableList); + m_pFormulaDialogPropertyManager->setFieldDataList(fieldList); + m_pFormulaDialogPropertyManager->setTableModelData(m_tableModelData); + } + } +} + +void PropertyWidget::ReadWellRoundDataToFormula() +{ + QString tbName; + m_tableModelData.clear(); + fieldList.clear(); + tableList.clear(); + + QString strSlfName = ""; + QString strWellName = ""; + QString strLeft = g_projectWidgets->getLeftTreeString_Import(); + if(strLeft.length() > 0) + { + QStringList list = strLeft.split("#@@#");//QString字符串分割函数 + if (list.size() > 3) + { + strSlfName = list[0]; + strWellName = list[1]; + } + } + else { + QMessageBox::warning(this, "提示", "请先选中待处理井或井次!"); + return; + } + + // + if(strWellName != "") + { + QString wellFile = strSlfName; + + if(!wellFile.isEmpty()) + { + //获得表格头 + CLogIO *logio=new CLogIO; + if(!logio->Open(wellFile.toStdString().c_str(),CLogIO::modeRead)) { + delete logio; + return ; + } + tableList << "Well_Message"; + tableList << "CARD"; + int count=logio->GetObjectCount(); + char* curvename=new char[65]; + curvename[64]='\0'; + char* aliasname=new char[65]; + aliasname[64]='\0'; + for(int i=0;iGetObjectStatus(i)!=OBJECT_NORMAL) continue; + logio->GetObjectName(i,curvename,NULL,aliasname); + short objectType=logio->GetObjectType(i); + //表格 + if(objectType >CARD_OBJECT||objectType==0) + { + tbName= QString::fromLocal8Bit(curvename); + tableList << tbName; + } + } + delete curvename; + delete aliasname; + char name[100]; + if (tableList.size() == 0) + { + delete logio; + return; + } + tbName=tableList.value(0); + if (tbName.isEmpty()) + { + delete logio; + return; + } + fieldList=GetWellMessageFields(); + ReadWellMessageData(logio,m_tableModelData); + delete logio; + } + } } - - - - diff --git a/logPlus/PropertyWidget.h b/logPlus/PropertyWidget.h index 67214f5..1d00e12 100644 --- a/logPlus/PropertyWidget.h +++ b/logPlus/PropertyWidget.h @@ -15,6 +15,7 @@ #include "variantmanager.h" #include "variantfactory.h" #include "ColorSchemeComboBox.h" +#include "QtFormulaDialogfactory.h" // #include "forminfo.h" #include "formhead.h" @@ -89,6 +90,8 @@ #pragma execution_character_set("utf-8") +typedef QVector > ViewData; + /** * @class PropertyWidget * @brief 统一属性服务 @@ -107,6 +110,7 @@ private: QtTreePropertyBrowser *m_pPropertyBrowser; QtVariantPropertyManager *m_pVariantManager; QtColorSchemeComboBoxPropertyManager * m_pColorSchemeManager; + CQtFormulaDialogPropertyManager * m_pFormulaDialogPropertyManager; public: QString m_strUuid; @@ -168,6 +172,10 @@ public: int m_sdVerticalDepthPosition = 0; int m_sdElevationVerticalDepthPosition = 0; + //图头,成果表 + QStringList tableList,fieldList; + ViewData m_tableModelData; + public: QWidget* GetPropertyWidget(); @@ -176,6 +184,9 @@ public: void _CreateEnumPropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue, QStringList listValue); QtProperty* _CreateColorSchemePropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue, int nclr); + QtProperty* _CreateFormulaPropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue); + //读取图头公式 + void ReadWellRoundDataToFormula(); void InitCurrentViewInfo(bool bAll = true); //初始化属性,清空 void initWidgetProperty(QString strUuid, int iScale); //可视解释整体属性 @@ -302,6 +313,7 @@ public: public slots: void SlotPropertyChanged(QtProperty *property, const QVariant &variant); void SlotPropertyChanged(QtProperty *property, const int &val, bool islinestyle); + void onTableChanged(const QString &tableName); }; extern PropertyWidget* PropertyService(); diff --git a/logPlus/mainwindow.cpp b/logPlus/mainwindow.cpp index 20e1752..07e59b4 100644 --- a/logPlus/mainwindow.cpp +++ b/logPlus/mainwindow.cpp @@ -65,6 +65,8 @@ int g_iPageStep = 1500; QString g_strSlfName = ""; QString g_strWellName = ""; +QtProjectWidgets *g_projectWidgets = nullptr; //左侧工程区 + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -429,6 +431,7 @@ void MainWindow::dockLayout() m_projectWidgets = new QtProjectWidgets(this); dock1->setWidget(m_projectWidgets); addDockWidget(Qt::LeftDockWidgetArea,dock1); + g_projectWidgets = m_projectWidgets; //属性编辑器 m_propertyWidget = PropertyService(); diff --git a/qtpropertybrowser/QtFormulaDialogfactory.cpp b/qtpropertybrowser/QtFormulaDialogfactory.cpp new file mode 100644 index 0000000..0afb23f --- /dev/null +++ b/qtpropertybrowser/QtFormulaDialogfactory.cpp @@ -0,0 +1,870 @@ +#include "QtFormulaDialogfactory.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "BaseObject.h" +//#include "ObjectID.h" +//#include "DialogFactory.h" +///*#include "geo"*/ +//using namespace pai::datamodel; + +static inline void setupTreeViewEditorMargin(QLayout *lt) +{ + enum { DecorationMargin = 4 }; + if (QApplication::layoutDirection() == Qt::LeftToRight) + lt->setContentsMargins(DecorationMargin, 0, 0, 0); + else + lt->setContentsMargins(0, 0, DecorationMargin, 0); +} + +template +static Value getData(const QMap &propertyMap, + Value PrivateData::*data, + const QtProperty *property, const Value &defaultValue = Value()) +{ + typedef QMap PropertyToData; + typedef typename PropertyToData::const_iterator PropertyToDataConstIterator; + const PropertyToDataConstIterator it = propertyMap.constFind(property); + if (it == propertyMap.constEnd()) + return defaultValue; + return it.value().*data; +} + +template +static Value getValue(const QMap &propertyMap, + const QtProperty *property, const Value &defaultValue = Value()) +{ + return getData(propertyMap, &PrivateData::val, property, defaultValue); +} + +CQtFormulaDialogFactory::CQtFormulaDialogFactory(QObject *parent) + : QtAbstractEditorFactory(parent), d_ptr(new CQtFormulaDialogFactoryPrivate()) +{ + d_ptr->q_ptr = this; + +} + +/*! + Destroys this factory, and all the widgets it has created. +*/ +CQtFormulaDialogFactory::~CQtFormulaDialogFactory() +{ + qDeleteAll(d_ptr->m_editorToProperty.keys()); +} + +/*! + \internal + + Reimplemented from the QtAbstractEditorFactory class. +*/ +void CQtFormulaDialogFactory::connectPropertyManager(CQtFormulaDialogPropertyManager *manager) +{ + connect(manager, SIGNAL(valueChanged(QtProperty*, QVariant)), + this, SLOT(slotPropertyChanged(QtProperty*, QVariant))); +} + + + /*! + \internal + + Reimplemented from the QtAbstractEditorFactory class. +*/ +QWidget *CQtFormulaDialogFactory::createEditor(CQtFormulaDialogPropertyManager *manager, QtProperty *property, + QWidget *parent) +{ + + CQtFormulaDialogEditWidget *editor = d_ptr->createEditor(property, parent); + connect(editor,SIGNAL(tableChanged(const QString&)),manager,SIGNAL(tableChanged(const QString&)),Qt::UniqueConnection); + editor->tableDataList=manager->tableDataList; + editor->fieldList=manager->fieldDataList; + editor->tableModelData=manager->tableModelData; + connect(manager,SIGNAL(fieldListChanged(const QStringList&)),editor,SLOT(setComboxFieldDataList(const QStringList&)),Qt::UniqueConnection); + connect(manager,SIGNAL(tableListChanged(const QStringList&)),editor,SLOT(setComboxTableDataList(const QStringList&)),Qt::UniqueConnection); + + connect(manager,SIGNAL(tableModelDataChanged(const ViewData&)),editor,SLOT(setTableModeData(const ViewData&)),Qt::UniqueConnection); + + //connect(manager,SIGNAL(signalCallFormulaDialogAction()),editor,SLOT(buttonClicked())); + + //editor->defaultDir=manager->defaultDir; + //editor->filter=manager->filter; + editor->setValue(manager->value(property)); + + + connect(editor, SIGNAL(valueChanged(QString)), this, SLOT(slotSetValue(QString)),Qt::UniqueConnection); + connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)),Qt::UniqueConnection); + return editor; + +} + +/*! + \internal + + Reimplemented from the QtAbstractEditorFactory class. +*/ +void CQtFormulaDialogFactory::disconnectPropertyManager(CQtFormulaDialogPropertyManager *manager) +{ + disconnect(manager, SIGNAL(valueChanged(QtProperty*,QString)), + this, SLOT(slotPropertyChanged(QtProperty*,QString))); +} + + +void CQtFormulaDialogFactoryPrivate::slotPropertyChanged(QtProperty *property, QString value) +{ + + const PropertyToEditorListMap::iterator it = m_createdEditors.find(property); + if (it == m_createdEditors.end()) + return; + QListIterator itEditor(it.value()); + + while (itEditor.hasNext()) + itEditor.next()->setValue(value); +} + +void CQtFormulaDialogFactoryPrivate::slotSetValue(QString value) +{ + QObject *object = q_ptr->sender(); + const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); + for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) + if (itEditor.key() == object) { + QtProperty *property = itEditor.value(); + CQtFormulaDialogPropertyManager *manager = q_ptr->propertyManager(property); + if (!manager) + return; + manager->setValue(property, value); + return; + } +} + + + +CQtFormulaDialogPropertyManager::CQtFormulaDialogPropertyManager(QObject *parent) + : QtAbstractPropertyManager(parent), d_ptr(new CQtFormulaDialogPropertyManagerPrivate) +{ + d_ptr->q_ptr = this; +} + +/*! + Destroys this manager, and all the properties it has created. +*/ +CQtFormulaDialogPropertyManager::~CQtFormulaDialogPropertyManager() +{ + clear(); +} + +/*! + Returns the given \a property's value which is an index in the + list returned by enumNames() + + If the given property is not managed by this manager, this + function returns -1. + + \sa enumNames(), setValue() +*/ +QString CQtFormulaDialogPropertyManager::value(const QtProperty *property) const +{ + return d_ptr->m_values.value(property, QString()); +} + +/*! + Returns the given \a property's list of enum names. + + \sa value(), setEnumNames() +*/ +/*! + \reimp +*/ +QString CQtFormulaDialogPropertyManager::valueText(const QtProperty *property) const +{ + const CQtFormulaDialogPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); + if (it == d_ptr->m_values.constEnd()) + return QString(); + QString avalue=*it; + QString strFilePath = avalue;//得到用户输入的文件名 + strFilePath.replace("\\","/"); + QString file = strFilePath.split("/").takeLast(); + //QString filename = file.split(".").takeFirst(); + return file; +} + +void CQtFormulaDialogPropertyManager::setFieldDataList(const QStringList &fieldList) +{ + fieldDataList=fieldList; + emit fieldListChanged(fieldList); +} +void CQtFormulaDialogPropertyManager::setTableDataList(const QStringList &tableList) +{ + tableDataList=tableList; + emit tableListChanged(tableList); +} +void CQtFormulaDialogPropertyManager::setTableModelData(const ViewData &modelData) +{ + tableModelData=modelData; + emit tableModelDataChanged(modelData); +} +/*! + \fn void QtLineStyleEnumPropertyManager::setValue(QtProperty *property, int value) + + Sets the value of the given \a property to \a value. + + The specified \a value must be less than the size of the given \a + property's enumNames() list, and larger than (or equal to) 0. + + \sa value(), valueChanged() +*/ +void CQtFormulaDialogPropertyManager::setValue(QtProperty *property, QString val) +{ + QString strFilePath = val;//得到用户输入的文件名 + strFilePath.replace("\\","/"); + QString file = strFilePath.split("/").takeLast(); + //QString filename = file.split(".").takeFirst(); + const CQtFormulaDialogPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); + if (it == d_ptr->m_values.end()) + return; + + *it = file; + //m_label->setText(filename); + emit propertyChanged(property); + emit valueChanged(property, val); + + +} + +/*! + Sets the given \a property's list of enum names to \a + enumNames. The \a property's current value is reset to 0 + indicating the first item of the list. + + If the specified \a enumNames list is empty, the \a property's + current value is set to -1. + + \sa enumNames(), enumNamesChanged() +*/ + +/*! + Sets the given \a property's map of enum values to their icons to \a + enumIcons. + + Each enum value can have associated icon. This association is represented with passed \a enumIcons map. + + \sa enumNames(), enumNamesChanged() +*/ +/*! + \reimp +*/ +void CQtFormulaDialogPropertyManager::initializeProperty(QtProperty *property) +{ + d_ptr->m_values[property] = "可疑气油层"; +} + +/*! + \reimp +*/ +void CQtFormulaDialogPropertyManager::uninitializeProperty(QtProperty *property) +{ + d_ptr->m_values.remove(property); +} + +//void CQtFormulaDialogPropertyManager::onGraphicsHeadCellFormula(const QString &formla) +//{ +// cellFormula=formla; +//} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//CQTtGeoStraEditWidget +CQtFormulaDialogEditWidget::CQtFormulaDialogEditWidget(QWidget *parent) : +QWidget(parent), + m_label(new QLabel), + m_button(new QToolButton), + m_formula(""), + m_tableCombox(new QComboBox), + m_fieldCombox(new QComboBox), + m_tableView(new QTableWidget), + btnAccpted(new QPushButton), + btnCancel(new QPushButton), + formulaDialog(new QDialog), + lblTable(new QLabel), + lblField(new QLabel), + lblSmall(new QLabel), + m_smallBox(new QSpinBox), + m_listWidget(new QListWidget), + btnAddCompute(new QPushButton), + btnSubtractCompute(new QPushButton), + btnMultiplyCompute(new QPushButton), + btnDivideCompute(new QPushButton), + btnAppend(new QPushButton), + btnUndo(new QPushButton), + editline(new QLineEdit()), + Noline(new QLineEdit()), + NoLabel(new QLabel), + m_lable1(new QLabel) +{ + + m_computeSymbol<<"+"<<"-"<<"*"<<"/"; + QHBoxLayout *lt = new QHBoxLayout(this); + setupTreeViewEditorMargin(lt); + lt->setSpacing(0); + lt->addWidget(m_label); + lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); + + m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); + m_button->setFixedWidth(20); + setFocusProxy(m_button); + setFocusPolicy(m_button->focusPolicy()); + m_button->setText(tr("...")); + m_button->installEventFilter(this); + + lt->addWidget(m_button); + m_label->setText(m_formula); + m_tableView->setMouseTracking(true); + formulaDialog->setLayout(NULL); + initConnect(); +} +void CQtFormulaDialogEditWidget::initConnect() +{ + connect(m_tableCombox,SIGNAL(currentIndexChanged(const QString &)),this,SIGNAL(tableChanged(const QString &)),Qt::UniqueConnection); + connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked())); + connect(btnAccpted,SIGNAL(clicked()),this,SLOT(onAcceptOk()),Qt::UniqueConnection); + connect(btnCancel,SIGNAL(clicked()),this,SLOT(onCancel()),Qt::UniqueConnection); + + + connect(btnAddCompute,SIGNAL(clicked()),this,SLOT(onAddCompute()),Qt::UniqueConnection); + connect(btnSubtractCompute,SIGNAL(clicked()),this,SLOT(onSubtractCompute()),Qt::UniqueConnection); + connect(btnMultiplyCompute,SIGNAL(clicked()),this,SLOT(onMultipyCompute()),Qt::UniqueConnection); + connect(btnDivideCompute,SIGNAL(clicked()),this,SLOT(onDivideCompute()),Qt::UniqueConnection); + + connect(btnAppend,SIGNAL(clicked()),this,SLOT(onAppend()),Qt::UniqueConnection); + connect(btnUndo,SIGNAL(clicked()),this,SLOT(onUndo()),Qt::UniqueConnection); + connect(m_tableView,SIGNAL(cellPressed(int, int)),this,SLOT(onCellPressed(int,int))); + +} +void CQtFormulaDialogEditWidget::onCellPressed(int row,int column) +{ + int rows=m_tableView->rowCount(); + int cols=m_tableView->columnCount(); + if (row >=0 && column < cols) + { + m_fieldCombox->setCurrentIndex(column); + } + QTableWidgetItem *item=m_tableView->item(row,column); + QString cellText,cellSam; + if (item) + { + cellText=item->text(); + } + if (cellText.isEmpty()) + { + return; + } + bool isOk=false; + float value=cellText.toFloat(&isOk); + int leftMid=0,canSize=0,orgSize=0; + if (isOk) + { + + leftMid= cellText.lastIndexOf("."); + + if (leftMid >=0) + { + leftMid=cellText.size()-(leftMid+1); + cellSam=cellText.right(leftMid); + } + + } + + m_smallBox->setValue(cellSam.size()); + +} +CQtFormulaDialogEditWidget::~CQtFormulaDialogEditWidget() +{ + if(formulaDialog) + { + delete formulaDialog; + formulaDialog=NULL; + } + +} +void CQtFormulaDialogEditWidget::setComboxFieldDataList() +{ + + m_fieldCombox->clear(); + foreach(const QString &itemText,fieldList) + { + m_fieldCombox->addItem(itemText); + } +} +void CQtFormulaDialogEditWidget::setComboxTableDataList() +{ + + m_tableCombox->clear(); + foreach(const QString &itemText,tableDataList) + { + m_tableCombox->addItem(itemText); + } + +} + +void CQtFormulaDialogEditWidget::setComboxFieldDataList(const QStringList& list) +{ + fieldList=list; + setComboxFieldDataList(); +} +void CQtFormulaDialogEditWidget::setComboxTableDataList(const QStringList& list) +{ + tableDataList=list; + setComboxTableDataList(); + +} + +void CQtFormulaDialogEditWidget::setTableModeData(const ViewData & tableData) +{ + tableModelData=tableData; + bindTableData(); +} + +void CQtFormulaDialogEditWidget::setValue(const QString &c) +{ + if (m_formula != c) + { + m_formula = c; + m_label->setText(c); + } +} +void CQtFormulaDialogEditWidget::showFormulaDlg() +{ + + setComboxFieldDataList(); + initUI(); + //bindTableData(); + QString formulaStr("=TABLE(%1:%2:%3.%4)"); + + QString tableName,fieldName,mapFieldKey,mapFieldValue; + int tbCount=0,fieldCount=0; + bindCellFormula(); + if(formulaDialog->exec() == QDialog::Accepted) + { + tbCount=m_tableCombox->count(); + fieldCount=m_fieldCombox->count(); + if(tbCount == 0 || fieldCount ==0) + { + return; + } + formulaStr=combinationFormual(); + setValue(formulaStr); + emit valueChanged(formulaStr); + } +} +void CQtFormulaDialogEditWidget::initUI() +{ + bool applayLayout=NULL == formulaDialog->layout(); + if(applayLayout) + { + + setComboxTableDataList(); + //formulaDialog->setWindowFlags(Qt::FramelessWindowHint); + + m_tableView->setParent(formulaDialog); + m_tableCombox->setParent(formulaDialog); + m_fieldCombox->setParent(formulaDialog); + btnAccpted->setParent(formulaDialog); + btnCancel->setParent(formulaDialog); + lblTable->setParent(formulaDialog); + editline->setParent(formulaDialog); + Noline->setParent(formulaDialog); + m_lable1->setParent(formulaDialog); + lblField->setParent(formulaDialog); + + lblSmall->setParent(formulaDialog); + m_smallBox->setParent(formulaDialog); + m_listWidget->setParent(formulaDialog); + btnAddCompute->setParent(formulaDialog); + btnSubtractCompute->setParent(formulaDialog); + btnMultiplyCompute->setParent(formulaDialog); + btnDivideCompute->setParent(formulaDialog); + btnAppend->setParent(formulaDialog); + btnUndo->setParent(formulaDialog); + m_smallBox->setMinimum(0); + m_smallBox->setMaximum(6); + m_smallBox->setValue(0); + + formulaDialog->resize(800,500); + + m_lable1->setText("输入附加信息"); + btnAccpted->setText("确定"); + btnCancel->setText("取消"); + lblTable->setText("选择数据表"); + lblField->setText("选择字段"); + lblSmall->setText("小数位数"); + btnAddCompute->setText("+"); + btnSubtractCompute->setText("-"); + btnMultiplyCompute->setText("*"); + btnDivideCompute->setText("/"); + btnAppend->setText("添加"); + btnUndo->setText("回退"); + + + QHBoxLayout *hMainboxLayout=new QHBoxLayout(formulaDialog); + QVBoxLayout *vRightBoxLayout=new QVBoxLayout(formulaDialog); + QVBoxLayout *vboxLayout=new QVBoxLayout(formulaDialog); + QHBoxLayout *hboxLayout=new QHBoxLayout(formulaDialog); + QHBoxLayout *bottomhboxLayout=new QHBoxLayout(formulaDialog); + + hboxLayout->addWidget(lblTable); + hboxLayout->addWidget(m_tableCombox); + + hboxLayout->addWidget(lblField); + hboxLayout->addWidget(m_fieldCombox); + + hboxLayout->addWidget(lblSmall); + hboxLayout->addWidget(m_smallBox); + + hboxLayout->addStretch(); + vboxLayout->addItem(hboxLayout); + vboxLayout->addWidget(m_listWidget,1); + // + vboxLayout->addWidget(m_tableView,2); + + bottomhboxLayout->addStretch(); + bottomhboxLayout->addWidget(m_lable1); + bottomhboxLayout->addWidget(editline); + bottomhboxLayout->addWidget(btnAccpted); + bottomhboxLayout->addWidget(btnCancel); + vboxLayout->addStretch(); + vboxLayout->addItem(bottomhboxLayout); + + vRightBoxLayout->addWidget(btnAddCompute); + vRightBoxLayout->addWidget(btnSubtractCompute); + vRightBoxLayout->addWidget(btnMultiplyCompute); + vRightBoxLayout->addWidget(btnDivideCompute); + vRightBoxLayout->addStretch(); + vRightBoxLayout->addWidget(btnAppend); + vRightBoxLayout->addWidget(btnUndo); + vRightBoxLayout->addStretch(); + NoLabel->setText("特定行"); + vRightBoxLayout->addWidget(NoLabel); + vRightBoxLayout->addWidget(Noline); + + vRightBoxLayout->addStretch(); + + hMainboxLayout->addItem(vboxLayout); + hMainboxLayout->addItem(vRightBoxLayout); + + formulaDialog->setWindowTitle("选择表及字段"); + + } +} +QString CQtFormulaDialogEditWidget::combinationFormual() +{ + QString formual; + int rows=m_listWidget->count(); + if(rows == 0) + { + return formual; + } + QListWidgetItem *item=NULL; + QStringList symbolList; + for(int i=0;iitem(i); + if(item) + { + symbolList << item->text(); + } + } + formual=symbolList.join(""); + return formual; +} +void CQtFormulaDialogEditWidget::onAcceptOk() +{ + formulaDialog->accept(); +} +void CQtFormulaDialogEditWidget::onCancel() +{ + formulaDialog->close(); +} + +void CQtFormulaDialogEditWidget::bindTableData() +{ + + int cols=0; + int rows=m_tableView->rowCount(); + QAbstractItemModel *itemModel=m_tableView->model(); + if (itemModel) + { + itemModel->removeRows(0,rows); + } + // 表字段 + cols= fieldList.size(); + // 表数据 + rows=tableModelData.size(); + if(rows == 0) + { + return; + } + m_tableView->setRowCount(rows); + m_tableView->setColumnCount(cols); + m_tableView->setHorizontalHeaderLabels(fieldList); + m_tableView->setSelectionMode(QAbstractItemView::SingleSelection); + m_tableView->setSelectionBehavior(QAbstractItemView::SelectItems); + + QHeaderView *headView= m_tableView->horizontalHeader(); + headView->setStretchLastSection(true); + itemModel=m_tableView->model(); + + QString text; + for(int r=0;rsetData(itemModel->index(r,c),text,Qt::DisplayRole); + } + } + } + + bindCellFormula(); +} +void CQtFormulaDialogEditWidget::buttonClicked() +{ + //QFileDialog fileDialog; + showFormulaDlg(); +} + +//compute slots +void CQtFormulaDialogEditWidget::onAddCompute() +{ + appendComputeSymbol(btnAddCompute); + +} +void CQtFormulaDialogEditWidget::onSubtractCompute() +{ + appendComputeSymbol(btnSubtractCompute); +} +void CQtFormulaDialogEditWidget::onMultipyCompute() +{ + appendComputeSymbol(btnMultiplyCompute); +} +void CQtFormulaDialogEditWidget::onDivideCompute() +{ + appendComputeSymbol(btnDivideCompute); +} +void CQtFormulaDialogEditWidget::appendComputeSymbol(QPushButton *button) +{ + + QString symbolStr; + bool isAppend=false; + if (button) + { + symbolStr=button->text().trimmed(); + isAppend=isAppendValidate(symbolStr); + if (isAppend) + { + m_listWidget->addItem(symbolStr); + } + } +} +bool CQtFormulaDialogEditWidget::isAppendValidate(const QString &rowItem) +{ + int rows=m_listWidget->count(); + bool isValidate=false; + QString symbolStr; + if(rows == 0 && !m_computeSymbol.contains(rowItem)) + { + isValidate=true; + + }else if(rows > 0) + { + QListWidgetItem *item= m_listWidget->item(rows-1); + symbolStr=item->text().trimmed(); + if(m_computeSymbol.contains(rowItem) && !m_computeSymbol.contains(symbolStr)) + { + isValidate=true; + + }else if (m_computeSymbol.contains(symbolStr) && !m_computeSymbol.contains(rowItem)) + { + isValidate=true; + } + } + return isValidate; +} +// fun +void CQtFormulaDialogEditWidget::onAppend() +{ + int tbCount=m_tableCombox->count(); + int fieldCount=m_fieldCombox->count(); + if(tbCount == 0 || fieldCount ==0) + { + return; + } + QString formualTable=buildTableFormulaRow(); + bool isAppend=isAppendValidate(formualTable); + if(isAppend) + { + m_listWidget->addItem(formualTable); + } + +} +void CQtFormulaDialogEditWidget::onUndo() +{ + int rows=m_listWidget->count(); + if(rows == 0) + { + return; + } + int index=rows -1; + QListWidgetItem* item=m_listWidget->takeItem(index); + if (item) + { + delete item; + item=NULL; + } + + //QListWidgetItem *item= m_listWidget->item(rows-1); + //m_listWidget->removeItemWidget(item); +} + +QString CQtFormulaDialogEditWidget::buildTableFormulaRow(const QString &computeFlag) +{ + QString formulaStr("=TABLE(%1:%2:%3.%4)"); + QString tableName,fieldName; + int recordNo=0,reatinNum=m_smallBox->value(); + if(computeFlag.isEmpty()) + { + tableName=m_tableCombox->currentText(); + fieldName=m_fieldCombox->currentText(); + recordNo=m_tableView->currentRow()+1; + if(editline->text()!="") + { + tableName="QString"; + fieldName=editline->text(); + recordNo=-1; + } + if(Noline->text()!="") { + formulaStr=formulaStr.arg(tableName).arg(fieldName).arg(Noline->text()).arg(reatinNum); + } + else formulaStr=formulaStr.arg(tableName).arg(fieldName).arg(recordNo).arg(reatinNum); + }else + { + formulaStr=computeFlag; + + } + return formulaStr; +} +//QString GetImagePath() +//{ +// static QString imgpath; +// if(imgpath!="") return imgpath; +// QString strImagePath; +// { +// QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator(); +// strImagePath = QDir::toNativeSeparators( strPathTmp ); +// QDir dir; +// if( dir.exists( strPathTmp + "image" ) ) +// { +// return strPathTmp + "image" + QDir::separator(); +// }else +// { +// strImagePath = strImagePath+".."+ "/LogPlus/image/"; +// } +// } +// imgpath=strImagePath; +// return imgpath; +//} +bool CQtFormulaDialogEditWidget::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj == m_button) { + switch (ev->type()) { + case QEvent::KeyPress: + case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate + switch (static_cast(ev)->key()) { + case Qt::Key_Escape: + case Qt::Key_Enter: + case Qt::Key_Return: + ev->ignore(); + return true; + default: + break; + } + } + break; + default: + break; + } + } + return QWidget::eventFilter(obj, ev); +} + +void CQtFormulaDialogEditWidget::bindCellFormula() +{ + //QString formulaStr("=TABLE(%1:%2:%3.%4)"); + QStringList formulaLst; + QString formula; + QString computeChar; + int sIndex=0,eIndex=0; + + if (m_formula.isEmpty()) + { + return; + } + + while(true) + { + eIndex = m_formula.indexOf(")",sIndex); + if (eIndex == -1) + { + break; + } + int tSize=m_formula.size(); + eIndex++; + + if (eIndex != m_formula.size()) + { + computeChar= m_formula.mid(eIndex,1); + } + + formula = m_formula.mid(sIndex,eIndex-sIndex); + formulaLst << formula; + if (!computeChar.isEmpty()) + { + formulaLst << computeChar; + eIndex++; + computeChar=QString(""); + } + + sIndex=eIndex; + } + + // 清空公式列表 + int rows=m_listWidget->count(); + while(rows > 0) + { + QListWidgetItem* item=m_listWidget->takeItem(0); + if (item) + { + delete item; + item=NULL; + } + rows=m_listWidget->count(); + } + + // 绑定到listview + for (int i=0;i < formulaLst.size(); i++) + { + formula=formulaLst.value(i); + bool isAppend=isAppendValidate(formula); + if(isAppend) + { + m_listWidget->addItem(formula); + } + } + +} diff --git a/qtpropertybrowser/QtFormulaDialogfactory.h b/qtpropertybrowser/QtFormulaDialogfactory.h new file mode 100644 index 0000000..b5928c4 --- /dev/null +++ b/qtpropertybrowser/QtFormulaDialogfactory.h @@ -0,0 +1,197 @@ +#ifndef QTFORMULADIALOGFACTORY_H +#define QTFORMULADIALOGFACTORY_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qteditorfactory.h" + +#pragma execution_character_set("utf-8") + +QT_BEGIN_NAMESPACE +class CQtFormulaDialogfactoryPrivate; +class CQtFormulaDialogPropertyManagerPrivate; + +typedef QVector > ViewData; + +class QTPROPERTYBROWSER_EXPORT CQtFormulaDialogPropertyManager : public QtAbstractPropertyManager +{ + Q_OBJECT +public: + CQtFormulaDialogPropertyManager(QObject *parent = 0); + ~CQtFormulaDialogPropertyManager(); + + QString value(const QtProperty *property) const; + QStringList enumNames(const QtProperty *property) const; + QMap enumIcons(const QtProperty *property) const; + + void setFieldDataList(const QStringList &fieldList); + void setTableDataList(const QStringList &tableList); + void setTableModelData(const ViewData &modelData); + + + + QStringList tableDataList; + QStringList fieldDataList; + ViewData tableModelData; + //QMap m_mapWellInfoFields; + //QString cellFormula; + //QString defaultDir; + //QString filter; + + public Q_SLOTS: + void setValue(QtProperty *property, QString val); + /* void onGraphicsHeadCellFormula(const QString &formla);*/ + +Q_SIGNALS: + void valueChanged(QtProperty *property, const QVariant &); + + void tableChanged(const QString &); + + void fieldListChanged(const QStringList&); + void tableListChanged(const QStringList&); + void tableModelDataChanged(const ViewData&); + + +protected: + QString valueText(const QtProperty *property) const; + virtual void initializeProperty(QtProperty *property); + virtual void uninitializeProperty(QtProperty *property); +private: + QScopedPointer d_ptr; + + + Q_DECLARE_PRIVATE(CQtFormulaDialogPropertyManager) + Q_DISABLE_COPY(CQtFormulaDialogPropertyManager) +}; + + + +class QTPROPERTYBROWSER_EXPORT CQtFormulaDialogPropertyManagerPrivate +{ + CQtFormulaDialogPropertyManager *q_ptr; + Q_DECLARE_PUBLIC(CQtFormulaDialogPropertyManager) +public: + + typedef QMap PropertyValueMap; + PropertyValueMap m_values; +}; + + +class CQtFormulaDialogFactoryPrivate; + +class QTPROPERTYBROWSER_EXPORT CQtFormulaDialogFactory : public QtAbstractEditorFactory +{ + Q_OBJECT +public: + CQtFormulaDialogFactory(QObject *parent = 0); + ~CQtFormulaDialogFactory(); + +protected: + void connectPropertyManager(CQtFormulaDialogPropertyManager *manager); + QWidget *createEditor(CQtFormulaDialogPropertyManager *manager, QtProperty *property, + QWidget *parent); + void disconnectPropertyManager(CQtFormulaDialogPropertyManager *manager); +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(CQtFormulaDialogFactory) + Q_DISABLE_COPY(CQtFormulaDialogFactory) + Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, QString)) + Q_PRIVATE_SLOT(d_func(), void slotSetValue(QString)) + Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) + +}; + + +class CQtFormulaDialogEditWidget; +class QTPROPERTYBROWSER_EXPORT CQtFormulaDialogFactoryPrivate : public EditorFactoryPrivate +{ + CQtFormulaDialogFactory *q_ptr; + Q_DECLARE_PUBLIC(CQtFormulaDialogFactory) +public: + + void slotPropertyChanged(QtProperty *property, QString value); + void slotSetValue(QString value); +}; + +// CQtFormulaDialogEditWidget +QString GetImagePath(); +class CQtFormulaDialogEditWidget : public QWidget { + Q_OBJECT + +public: + CQtFormulaDialogEditWidget(QWidget *parent); + ~CQtFormulaDialogEditWidget(); + + bool eventFilter(QObject *obj, QEvent *ev); + QStringList tableDataList; + QStringList fieldList; + ViewData tableModelData; + QMap mapWellInfoFields; + + + public Q_SLOTS: + void setValue(const QString &value); + void setComboxFieldDataList(const QStringList& list); + void setComboxTableDataList(const QStringList& list); + void setTableModeData(const ViewData &tableData); + void buttonClicked(); +private Q_SLOTS: + + void onAcceptOk(); + void onCancel(); + //compute slots + void onAddCompute(); + void onSubtractCompute(); + void onMultipyCompute(); + void onDivideCompute(); + // fun + void onAppend(); + void onUndo(); + void onCellPressed(int row, int column); +Q_SIGNALS: + void valueChanged(const QString &value); + void tableChanged(const QString &tableName); +private: + void initUI(); + void showFormulaDlg(); + void bindTableData(); + void setComboxFieldDataList(); + void setComboxTableDataList(); + void initConnect(); + QString buildTableFormulaRow(const QString &computeFlag=""); + bool isAppendValidate(const QString &rowItem); + void appendComputeSymbol(QPushButton *button); + QString combinationFormual(); + void bindCellFormula(); + +private: + QString m_formula; + QLabel *m_label; + QToolButton *m_button; + QComboBox *m_tableCombox,*m_fieldCombox; + + QTableWidget *m_tableView; + QListWidget *m_listWidget; + QSpinBox *m_smallBox; + QPushButton *btnAccpted,*btnCancel,*btnAddCompute,*btnSubtractCompute, + *btnMultiplyCompute,*btnDivideCompute,*btnAppend,*btnUndo; + QLabel *m_lable1; + QLineEdit *editline; + QLabel*NoLabel; + QLineEdit *Noline; + QDialog *formulaDialog; + QLabel *lblTable,*lblField,*lblSmall; + QList m_computeSymbol; +}; + + +QT_END_NAMESPACE +#endif diff --git a/qtpropertybrowser/qtpropertybrowser.pro b/qtpropertybrowser/qtpropertybrowser.pro index 9cce253..3edebfa 100644 --- a/qtpropertybrowser/qtpropertybrowser.pro +++ b/qtpropertybrowser/qtpropertybrowser.pro @@ -43,6 +43,7 @@ SOURCES += $$PWD/qtpropertybrowser.cpp \ $$PWD/qtpropertybrowserutils.cpp \ ColorSchemeComboBox.cpp \ Gradient.cpp \ + QtFormulaDialogfactory.cpp \ qtColorSchemeComboBox.cpp \ qtComboBox.cpp @@ -56,6 +57,7 @@ HEADERS += $$PWD/qtpropertybrowser.h \ $$PWD/qtpropertybrowserutils_p.h \ ColorSchemeComboBox.h \ Gradient.h \ + QtFormulaDialogfactory.h \ qtColorSchemeComboBox.h \ qtComboBox.h