From 506cecf05cc2b2dabdf7708d9a50d384ce5c8204 Mon Sep 17 00:00:00 2001 From: "DESKTOP-450PEFP\\mainc" Date: Wed, 4 Feb 2026 12:16:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E5=B7=A6=E4=BE=A7?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=89=B2=E6=9D=BF=E5=B1=9E=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=EF=BC=8C=E6=98=BE=E7=A4=BA=E8=89=B2=E6=9D=BF?= =?UTF-8?q?=E5=88=97=E8=A1=A8=20=E4=BF=AE=E6=94=B9=E6=B3=A2=E5=88=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=88=E6=9E=9C=EF=BC=8C=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E5=AF=B9=E5=BA=94=E6=97=A7=E7=89=88logplus?= =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E6=B3=A2=E5=BD=A2=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=B7=A6=E5=88=BB?= =?UTF-8?q?=E5=BA=A6=EF=BC=8C=E5=8F=B3=E5=88=BB=E5=BA=A6=EF=BC=8C=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=90=8D=E7=A7=B0=EF=BC=8C=E6=98=BE=E7=A4=BA=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E5=AD=97=E4=BD=93=E5=B1=9E=E6=80=A7=EF=BC=8C=E8=89=B2?= =?UTF-8?q?=E6=9D=BF=EF=BC=8C=E5=8F=98=E5=AF=86=E5=BA=A6=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E7=BA=A7=E6=95=B0=E7=AD=89=E5=B1=9E=E6=80=A7=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=B3=A2=E5=BD=A2=E5=B1=9E=E6=80=A7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AE=8C=E5=90=8E=E4=BF=9D=E5=AD=98=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=BF=9D=E5=AD=98=E7=9A=84=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PropertyWidget.cpp | 64 ++- logPlus/PropertyWidget.h | 6 +- logPlus/formdraw.cpp | 106 ++-- logPlus/formdraw.h | 3 +- logPlus/forminfo.cpp | 150 ++++-- logPlus/forminfo.h | 7 +- logPlus/formtrack.cpp | 98 ++-- logPlus/formtrack.h | 2 +- logPlus/formwell.cpp | 11 +- logPlus/qmycustomplot.cpp | 43 +- logPlus/qmycustomplot.h | 5 + qtpropertybrowser/ColorSchemeComboBox.cpp | 442 +++++++++++++++ qtpropertybrowser/ColorSchemeComboBox.h | 117 ++++ qtpropertybrowser/qtColorSchemeComboBox.cpp | 560 ++++++++++++++++++++ qtpropertybrowser/qtColorSchemeComboBox.h | 233 ++++++++ qtpropertybrowser/qtComboBox.cpp | 530 ++++++++++++++++++ qtpropertybrowser/qtComboBox.h | 115 ++++ qtpropertybrowser/qteditorfactory.cpp | 58 -- qtpropertybrowser/qteditorfactory.h | 59 +++ qtpropertybrowser/qtpropertybrowser.pro | 18 +- 20 files changed, 2412 insertions(+), 215 deletions(-) create mode 100644 qtpropertybrowser/ColorSchemeComboBox.cpp create mode 100644 qtpropertybrowser/ColorSchemeComboBox.h create mode 100644 qtpropertybrowser/qtColorSchemeComboBox.cpp create mode 100644 qtpropertybrowser/qtColorSchemeComboBox.h create mode 100644 qtpropertybrowser/qtComboBox.cpp create mode 100644 qtpropertybrowser/qtComboBox.h diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index f0ef65c..3ffe682 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -29,6 +29,11 @@ PropertyWidget::PropertyWidget(const QString &title, QWidget *parent , Qt::Windo connect( m_pVariantManager,SIGNAL(valueChanged(QtProperty *, const QVariant &)), this,SLOT(SlotPropertyChanged(QtProperty *, const QVariant &)) ); + QtColorSchemeComboBoxFactory * colorSchemeComboBoxFactory = new QtColorSchemeComboBoxFactory(); + m_pColorSchemeManager = new QtColorSchemeComboBoxPropertyManager(); + m_pPropertyBrowser->setFactoryForManager(m_pColorSchemeManager, colorSchemeComboBoxFactory); + connect(m_pColorSchemeManager, SIGNAL(valueChanged(QtProperty *, const int &, bool)), this, + SLOT(SlotPropertyChanged(QtProperty *, const int &, bool))); } PropertyWidget::~PropertyWidget() @@ -123,7 +128,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant bool bDraw = false; QStringList slist; slist << "显示名称" << "显示单位" << "曲线名称" << "曲线单位" << "曲线刻度" - << "左刻度" << "右刻度" << "幅度刻度" << "最大振幅" << "显示刻度"; + << "方式" << "左刻度" << "右刻度" << "幅度刻度" << "最大振幅" << "显示刻度" << "色板" << "变密度颜色级数"; for (int i = 0; i < slist.length(); i++) { if (slist.at(i) == m_propertyData[pProperty]) @@ -542,6 +547,26 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } } +void PropertyWidget::SlotPropertyChanged(QtProperty *property, const int &val, bool islinestyle) +{ + QString str = m_propertyData[property]; + if (m_strCurrentProperty == Wave_Property) + { + m_formInfo->setInfoProperty(str, val); + + QVariantList listCond; + listCond << m_strUuid; + listCond << m_strSlfName; + listCond << m_strWellName; + listCond << m_strTrackName; + listCond << m_strLineName; + listCond << str; + listCond << val; + emit CallManage::getInstance()->sig_changeDrawProperty(listCond); + } + return; +} + void PropertyWidget::ChangHeadItemProperty() { //清空 @@ -801,6 +826,37 @@ void PropertyWidget::_CreateEnumPropertyItem(QString strGroup, QString strProper } +void PropertyWidget::_CreateColorSchemePropertyItem(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 *colorSchemeProperty = m_pColorSchemeManager->addProperty(strPropertyCaption); + m_pColorSchemeManager->setLinear(colorSchemeProperty); + if (colorSchemeProperty) + { + m_propertyData[colorSchemeProperty] = strPropertyCaption; + pGroupItem->addSubProperty(colorSchemeProperty); + m_pColorSchemeManager->setValue(colorSchemeProperty, vtPropertyValue.toInt(), false); + //if (pMetaProperty) + //{ + // m_mapProperty[colorSchemeProperty] = pMetaProperty; + //} + } +} + void PropertyWidget::initWidgetProperty(QString strUuid, int iScale) { //初始化,清空 @@ -1135,7 +1191,7 @@ void PropertyWidget::initWaveProperty(FormInfo *formInfo) fillType.append("全周"); fillType.append("正半周"); fillType.append("负半周"); - _CreateEnumPropertyItem("填充方式", "方式", fillType.indexOf(formInfo->m_strFillType), fillType); + _CreateEnumPropertyItem("填充方式", "方式", formInfo->m_strFillType.toInt(), fillType); //_CreateVariantPropertyItem("波形绘制参数", "自动平滑", true, QVariant::Bool); _CreateVariantPropertyItem("波形绘制参数", "左刻度", formInfo->m_vmin, QVariant::Double); @@ -1156,8 +1212,8 @@ void PropertyWidget::initWaveProperty(FormInfo *formInfo) //_CreateVariantPropertyItem("成像显示", "是否深度校正", false, QVariant::Bool); //_CreateVariantPropertyItem("成像显示", "是否自动计算波参数", "", QVariant::String); -// _CreateVariantPropertyItem("调色板参数设置", "色板", false, QVariant::Bool); -// _CreateVariantPropertyItem("调色板参数设置", "变密度颜色级数", 256, QVariant::Int); + _CreateColorSchemePropertyItem("调色板参数设置", "色板", formInfo->m_nSchemeIndex); + _CreateVariantPropertyItem("调色板参数设置", "变密度颜色级数", formInfo->m_nColorNum, QVariant::Int); // _CreateVariantPropertyItem("调色板参数设置", "图例置顶", false, QVariant::Bool); // _CreateVariantPropertyItem("调色板参数设置", "反转显示", false, QVariant::Bool); diff --git a/logPlus/PropertyWidget.h b/logPlus/PropertyWidget.h index 7e9b3e9..2809d5e 100644 --- a/logPlus/PropertyWidget.h +++ b/logPlus/PropertyWidget.h @@ -14,6 +14,7 @@ //file #include "variantmanager.h" #include "variantfactory.h" +#include "ColorSchemeComboBox.h" // #include "forminfo.h" #include "formhead.h" @@ -46,6 +47,7 @@ public: private: QtTreePropertyBrowser *m_pPropertyBrowser; QtVariantPropertyManager *m_pVariantManager; + QtColorSchemeComboBoxPropertyManager * m_pColorSchemeManager; public: QString m_strUuid; @@ -90,6 +92,8 @@ public: void _CreateVariantPropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue, int propertyType, double dMin, double dMax); void _CreateEnumPropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue, QStringList listValue); + void _CreateColorSchemePropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue); + void InitCurrentViewInfo(); //初始化属性,清空 void initWidgetProperty(QString strUuid, int iScale); //可视解释整体属性 //井 @@ -115,7 +119,7 @@ public: public slots: void SlotPropertyChanged( QtProperty *property, const QVariant &variant ); - + void SlotPropertyChanged(QtProperty *property, const int &val, bool islinestyle); }; extern PropertyWidget* PropertyService(); diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index aebff72..ef9fb06 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -107,7 +107,7 @@ FormDraw::~FormDraw() delete ui; } -void FormDraw::setDrawData(QStringList listdt) +void FormDraw::setDrawData(QStringList listdt, QJsonObject objInfo) { QString strWellName = listdt.at(1); QString strSlfName = listdt.at(2); @@ -122,6 +122,9 @@ void FormDraw::setDrawData(QStringList listdt) return; } + //道-对象 + FormInfo* pInfo = m_formTrack->setDrawDt(listdt, objInfo); + // QMyCustomPlot *curv = new QMyCustomPlot(this, strSlfName, strWellName, m_strTrackName, strLineName); curv->m_strUuid = m_strUuid; @@ -141,11 +144,31 @@ void FormDraw::setDrawData(QStringList listdt) dHight = 32767; } curv->setGeometry(0, 0, nW, (int)dHight);//7500-3184 - curv->show(); + if ("waveObject" == strType) + { + int _nSamples = 0; + if (g_iSupport3D) + { + initWave_3D(curv, m_strSlfName, strLineName, _nSamples); + } + else + { + initWave(curv, m_strSlfName, strLineName, _nSamples); + } + curv->m_nMode = pInfo->getFillTypeIndex(); + //curv->m_fmin = pInfo->getVMin(); + //curv->m_fmax = pInfo->getVMax(); + curv->m_nColorNum = pInfo->m_nColorNum; + curv->m_nSchemeIndex = pInfo->m_nSchemeIndex; + curv->initColorTable(); + curv->updateWave(); + float f = 264 / pInfo->getVMax(); + curv->m_colorMap->data()->setValueRange(QCPRange(curv->m_fmin, curv->m_fmax*f)); + } // 深度 - if("depthObject" == strType) + else if("depthObject" == strType) { initDepth(curv); } @@ -179,8 +202,6 @@ void FormDraw::setDrawData(QStringList listdt) connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*))); - //道-对象 - m_formTrack->setDrawDt(listdt, m_vmax, m_vmin); // m_listLineName.push_back(strLineName); } @@ -368,40 +389,8 @@ void FormDraw::DisplayLine_One(QJsonObject lineObjInfo) // if (lineObjInfo.contains("lineColorRed")) { - QJsonValue value = lineObjInfo.value("lineColorRed"); - if (value.isDouble()) { - lineColor.setRed(value.toInt()); - //qDebug() << "lineColorRed:" << QString::number(value.toInt()); - } + lineColor.setNamedColor(lineObjInfo.value("lineColor").toString()); } - // - if (lineObjInfo.contains("lineColorGreen")) - { - QJsonValue value = lineObjInfo.value("lineColorGreen"); - if (value.isDouble()) { - lineColor.setGreen(value.toInt()); - //qDebug() << "lineColorGreen:" << QString::number(value.toInt()); - } - } - // - if (lineObjInfo.contains("lineColorBlue")) - { - QJsonValue value = lineObjInfo.value("lineColorBlue"); - if (value.isDouble()) { - lineColor.setBlue(value.toInt()); - //qDebug() << "lineColorBlue:" << QString::number(value.toInt()); - } - } - // - if (lineObjInfo.contains("lineColorAlpha")) - { - QJsonValue value = lineObjInfo.value("lineColorAlpha"); - if (value.isDouble()) { - lineColor.setAlpha(value.toInt()); - //qDebug() << "lineColorAlpha:" << QString::number(value.toInt()); - } - } - QString folderPath = GetLogdataPath(); folderPath = folderPath + g_prjname; @@ -599,21 +588,21 @@ void FormDraw::DisplayType_One(QJsonObject objInfo) { QString strType = objInfo.value("Type").toString(); QString strLineName = objInfo.value("LineName").toString(); - if (strType == "waveObject") - { - //新建波列 - emit CallManage::getInstance()->sig_AddWave(m_strUuid, m_strSlfName, m_strWellName, m_strTrackName, strLineName); - } - else + //if (strType == "waveObject") + //{ + // //新建波列 + // //emit CallManage::getInstance()->sig_AddWave(m_strUuid, m_strSlfName, m_strWellName, m_strTrackName, strLineName); + //} + //else { QStringList dt; dt << m_strUuid; dt << m_strWellName; dt << m_strSlfName; - dt << ""; + dt << strLineName; dt << strType; dt << QString::number(m_nTrackW); - this->setDrawData(dt); + this->setDrawData(dt, objInfo); } } @@ -828,6 +817,7 @@ void FormDraw::s_addWave(QString strUuid, QString strSlfName, QString strWellNam initWave(curv, strSlfName, strWaveName, _nSamples); } + curv->initColorTable(); connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*))); // @@ -2672,18 +2662,18 @@ void FormDraw::initWave(QMyCustomPlot *widget, QString strSlfName, QString strWa //colorMap->setGradient(QCPColorGradient::gpPolar);//gpJet); // 我们还可以创建一个QCPColorGradient实例并向其中添加自己的颜色 // 渐变,请参阅QCPColorGradient的文档以获取可能的效果. - int nIndex = 11; - QVector colorList; - bool inpolation = true; - int iColorNum = getSystemColor(nIndex, colorList, inpolation); - // - QCPColorGradient gradient; - for (int i = 0; i < iColorNum; i++) - { - double dbTmpIndex = (double)(i + 1) / iColorNum; - gradient.setColorStopAt(dbTmpIndex, colorList[i].color); // x% 位置的颜色 - } - colorMap->setGradient(gradient); + //int nIndex = 11; + //QVector colorList; + //bool inpolation = true; + //int iColorNum = getSystemColor(nIndex, colorList, inpolation); + //// + //QCPColorGradient gradient; + //for (int i = 0; i < iColorNum; i++) + //{ + // double dbTmpIndex = (double)(i + 1) / iColorNum; + // gradient.setColorStopAt(dbTmpIndex, colorList[i].color); // x% 位置的颜色 + //} + //colorMap->setGradient(gradient); // 重新缩放数据维度(颜色),以使所有数据点都位于颜色渐变显示的范围内: colorMap->rescaleDataRange(); diff --git a/logPlus/formdraw.h b/logPlus/formdraw.h index 080f6e7..81ae41f 100644 --- a/logPlus/formdraw.h +++ b/logPlus/formdraw.h @@ -49,7 +49,7 @@ public: explicit FormDraw(QWidget *parent = nullptr, QString m_strWellName="", QString strTrackName=""); ~FormDraw(); - void setDrawData(QStringList slist); + void setDrawData(QStringList slist, QJsonObject objInfo); void setDrawPropert(QJsonObject obj); @@ -212,7 +212,6 @@ public: signals: //void sig_AddLine(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName); - public slots: void s_addLine(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName); void s_AddLine_Property(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, diff --git a/logPlus/forminfo.cpp b/logPlus/forminfo.cpp index aaed0bc..0b2d388 100644 --- a/logPlus/forminfo.cpp +++ b/logPlus/forminfo.cpp @@ -7,6 +7,7 @@ #include #include #include "geometryutils.h" +#include "qtColorSchemeComboBox.h" //曲线名称(单个) FormInfo::FormInfo(QWidget *parent, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor) : @@ -72,6 +73,24 @@ FormInfo::~FormInfo() delete ui; } +void FormInfo::initProperty(QJsonObject obj) +{ + m_vmin = obj.value("vmin").toDouble(); + m_vmax = obj.value("vmax").toDouble(); + m_strUnit = obj.value("Unit").toString(); + + QString strType = obj.value("Type").toString(); + if ("waveObject" == strType) + { + m_strDrawType = obj.value("DrawType").toString(); + m_strFillType = obj.value("FillType").toString(); + m_strAmp = obj.value("Amp").toString(); + m_fMaxAmp = obj.value("MaxAmp").toDouble(); + m_nSchemeIndex = obj.value("SchemeIndex").toInt(); + m_nColorNum = obj.value("ColorNum").toInt(); + } +} + QJsonObject FormInfo::makeJson() { // 创建根对象 @@ -88,39 +107,53 @@ QJsonObject FormInfo::makeJson() rootObj["WellName"] = m_strWellName; // rootObj["TrackName"] = m_strTrackName; rootObj["LineName"] = m_strLineName; + rootObj["AliasName"] = m_strAliasName; + rootObj["Unit"] = m_strUnit; rootObj["Type"] = m_strType; - rootObj["lineColorRed"] = m_lineColor.red(); - rootObj["lineColorGreen"] = m_lineColor.green(); - rootObj["lineColorBlue"] = m_lineColor.blue(); - rootObj["lineColorAlpha"] = m_lineColor.alpha(); + rootObj["lineColor"] = m_lineColor.name(); rootObj["Width"] = m_dWidth; rootObj["lineStyle"] = m_lineStyle; rootObj["vmax"] = m_vmax; rootObj["vmin"] = m_vmin; rootObj["ScaleType"] = m_strScaleType; - //岩性填充 - rootObj["newFillMode"] = m_newFillMode; - rootObj["newHeadFill"] = m_newHeadFill; - rootObj["newTargetLine"] = m_newTargetLine; - rootObj["newFillType"] = m_newFillType; - //填充颜色 - rootObj["newColorRed"] = m_newColor.red(); - rootObj["newColorGreen"] = m_newColor.green(); - rootObj["newColorBlue"] = m_newColor.blue(); - rootObj["newColorAlpha"] = m_newColor.alpha(); - rootObj["newLithosImage"] = m_newLithosImage; - rootObj["new_vMax"] = m_new_vMax; - rootObj["new_vMin"] = m_new_vMin; - //岩性前景色 - rootObj["frontColorRed"] = m_frontColor.red(); - rootObj["frontColorGreen"] = m_frontColor.green(); - rootObj["frontColorBlue"] = m_frontColor.blue(); - rootObj["frontColorAlpha"] = m_frontColor.alpha(); - //岩性背景色 - rootObj["backColorRed"] = m_backColor.red(); - rootObj["backColorGreen"] = m_backColor.green(); - rootObj["backColorBlue"] = m_backColor.blue(); - rootObj["backColorAlpha"] = m_backColor.alpha(); + rootObj["ShowScale"] = m_bShowScale; + + if (m_strType == "curveObject") + { + //岩性填充 + rootObj["newFillMode"] = m_newFillMode; + rootObj["newHeadFill"] = m_newHeadFill; + rootObj["newTargetLine"] = m_newTargetLine; + rootObj["newFillType"] = m_newFillType; + //填充颜色 + rootObj["newColorRed"] = m_newColor.red(); + rootObj["newColorGreen"] = m_newColor.green(); + rootObj["newColorBlue"] = m_newColor.blue(); + rootObj["newColorAlpha"] = m_newColor.alpha(); + rootObj["newLithosImage"] = m_newLithosImage; + rootObj["new_vMax"] = m_new_vMax; + rootObj["new_vMin"] = m_new_vMin; + //岩性前景色 + rootObj["frontColorRed"] = m_frontColor.red(); + rootObj["frontColorGreen"] = m_frontColor.green(); + rootObj["frontColorBlue"] = m_frontColor.blue(); + rootObj["frontColorAlpha"] = m_frontColor.alpha(); + //岩性背景色 + rootObj["backColorRed"] = m_backColor.red(); + rootObj["backColorGreen"] = m_backColor.green(); + rootObj["backColorBlue"] = m_backColor.blue(); + rootObj["backColorAlpha"] = m_backColor.alpha(); + } + else if (m_strType == "waveObject") + { + rootObj["DrawType"] = m_strDrawType; + rootObj["FillType"] = m_strFillType; + rootObj["Amp"] = m_strAmp; + rootObj["MaxAmp"] = m_fMaxAmp; + + rootObj["SchemeIndex"] = m_nSchemeIndex; + rootObj["ColorNum"] = m_nColorNum; + } return rootObj; } @@ -260,26 +293,27 @@ void FormInfo::paintEvent(QPaintEvent* event) if(m_strType=="waveObject") { - //波列 - int nIndex=11; - QVector colorList; - bool inpolation = true; - int iColorNum = 256; - int iColorNum_tmp = getSystemColor(nIndex, colorList, inpolation); - colorList=myInpolation(colorList,256);//重新扩展调色板 - //头部绘制调色板 - float scale = (float)(rect.width()-4) / (float)iColorNum; - QRectF rt7=QRectF(rect.left()+2, rect.top()+rect.height()/3, rect.width()-4, rect.height()/3); - for (int i= 0; iSetCurrentSchemeIndex(m_nSchemeIndex); + //ColorTableIndex = ind; + + QtColorTableData::getInstance()->ChangeColorNum(m_nColorNum); + QList rgbList = QtColorTableData::getInstance()->GetRgb(); + int iColorNum = rgbList.size(); + + //头部绘制调色板 + float scale = (float)(rect.width() - 4) / (float)iColorNum; + QRectF rt7 = QRectF(rect.left() + 2, rect.top() + rect.height() / 3, rect.width() - 4, rect.height() / 3); + for (int i = 0; i < iColorNum; i++) + { + QColor acolor = rgbList.at(i); + float temp = (float)i * scale; + if (i)rt7.setLeft(rect.left() + 2 + temp); + else rt7.setLeft(rect.left() + 2 + temp + 1); + temp = (float)(i + 1) * scale; + rt7.setRight(rect.left() + 2 + temp); + QBrush HeadBrush = QBrush(acolor); + painter.fillRect(rt7, HeadBrush); + } } painter.setFont(m_curveUnitFont); @@ -519,7 +553,7 @@ bool FormInfo::setInfoProperty(QString strProName, QVariant val) bool bDraw = false; if ("显示名称" == strProName) { - this->m_strLineName = val.toString(); + this->m_strAliasName = val.toString(); } else if ("显示单位" == strProName) { @@ -537,6 +571,11 @@ bool FormInfo::setInfoProperty(QString strProName, QVariant val) { this->m_curveScaleFont = val.value(); } + else if ("方式" == strProName) + { + bDraw = true; + this->m_strFillType = val.toString(); + } else if ("左刻度" == strProName) { bDraw = true; @@ -559,10 +598,25 @@ bool FormInfo::setInfoProperty(QString strProName, QVariant val) { this->m_bShowScale = val.toBool(); } + else if ("色板" == strProName) + { + this->m_nSchemeIndex = val.toInt(); + return true; + } + else if ("变密度颜色级数" == strProName) + { + this->m_nColorNum = val.toInt(); + return true; + } this->update(); return bDraw; } +int FormInfo::getFillTypeIndex() +{ + return m_strFillType.toInt(); +} + //修改曲线选择状态 iSelect=0未知,1标准曲线,2主曲线,3从曲线 void FormInfo::s_ChangeLineStatus(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, int iSelect, bool bMerge) { diff --git a/logPlus/forminfo.h b/logPlus/forminfo.h index 5017fd9..5a10261 100644 --- a/logPlus/forminfo.h +++ b/logPlus/forminfo.h @@ -23,6 +23,7 @@ public: explicit FormInfo(QWidget *parent = nullptr, QString strSlfName="", QString strWellName="", QString strTrackName="", QString strLineName="", QColor lineColor=QColor(255,0,0)); ~FormInfo(); + void initProperty(QJsonObject obj); private: Ui::FormInfo *ui; @@ -97,13 +98,15 @@ public: int m_nJg; - QString m_strDrawType; // 绘图类型 QString m_strFillType; // 填充类型 QString m_strAmp; // 幅度刻度 float m_fMaxAmp; // 最大振幅 bool m_bShowScale; // 显示刻度 + int m_nColorNum = 256; // 调色板参数设置-变密度颜色级数 + int m_nSchemeIndex = 1; // 调色板参数设置-色板 + public: void setLineWidth(double dWidth); double getLineWidth(); @@ -125,6 +128,8 @@ public: bool setInfoProperty(QString strProName, QVariant val); + int getFillTypeIndex(); + QJsonObject makeJson(); //public: diff --git a/logPlus/formtrack.cpp b/logPlus/formtrack.cpp index 3c8ea6a..9ec8b7f 100644 --- a/logPlus/formtrack.cpp +++ b/logPlus/formtrack.cpp @@ -130,6 +130,38 @@ FormTrack::~FormTrack() { delete ui; } +// +// void FormTrack::setTrackPropert(QJsonObject trackObj) +// { +// if (!trackObj.contains("formInfos")) +// return; +// +// QJsonValue value = trackObj.value("formInfos"); +// if (!value.isArray()) +// return; +// +// QJsonArray linesArray = value.toArray(); +// +// int iCount = linesArray.size(); +// ui->tableWidget->setRowCount(iCount); +// for (int i = 0; i < iCount; i++) +// { +// //按照id顺序,展示曲线 +// QJsonValue lineValue = linesArray[i]; +// QJsonObject lineObj = lineValue.toObject(); +// QString strSlfName = lineObj.value("SlfName").toString(); +// QString strLineName = lineObj.value("LineName").toString(); +// QColor lineColor; +// lineColor.setNamedColor(lineObj.value("lineColor").toString()); +// FormInfo *formInfo = new FormInfo(this, strSlfName, m_strWellName, m_strTrackName, strLineName, lineColor); +// formInfo->m_strUuid = m_strUuid; +// formInfo->initProperty(lineObj); +// +// ui->tableWidget->setRowHeight(i, 100); +// ui->tableWidget->setCellWidget(i, 0, formInfo); +// +// } +// } void FormTrack::Add(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QString strAliasName, QString strUnit, QColor lineColor, double dWidth, float vmax, float vmin, QString strScaleType, QString strType) { @@ -202,7 +234,7 @@ void FormTrack::Add(QString strSlfName, QString strWellName, QString strTrackNam } } -void FormTrack::setDrawDt(QStringList listdt, float vmax, float vmin) +FormInfo* FormTrack::setDrawDt(QStringList listdt, QJsonObject obj) { QString strWellName = listdt.at(1); QString strSlfName = listdt.at(2); @@ -214,55 +246,56 @@ void FormTrack::setDrawDt(QStringList listdt, float vmax, float vmin) int row = ui->tableWidget->rowCount(); ui->tableWidget->setRowCount(row + 1); - //避免出现小滚动条 - //ui->tableWidget->resize(g_iOneWidth, 100*(row + 1)+10); - //this->resize(g_iOneWidth, 100*(row + 1)+30); + QString strAliasName = ""; + if (obj.contains("AliasName")) + { + strAliasName = obj.value("AliasName").toString(); + } + else + { + if ("depthObject" == strType) + { + strAliasName = "深度"; + } + else if ("plObject" == strType) + { + strAliasName = "频率统计图"; + } + else if ("roseObject" == strType) + { + strAliasName = "玫瑰图"; + } + else if ("dcaObject" == strType) + { + strAliasName = "裂缝检测"; + } + else if ("tdtObject" == strType) + { + strAliasName = "TDT"; + } + } - QString strAliasName = "深度"; - if("depthObject" == strType) - { - strAliasName = "深度"; - } - else if("plObject" == strType) - { - strAliasName = "频率统计图"; - } - else if("roseObject" == strType) - { - strAliasName = "玫瑰图"; - } - else if("dcaObject" == strType) - { - strAliasName = "裂缝检测"; - } - else if("tdtObject" == strType) - { - strAliasName = "TDT"; - } - QString strUnit = ""; QColor lineColor=QColor(0,0,0); double width=2; QString strScaleType = ""; //曲线信息栏 FormInfo *formInfo = new FormInfo(this, strSlfName, strWellName, m_strTrackName, strLineName, lineColor); + formInfo->initProperty(obj); formInfo->m_strUuid = m_strUuid; formInfo->m_strAliasName = strAliasName; - formInfo->m_strUnit = strUnit; formInfo->m_strScaleType = strScaleType; formInfo->m_strType = strType; formInfo->m_nJg = 2; formInfo->setLineWidth(width); - formInfo->setVMax(vmax); - formInfo->setVMin(vmin); - formInfo->setFrontColor(QColor(0,0,0)); - formInfo->setBackColor(QColor(255,255,255)); //设置高度 ui->tableWidget->setRowHeight(row, 100); //单元格委托 //ui->tableWidget->setItemDelegateForRow(row, m_delegate); // ui->tableWidget->setCellWidget(row, 0, formInfo); + + return formInfo; } void FormTrack::s_addLine(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QString strAliasName, QString strUnit, QColor lineColor, double dWidth, float vmax, float vmin, QString strScaleType) @@ -886,8 +919,7 @@ QJsonObject FormTrack::makeJson() if( ui->tableWidget->cellWidget(i, 0) != nullptr ) { auto myWidget = ui->tableWidget->cellWidget(i, 0); - // - FormInfo *formInfo = (FormInfo*)myWidget;//获得widget + FormInfo *formInfo = qobject_cast(myWidget);//获得widget if(formInfo) { //options diff --git a/logPlus/formtrack.h b/logPlus/formtrack.h index e3860bc..99790aa 100644 --- a/logPlus/formtrack.h +++ b/logPlus/formtrack.h @@ -62,7 +62,7 @@ public: public: void Add(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QString strAliasName, QString strUnit, QColor lineColor, double dWidth, float vmax, float vmin, QString strScaleType, QString strType); - void setDrawDt(QStringList listdt, float vmax, float vmin); + FormInfo* setDrawDt(QStringList listdt, QJsonObject obj); QJsonObject makeJson(); QStringList getLineList(QString strWellName, QString strTrackName); diff --git a/logPlus/formwell.cpp b/logPlus/formwell.cpp index 73de773..893352c 100644 --- a/logPlus/formwell.cpp +++ b/logPlus/formwell.cpp @@ -1,6 +1,7 @@ #include "formwell.h" #include "ui_formwell.h" #include "CallManage.h" +#include "qtColorSchemeComboBox.h" extern int g_iOneWidth; //道宽 //extern int m_iY1; @@ -36,6 +37,8 @@ FormWell::FormWell(QWidget *parent, QString strWellName) : connect(CallManage::getInstance(), SIGNAL(sig_Raise(QString, QString, QString, QString, QString, int, QString)), this, SLOT(s_Raise(QString, QString, QString, QString, QString, int, QString))); connect(CallManage::getInstance(), SIGNAL(sig_NewCol(QStringList)), this, SLOT(s_NewCol(QStringList))); + + QtColorTableData::getInstance()->LoadScheme(); } FormWell::~FormWell() @@ -334,6 +337,11 @@ void FormWell::slot_NewTrack_No_Line(QString strUuid, QJsonObject topObj, QJsonO { formTop->setTrackTopPropert(topObj); } +// FormTrack *formTrack = qobject_cast(vecWgt.at(1)); +// if (formTrack) +// { +// formTrack->setTrackPropert(infoObj); +// } FormDraw *formDraw = qobject_cast(vecWgt.at(2)); if (formDraw) { @@ -421,7 +429,8 @@ void FormWell::s_NewCol(QStringList listdt) FormDraw *formDraw = qobject_cast(vecWgt.at(2)); if(formDraw == nullptr) return; - formDraw->setDrawData(listdt); + QJsonObject obj; + formDraw->setDrawData(listdt, obj); } diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index bbc7b83..b387cbb 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -96,6 +96,38 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel connect(CallManage::getInstance(), SIGNAL(sig_changeDrawProperty(QVariantList)), this, SLOT(s_changeDrawProperty(QVariantList))); } +void QMyCustomPlot::initColorTable() +{ + this->setSchemeIndex(m_nSchemeIndex, m_nColorNum); +} + +void QMyCustomPlot::setSchemeIndex(int nidx, int colorNum) +{ + if (m_colorMap == NULL) + return; + + m_nSchemeIndex = nidx; + m_nColorNum = colorNum; + + QtColorTableData::getInstance()->SetCurrentSchemeIndex(nidx); + //ColorTableIndex = ind; + + QtColorTableData::getInstance()->ChangeColorNum(colorNum); + QList rgbList = QtColorTableData::getInstance()->GetRgb(); + + int iColorNum = rgbList.size(); + QCPColorGradient gradient; + for (int i = 0; i < iColorNum; i++) + { + QColor acolor = rgbList.at(i); + double dbTmpIndex = (double)(i) / iColorNum; + gradient.setColorStopAt(dbTmpIndex, acolor); // x% 位置的颜色 + //mWaveMes.m_ColorMessage.Color[i] = acolor; + } + + m_colorMap->setGradient(gradient); +} + double** QMyCustomPlot::getWavedata(int nrow, int ncol) { if (nrow > 0 && m_wavedata) @@ -833,7 +865,6 @@ void QMyCustomPlot::s_changeDrawProperty(QVariantList vlist) { m_nMode = strValue.toFloat(); this->updateWave(); - this->replot(); } else if ("左刻度" == strProperty) { @@ -845,9 +876,17 @@ void QMyCustomPlot::s_changeDrawProperty(QVariantList vlist) { float f = 264 / strValue.toFloat(); m_colorMap->data()->setValueRange(QCPRange(m_fmin, m_fmax*f)); - this->replot(); } } + else if ("色板" == strProperty) + { + this->setSchemeIndex(strValue.toInt(), m_nColorNum); + } + else if ("变密度颜色级数" == strProperty) + { + this->setSchemeIndex(m_nSchemeIndex, strValue.toInt()); + } + this->replot(); } } diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index c574a71..eec8213 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -5,6 +5,7 @@ #include "LogIO.h" //#include "TransparentDraggableRect.h" #include "QCPSizeHandleManager.h" +#include "qtColorSchemeComboBox.h" #pragma execution_character_set("utf-8") @@ -20,6 +21,8 @@ public: { } + void initColorTable(); + void setSchemeIndex(int nidx, int colorNum); double** getWavedata(int nrow, int ncol); QCPColorMap * updateWave(); protected: @@ -72,6 +75,8 @@ public: int m_nMode = 1; float m_fmin; float m_fmax; + int m_nColorNum = 256; + int m_nSchemeIndex = 1; public: //分段刷新 QVector m_x; diff --git a/qtpropertybrowser/ColorSchemeComboBox.cpp b/qtpropertybrowser/ColorSchemeComboBox.cpp new file mode 100644 index 0000000..f2e099d --- /dev/null +++ b/qtpropertybrowser/ColorSchemeComboBox.cpp @@ -0,0 +1,442 @@ + +#include +// #include +#include +#include +#include +#include "ColorSchemeComboBox.h" +#include "QtColorSchemeComboBox.h" +// #include "QtColorTableData.h" +template +static Value getData(const QMap &propertyMap, + Value PrivateData::*data, + const QtProperty *property, const Value &defaultValue = Value()) +{ + typedef QMap PropertyToData; + typedef 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); +} + +QtColorSchemeComboBoxFactory::QtColorSchemeComboBoxFactory(QObject *parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtColorSchemeComboBoxFactoryPrivate()) +{ + d_ptr->q_ptr = this; + +} + +/*! + Destroys this factory, and all the widgets it has created. +*/ +QtColorSchemeComboBoxFactory::~QtColorSchemeComboBoxFactory() +{ + qDeleteAll(d_ptr->m_editorToProperty.keys()); +} + +/*! + \internal + + Reimplemented from the QtAbstractEditorFactory class. +*/ +void QtColorSchemeComboBoxFactory::connectPropertyManager(QtColorSchemeComboBoxPropertyManager *manager) +{ + connect(manager, SIGNAL(valueChanged(QtProperty*,int,bool)), + this, SLOT(slotPropertyChanged(QtProperty*,int,bool))); + connect(manager, SIGNAL(enumNamesChanged(QtProperty*,QStringList)), + this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList))); +} + +// void QtColorSchemeComboBoxFactory::rendererLinearEnum(QComboBox *editor) +// { +// for (int ls = Qt::SolidLine; ls < Qt::CustomDashLine; ls++) +// { +// for(int lw = Qt::SolidLine; lw < Qt::CustomDashLine; lw++){ +// QSize rectSize(200,15); +// QPixmap pix(rectSize); +// pix.fill(Qt::white); +// +// QBrush brush(Qt::black); +// QPen pen(brush,(Qt::PenStyle)lw,(Qt::PenStyle)ls); +// QPainter painter(&pix); +// painter.setPen(pen); +// painter.drawLine(2,7,500,7); +// editor->setIconSize(rectSize); +// editor->addItem(QIcon(pix),""); +// +// } +// } +// } +/*! + \internal + + Reimplemented from the QtAbstractEditorFactory class. +*/ +QWidget *QtColorSchemeComboBoxFactory::createEditor(QtColorSchemeComboBoxPropertyManager *manager, QtProperty *property, + QWidget *parent) +{ + //QtColorSchemeComboBox * m_pColorSchemeBox = new QtColorSchemeComboBox(); + //return m_pColorSchemeBox; + QtColorSchemeComboBox * pColorSchemeCombox = d_ptr->createEditor(property,parent); + QtColorTableData colorMap("Color Scheme",true); + colorMap.SetCurrentSchemeIndex(manager->value(property)); + pColorSchemeCombox->setSchemeColor(colorMap.GetSchemeList()); + pColorSchemeCombox->setCurrentIndex(manager->value(property)); + + //QComboBox *editor = d_ptr->createEditor(property, parent); + //pColorSchemeCombox->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + //pColorSchemeCombox->view()->setTextElideMode(Qt::ElideRight); + QStringList enumNames = manager->enumNames(property); +// QSize rectSize(200,15); +// editor->setIconSize(rectSize); +// editor->addItems(enumNames); +// rendererLinearEnum(editor); +// + QMap enumIcons = manager->enumIcons(property); + const int enumNamesCount = enumNames.count(); + const int enumIconCount = enumIcons.count(); +// for (int i = 0; i < enumIconCount; i++) +// editor->setItemIcon(i, enumIcons.value(i)); +// editor->setCurrentIndex(manager->value(property)); +// + connect(pColorSchemeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetValue(int))); + connect(pColorSchemeCombox, SIGNAL(destroyed(QObject*)), + this, SLOT(slotEditorDestroyed(QObject*))); + return pColorSchemeCombox; +// return editor; +} + +/*! + \internal + + Reimplemented from the QtAbstractEditorFactory class. +*/ +void QtColorSchemeComboBoxFactory::disconnectPropertyManager(QtColorSchemeComboBoxPropertyManager *manager) +{ + disconnect(manager, SIGNAL(valueChanged(QtProperty*,int)), + this, SLOT(slotPropertyChanged(QtProperty*,int))); + disconnect(manager, SIGNAL(enumNamesChanged(QtProperty*,QStringList)), + this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList))); + +} + + +void QtColorSchemeComboBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) +{ + if (!m_createdEditors.contains(property)) + return; + + QListIterator itEditor(m_createdEditors[property]); + while (itEditor.hasNext()) { + QtColorSchemeComboBox *editor = itEditor.next(); + editor->blockSignals(true); + editor->setCurrentIndex(value); + editor->blockSignals(false); + } +} + +void QtColorSchemeComboBoxFactoryPrivate::slotEnumNamesChanged(QtProperty *property, + const QStringList &enumNames) +{ + if (!m_createdEditors.contains(property)) + return; + + QtColorSchemeComboBoxPropertyManager *manager = q_ptr->propertyManager(property); + if (!manager) + return; + + QMap enumIcons = manager->enumIcons(property); + + QListIterator itEditor(m_createdEditors[property]); + while (itEditor.hasNext()) { + QtColorSchemeComboBox *editor = itEditor.next(); + editor->blockSignals(true); + editor->clear(); + editor->addItems(enumNames); + const int nameCount = enumNames.count(); + for (int i = 0; i < nameCount; i++) + editor->setItemIcon(i, enumIcons.value(i)); + editor->setCurrentIndex(manager->value(property)); + editor->blockSignals(false); + } +} + +void QtColorSchemeComboBoxFactoryPrivate::slotEnumIconsChanged(QtProperty *property, + const QMap &enumIcons) +{ + if (!m_createdEditors.contains(property)) + return; + + QtColorSchemeComboBoxPropertyManager *manager = q_ptr->propertyManager(property); + if (!manager) + return; + + const QStringList enumNames = manager->enumNames(property); + QListIterator itEditor(m_createdEditors[property]); + while (itEditor.hasNext()) { + QtColorSchemeComboBox *editor = itEditor.next(); + + editor->blockSignals(true); + const int nameCount = enumNames.count(); + for (int i = 0; i < nameCount; i++) + editor->setItemIcon(i, enumIcons.value(i)); + editor->setCurrentIndex(manager->value(property)); + editor->blockSignals(false); + } +} + +void QtColorSchemeComboBoxFactoryPrivate::slotSetValue(int 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(); + QtColorSchemeComboBoxPropertyManager *manager = q_ptr->propertyManager(property); + if (!manager) + return; + manager->setValue(property, value,false); + return; + } +} + + + +QtColorSchemeComboBoxPropertyManager::QtColorSchemeComboBoxPropertyManager(QObject *parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtColorSchemeComboBoxPropertyManagerPrivate) +{ + d_ptr->q_ptr = this; +} + +/*! + Destroys this manager, and all the properties it has created. +*/ +QtColorSchemeComboBoxPropertyManager::~QtColorSchemeComboBoxPropertyManager() +{ + 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() +*/ +int QtColorSchemeComboBoxPropertyManager::value(const QtProperty *property) const +{ + return getValue(d_ptr->m_values, property, -1); +} + +/*! + Returns the given \a property's list of enum names. + + \sa value(), setEnumNames() +*/ +QStringList QtColorSchemeComboBoxPropertyManager::enumNames(const QtProperty *property) const +{ + return getData(d_ptr->m_values, &QtColorSchemeComboBoxPropertyManagerPrivate::Data::enumNames, property, QStringList()); +} + +/*! + Returns the given \a property's map of enum values to their icons. + + \sa value(), setEnumIcons() +*/ +QMap QtColorSchemeComboBoxPropertyManager::enumIcons(const QtProperty *property) const +{ + return getData >(d_ptr->m_values, &QtColorSchemeComboBoxPropertyManagerPrivate::Data::enumIcons, property, QMap()); +} + +/*! + \reimp +*/ +QString QtColorSchemeComboBoxPropertyManager::valueText(const QtProperty *property) const +{ + const QtColorSchemeComboBoxPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); + if (it == d_ptr->m_values.constEnd()) + return QString(); + + const QtColorSchemeComboBoxPropertyManagerPrivate::Data &data = it.value(); + + const int v = data.val; + if (v >= 0 && v < data.enumNames.count()) + return data.enumNames.at(v); + return QString(); +} + +bool QtColorSchemeComboBoxPropertyManager::IsColorScheme(const QtProperty *property) const +{ + return true; +} +/*! + \reimp +*/ +QIcon QtColorSchemeComboBoxPropertyManager::valueIcon(const QtProperty *property) const +{ + const QtColorSchemeComboBoxPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); + if (it == d_ptr->m_values.constEnd()) + return QIcon(); + + const QtColorSchemeComboBoxPropertyManagerPrivate::Data &data = it.value(); + + const int v = data.val; + return data.enumIcons.value(v); +} + +/*! + \fn void QtColorSchemeComboBoxPropertyManager::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 QtColorSchemeComboBoxPropertyManager::setValue(QtProperty *property, int val,bool islineStyle) +{ + const QtColorSchemeComboBoxPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); + if (it == d_ptr->m_values.end()) + return; + + QtColorSchemeComboBoxPropertyManagerPrivate::Data data = it.value(); + + if (val >= data.enumNames.count()) + return; + + if (val < 0 && data.enumNames.count() > 0) + return; + + if (val < 0) + val = -1; + + if (data.val == val) + return; + + data.val = val; + + it.value() = data; + emit propertyChanged(property); + emit valueChanged(property, val,islineStyle); + + +} + +/*! + 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() +*/ + +void QtColorSchemeComboBoxPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames) +{ + const QtColorSchemeComboBoxPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); + if (it == d_ptr->m_values.end()) + return; + + QtColorSchemeComboBoxPropertyManagerPrivate::Data data = it.value(); + + if (data.enumNames == enumNames) + return; + + data.enumNames = enumNames; + + data.val = -1; + + if (enumNames.count() > 0) + data.val = 0; + + it.value() = data; + + emit enumNamesChanged(property, data.enumNames); + + emit propertyChanged(property); + emit valueChanged(property, data.val,false); +} + +/*! + 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() +*/ +void QtColorSchemeComboBoxPropertyManager::setEnumIcons(QtProperty *property, const QMap &enumIcons) +{ + const QtColorSchemeComboBoxPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); + if (it == d_ptr->m_values.end()) + return; + + it.value().enumIcons = enumIcons; + + emit enumIconsChanged(property, it.value().enumIcons); + + emit propertyChanged(property); +} +void QtColorSchemeComboBoxPropertyManager::setLinear(QtProperty *property) +{ + QStringList enumNames; + QMap enumIcons; + + QtColorTableData colorMap("Color Scheme",true); + QList colorList = colorMap.GetSchemeList(); + + int nCount = colorList.size(); + //样式值 + ///QList linears; +// for(int index = 0; index < nCount; index++) +// { +// linears.push_back((Qt::PenStyle)(index)); +// } + + for(int i = 0 ; i < nCount; i++) + { + enumNames.push_back(QString::number(i)); + //colorMap. +// QPixmap pix(rectSize); +// pix.fill(Qt::white); +// QBrush brush(Qt::black); +// QPen pen(brush,2, linears.at(i)); +// QPainter painter(&pix); +// painter.setPen(pen); +// painter.drawLine(2,7,500,7); + //enumIcons[i] = QIcon(pix); + } + + setEnumNames(property, enumNames); + //setEnumIcons(property, enumIcons); + +} +/*! + \reimp +*/ +void QtColorSchemeComboBoxPropertyManager::initializeProperty(QtProperty *property) +{ + d_ptr->m_values[property] = QtColorSchemeComboBoxPropertyManagerPrivate::Data(); +} + +/*! + \reimp +*/ +void QtColorSchemeComboBoxPropertyManager::uninitializeProperty(QtProperty *property) +{ + d_ptr->m_values.remove(property); +} + diff --git a/qtpropertybrowser/ColorSchemeComboBox.h b/qtpropertybrowser/ColorSchemeComboBox.h new file mode 100644 index 0000000..b1c6016 --- /dev/null +++ b/qtpropertybrowser/ColorSchemeComboBox.h @@ -0,0 +1,117 @@ + +#ifndef COLORSCHEMACOMOBOX_H +#define COLORSCHEMACOMOBOX_H + +#include +#include +// #include +#include "qtpropertybrowser.h" +#include "qteditorfactory.h" +#include "QtColorSchemeComboBox.h" +//const QSize rectSize(200,15); +QT_BEGIN_NAMESPACE + +class QtColorSchemeComboBoxFactoryPrivate; +class QtColorSchemeComboBoxPropertyManagerPrivate; +class QTPROPERTYBROWSER_EXPORT QtColorSchemeComboBoxPropertyManager : public QtAbstractPropertyManager +{ + Q_OBJECT +public: + QtColorSchemeComboBoxPropertyManager(QObject *parent = 0); + ~QtColorSchemeComboBoxPropertyManager(); + + int value(const QtProperty *property) const; + QStringList enumNames(const QtProperty *property) const; + QMap enumIcons(const QtProperty *property) const; + + + public Q_SLOTS: + void setValue(QtProperty *property, int val, bool islinestyle); + void setEnumNames(QtProperty *property, const QStringList &names); + void setEnumIcons(QtProperty *property, const QMap &icons); + void setLinear(QtProperty *property); +Q_SIGNALS: + void valueChanged(QtProperty *property, int val,bool islineStyle); + void enumNamesChanged(QtProperty *property, const QStringList &names); + void enumIconsChanged(QtProperty *property, const QMap &icons); +protected: + QString valueText(const QtProperty *property) const; + QIcon valueIcon(const QtProperty *property) const; + bool IsColorScheme(const QtProperty *property) const; + virtual void initializeProperty(QtProperty *property); + virtual void uninitializeProperty(QtProperty *property); +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(QtColorSchemeComboBoxPropertyManager) + Q_DISABLE_COPY(QtColorSchemeComboBoxPropertyManager) +}; + + + +class QTPROPERTYBROWSER_EXPORT QtColorSchemeComboBoxPropertyManagerPrivate +{ + QtColorSchemeComboBoxPropertyManager *q_ptr; + Q_DECLARE_PUBLIC(QtColorSchemeComboBoxPropertyManager) +public: + + + struct Data + { + Data() : val(-1) {} + int val; + QStringList enumNames; + QMap enumIcons; + + }; + + typedef QMap PropertyValueMap; + PropertyValueMap m_values; + bool m_pIsColorScheme; +}; + + +class QtColorSchemeComboBoxFactoryPrivate; + +class QTPROPERTYBROWSER_EXPORT QtColorSchemeComboBoxFactory : public QtAbstractEditorFactory +{ + Q_OBJECT +public: + QtColorSchemeComboBoxFactory(QObject *parent = 0); + ~QtColorSchemeComboBoxFactory(); +protected: + void connectPropertyManager(QtColorSchemeComboBoxPropertyManager *manager); + QWidget *createEditor(QtColorSchemeComboBoxPropertyManager *manager, QtProperty *property, + QWidget *parent); + void disconnectPropertyManager(QtColorSchemeComboBoxPropertyManager *manager); + //void rendererLinearEnum(QComboBox *editor); +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(QtColorSchemeComboBoxFactory) + Q_DISABLE_COPY(QtColorSchemeComboBoxFactory) + Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) + Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty *, + const QStringList &)) + Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty *, + const QMap &)) + Q_PRIVATE_SLOT(d_func(), void slotSetValue(int)) + Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) + +}; + + + +class QTPROPERTYBROWSER_EXPORT QtColorSchemeComboBoxFactoryPrivate : public EditorFactoryPrivate +{ + QtColorSchemeComboBoxFactory *q_ptr; + Q_DECLARE_PUBLIC(QtColorSchemeComboBoxFactory) +public: + + void slotPropertyChanged(QtProperty *property, int value); + void slotEnumNamesChanged(QtProperty *property, const QStringList &); + void slotEnumIconsChanged(QtProperty *property, const QMap &); + void slotSetValue(int value); +}; +QT_END_NAMESPACE + +#endif + diff --git a/qtpropertybrowser/qtColorSchemeComboBox.cpp b/qtpropertybrowser/qtColorSchemeComboBox.cpp new file mode 100644 index 0000000..a9a52dd --- /dev/null +++ b/qtpropertybrowser/qtColorSchemeComboBox.cpp @@ -0,0 +1,560 @@ +/* + * QtColorSchemeComboBox.cpp + * + * Created on: 2013-5-27 + * Author: long + */ +#include +#include +#include +#include +#include +#include "qtColorSchemeComboBox.h" +QtColorSchemeComboBox::QtColorSchemeComboBox(QWidget *parent):QtComboBox(parent), m_isShowText(true) +{ + m_colorSchemeList.clear(); +} + +QtColorSchemeComboBox::~QtColorSchemeComboBox() +{ + freeColorScheme(); +} + +void QtColorSchemeComboBox::ShowText(bool showText) +{ + m_isShowText = showText; + if(m_isShowText) + { + setMinimumWidth(140); + } + else + { + setMinimumWidth(40); + setMaximumWidth(44); + } +} + +void QtColorSchemeComboBox::setSchemeColor(const QList &schemeList) +{ + freeColorScheme(); + + for(int i=0;i &colorList,int colorNumber) +{ + int w=64,h=32; + QPixmap pixmap(w,h); + QBrush brush(QColor(255,0,0)); + pixmap.fill(QColor(255,0,0)); + + //QVector newColorList=paiInpolation(colorList,colorNumber); + + + QPainter painter; + painter.begin(&pixmap); + float colorStep = colorNumber * 1. / w; + QPen Pen; + for (int x = 0; x < w; x++) + { + // 色标位置 + int clrIndex = (int) ((x) * colorStep); + if(colorList.size()<=x) break; + Pen.setColor(QColor(colorList[clrIndex].color)); + painter.setPen(Pen); + painter.drawLine(x, 0, x, h-1); + } + painter.end(); + return pixmap; +} + +void QtColorSchemeComboBox::freeColorScheme() +{ + m_colorSchemeList.clear(); +} + +QVector paiInpolation(const QVector &colorList,int totalColorNum) +{ + QVector newColorList; + + // 填充新的颜色项目 + for(int i=0;i=colorList.size()) index2=colorList.size()-1; + float flgap1=pos-index1; + float flgap2=index2-pos; + int r=colorList[index1].color.red()*flgap2+colorList[index2].color.red()*flgap1; + int g=colorList[index1].color.green()*flgap2+colorList[index2].color.green()*flgap1; + int b=colorList[index1].color.blue()*flgap2+colorList[index2].color.blue()*flgap1; + newColorList[i]=QtColorItem(QColor(r,g,b)); + + } + + } + return newColorList; +} +bool readColorPaletteSetting(QList &schemeList,const QString &orignaName,const QString &moduleName) +{ + schemeList.clear(); + // 读取颜色设置 + QString orgName=orignaName; + if(orgName.isEmpty()) + { + orgName=gOrignizationName; + } + + QString softName=moduleName; + if(softName.isEmpty()) + softName="General Color Schema"; + QSettings settings(orgName, softName); + QString aa=settings.fileName(); + + // 读取自定义的颜色方案 + QVariant v = settings.value(gSchemeNumKey); + int schemeNum=0; + if(!v.isValid()) + { + return false; + } + + schemeNum=v.toUInt(); + // 循环读取颜色方案 + + QVector colorLis; + for(int i=0;i(); + item.strComments=list[1].toString(); + colorLis.push_back(item); + } + + QtSchemeColor schemeItem; + schemeItem.schemeName=customName; + schemeItem.isCustom=true; + schemeItem.isDirty=false; + schemeItem.colorList=colorLis; + schemeItem.currentIndex=0; + schemeList.push_back(schemeItem); + settings.endGroup(); + } + + return true; +} + + + +int getPaiSystemColorNumber(QStringList &names) +{ + QString strImagePath; + QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator(); + strImagePath = QDir::toNativeSeparators( strPathTmp ); + QString filecfg=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+"colortable.cfg"; + FILE *fp1=fopen(filecfg.toStdString().c_str(),"rt"); + if(!fp1) return -1; + char buf[100]; + QString str; + int i=0; + while(!feof(fp1)) { + fscanf(fp1,"%s",buf); + str=buf; + if(str.indexOf("custom",Qt::CaseInsensitive)>=0) continue; + names.push_back(str); + i++; + } + fclose(fp1); + return i; +} +int getPaiSystemColor(int nIndex,QVector &colorList,bool inpolation) +{ + colorList.clear(); + QtColorItem itemColor; + QString strImagePath; + QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator(); + strImagePath = QDir::toNativeSeparators( strPathTmp ); + QString filecfg=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+"colortable.cfg"; + FILE *fp1=fopen(filecfg.toStdString().c_str(),"rt"); + if(!fp1) return -1; + char buf[100]; + QString str; + int i=0; + while(!feof(fp1)) { + fscanf(fp1,"%s",buf); + if(i>=nIndex) { + str=buf; + break; + } + i++; + } + fclose(fp1); + if(str.isEmpty()) return -1; + QString filename=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+str; + FILE *fp=fopen(filename.toStdString().c_str(),"rt"); + if(!fp) return -1; + float r,g,b; + QStringList strs; + int colornum=0; + while(!feof(fp)) { + char *ret=fgets(buf,100,fp); + if(!ret) break; + str=buf; + str.replace("\r",""); + str.replace("\n",""); + str.replace("\t"," "); + if(str.indexOf("#")>-1) continue; + if(str.indexOf("=")>-1) continue; + if(str.indexOf("R",Qt::CaseInsensitive)>-1) continue; + if(str.indexOf("G",Qt::CaseInsensitive)>-1) continue; + if(str.indexOf("B",Qt::CaseInsensitive)>-1) continue; + strs=str.split(" "); + strs.removeAll(""); + if(strs.size()!=3) continue; + r=strs[0].toFloat(); + g=strs[1].toFloat(); + b=strs[2].toFloat(); + if(g<=1||b<=1) if(r>0&&r<=1) r*=255; + if(r<=1||b<=1) if(g>0&&g<=1) g*=255; + if(r<=1||g<=1) if(b>0&&b<=1) b*=255; + int rr=r,gg=g,bb=b; + colorList.push_back(QtColorItem(QColor(rr,gg,bb))); + colornum++; + } + fclose(fp); + if(colornumPAITOTALCOLOR_MAX) colornum=PAITOTALCOLOR_MAX; // 最大总颜色数目 + if(inpolation) + { + colorList=paiInpolation(colorList,colornum);//SYSTEM_INPOLATION); + } + return colorList.count(); +} + +QtColorTableData *QtColorTableData::getInstance() +{ + static QtColorTableData ref("Color Scheme", true); + return &ref; +} + +bool QtColorTableData::LoadScheme(bool IsReLoad) +{ + if(!IsReLoad&&m_SharedMemory.isAttached()) { + if(m_SharedMemory.key()!=m_modulName) { + m_SharedMemory.detach(); + m_SharedMemory.setKey(m_modulName); + m_SharedMemory.attach(); + } + int s=m_SharedMemory.size(); + if(m_SharedMemory.isAttached()&&s) { + m_colorSchemeList.clear(); + char *buffer=(char*)m_SharedMemory.data(); + int size=*(int*)buffer; + for(int i=0;i-1)name=name.mid(0,pos); + QVector colorList; + + int ret=getPaiSystemColor(i,colorList,m_polatationSystemColor); + if(ret<=0) continue; + k++; + // 构建颜色方案表 + QtSchemeColor schemeItem; + schemeItem.schemeName=name; + schemeItem.colorList=colorList; + schemeItem.isDirty=false; + schemeItem.isCustom=false; + schemeItem.currentIndex=0; + m_colorSchemeList.push_back(schemeItem); + + // 对于系统颜色方案,单独生成备份 + m_systemSchemeList.push_back(schemeItem); + } + m_systemShcemeNum=k; + } + // 读取定制的颜色方案 + ReadSettings(); + if(m_currentSchemIndex<0 || m_currentSchemIndex>=m_colorSchemeList.count()) + { + m_currentSchemIndex=0; + } + + for(int i=0;icolorList.count()) + return false; + + // 完成颜色插值 + QVector newColorList= + paiInpolation(scheme->colorList,colorNum); + scheme->colorList=newColorList; + if(scheme->currentIndex>=scheme->colorList.count()) + scheme->currentIndex=0; + ChangeDataRange(scheme); + scheme->isDirty=true; + return true; +} + +QList QtColorTableData::GetRgb(int colornum) const +{ + const QtSchemeColor* scheme=&m_colorSchemeList[m_currentSchemIndex]; + QList rgbList; + if(colornum<=0) + colornum=scheme->colorList.count(); + else if(colornum>SECTIONVIEW_NUM) + colornum=SECTIONVIEW_NUM; + + QVector newColorList; + + if(colornum!=scheme->colorList.count()) + newColorList=paiInpolation(scheme->colorList,colornum); + else + newColorList=scheme->colorList; + + for(int i=0;icolorList.count(); + float flGap=(m_flMaxVal-m_flMinVal)/(colorNum); + for(int row=0;rowcolorList[row].toValue=m_flMinVal+flGap; + } + else + { + scheme->colorList[row].fromValue=m_flMinVal+(row)*flGap; + scheme->colorList[row].toValue=m_flMinVal+(row+1)*flGap; + } + } +} + +void QtColorTableData::ReadSettings() +{ + QList shcemeLis; + QtColorItem itemColor; + QString strImagePath; + QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator(); + strImagePath = QDir::toNativeSeparators( strPathTmp ); + QString filecfg=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+"colortable.cfg"; + FILE *fp1=fopen(filecfg.toStdString().c_str(),"rt"); + if(!fp1) return; + char buf[100]; + QString str,name; + int i=0; + while(!feof(fp1)) { + fscanf(fp1,"%s",buf); + name=buf; + if(name.indexOf("custom",Qt::CaseInsensitive)>=0) { + QString filename=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+name; + FILE *fp=fopen(filename.toStdString().c_str(),"rt"); + if(!fp) return; + QVector colorList; + float r,g,b; + QStringList strs; + while(!feof(fp)) { + char *ret=fgets(buf,100,fp); + if(!ret) break; + str=buf; + str.replace("\r",""); + str.replace("\n",""); + if(str.indexOf("#")>-1) continue; + if(str.indexOf("=")>-1) continue; + if(str.indexOf("R",Qt::CaseInsensitive)>-1) continue; + if(str.indexOf("G",Qt::CaseInsensitive)>-1) continue; + if(str.indexOf("B",Qt::CaseInsensitive)>-1) continue; + strs=str.split(" "); + strs.removeAll(""); + if(strs.size()!=3) continue; + r=strs[0].toFloat(); + g=strs[1].toFloat(); + b=strs[2].toFloat(); + if((r>0&&r<=1)||(g>0&&g<=1)||(b>0&&b<=1)) { + r*=255; + g*=255; + b*=255; + } + int rr=r,gg=g,bb=b; + colorList.push_back(QtColorItem(QColor(rr,gg,bb))); + } + fclose(fp); + QtSchemeColor schemeItem; + name=name.mid(name.lastIndexOf("\\")+1); + if(name.lastIndexOf(".rgb",-1,Qt::CaseInsensitive)>-1)name=name.mid(0,name.lastIndexOf(".rgb",-1,Qt::CaseInsensitive)); + schemeItem.schemeName=name; + schemeItem.colorList=colorList; + schemeItem.isDirty=false; + schemeItem.isCustom=true; + schemeItem.currentIndex=0; + m_colorSchemeList.push_back(schemeItem); + } + } + fclose(fp1); + return; + // 读取 + bool readOk=readColorPaletteSetting(shcemeLis,gOrignizationName, m_modulName); + if(!readOk || shcemeLis.count()==0) + return; + + for(int i=0;i=m_colorSchemeList.count()) + return; + m_currentSchemIndex=nIndex; +} + +void QtColorTableData::FreeColorScheme() +{ + m_colorSchemeList.clear(); + m_systemSchemeList.clear(); + m_SharedMemory.detach(); +} diff --git a/qtpropertybrowser/qtColorSchemeComboBox.h b/qtpropertybrowser/qtColorSchemeComboBox.h new file mode 100644 index 0000000..d7abe3f --- /dev/null +++ b/qtpropertybrowser/qtColorSchemeComboBox.h @@ -0,0 +1,233 @@ +/* + * QtColorSchemeComboBox.h + * + * Created on: 2013-5-27 + * Author: long + */ + +#ifndef QtColorSchemeComboBox_H_ +#define QtColorSchemeComboBox_H_ +#include "qtpropertybrowser.h" +// #include "PaiColorPub.h" +#include "qtComboBox.h" +#include + +const QString gOrignizationName="PI PlatForm"; +const QString gSchemeNumKey="Scheme Color Number"; +const QString gOneSchemeNameKey="Custom "; +const QString gOneSchemeControlColorNumKey="Control colornum"; +const QString gOneSchemeColorKey="color"; + +#define PAITOTALCOLOR_MIN 2 // 最小总颜色数目 +#define PAITOTALCOLOR_MAX 65 // 最大总颜色数目 +#define SECTIONVIEW_NUM 255 + +struct Qt_ColorItem +{ + QRgb color; // 颜色值 + float fromValue; // 对应的振幅开始值 + float toValue; // 对应的振幅的结束值 + char strComments[64]; // 描述信息 +}; +class QtColorItem +{ +public: + QtColorItem() + { + color=QColor(0,0,0); + fromValue=toValue=0; + strComments=""; + } + QtColorItem(const QColor &color,float value=0) + { + this->color=color; + this->fromValue=this->toValue=value; + strComments=""; + } + + QtColorItem(const QtColorItem &other) + { + color=other.color; + fromValue=other.fromValue; + toValue=other.toValue; + strComments=other.strComments; + } + + QtColorItem & operator=(const QtColorItem &other) + { + color=other.color; + fromValue=other.fromValue; + toValue=other.toValue; + strComments=other.strComments; + return *this; + } + QColor color; // 颜色值 + float fromValue; // 对应的振幅开始值 + float toValue; // 对应的振幅的结束值 + QString strComments; // 描述信息 +}; + +/** + * @class QtSchemeColor + * @brief 描述一种颜色方案 + */ + +struct QtScheme_Color +{ + char schemeName[64]; + int size; + struct Qt_ColorItem colorList[256]; + bool isDirty; + bool isCustom; + int currentIndex; // 当前编辑的位置 +}; +class QtSchemeColor +{ +public: + QtSchemeColor() + { + schemeName=""; + colorList.clear(); + isDirty=isCustom=false; + currentIndex=0; + } + + QtSchemeColor(const QtSchemeColor &other) + { + schemeName=other.schemeName; + colorList=other.colorList; + isDirty=other.isDirty; + isCustom=other.isCustom; + currentIndex=other.currentIndex; + } + + + QtSchemeColor & operator=(const QtSchemeColor &other) + { + schemeName=other.schemeName; + colorList=other.colorList; + isDirty=other.isDirty; + isCustom=other.isCustom; + currentIndex=other.currentIndex; + return *this; + } + + + QString schemeName; + QVector colorList; + bool isDirty; + bool isCustom; + int currentIndex; // 当前编辑的位置 +}; + + +class QTPROPERTYBROWSER_EXPORT QtColorTableData +{ +public: + enum + { + MAXCUSTOM_SCHEME=12 // 允许的最大颜色自定义方案 + }; + + /** + * @brief 构造函数 + * @param moduleName 模块名称 + * @param inopSystemColor是否将读取的缺省颜色插值为65中 + */ + QtColorTableData(const QString &moduleName,bool inopSystemColor) + { + m_isSettingSysColor=false; + m_systemShcemeNum=0; + m_flMinVal=-1000; + m_flMaxVal=1000; + m_modulName=moduleName; + m_polatationSystemColor=inopSystemColor; + LoadScheme(); + } + + static QtColorTableData* getInstance(); + + /** + * @brief 加载已经存在的颜色方案 + */ + bool LoadScheme(bool IsReLoad=false); + + /* + * @brief 获取颜色方案列表 + * @warning 下一部准备实现不同模块的系统保留和自定义方案 + */ + QList &GetSchemeList() + { + return m_colorSchemeList; + } + + /** + * @brief 改变当前颜色方案的颜色数 + */ + bool ChangeColorNum(int colorNum); + /** + * @brief 获取当前颜色方案的RGB值 + * @param colornum 需要返回的颜色数目,如果为0按照实际的颜色数目返回 + */ + QList GetRgb(int colornum=0) const; + + void ChangeDataRange(QtSchemeColor *scheme); + + void ReadSettings(); + + /* + * @brief 设置当前的颜色方案序号 + * + */ + void SetCurrentSchemeIndex(int nIndex); + + /** + * @brief 获取当前的颜色方案 + */ + QtSchemeColor* CurrentScheme() + { + if(m_currentSchemIndex==-1) + return NULL; + return &m_colorSchemeList[m_currentSchemIndex]; + } +private: + void FreeColorScheme(); + + // 是否设置系统缺省颜色 + bool m_isSettingSysColor; + // 当前所有的颜色方案,包括系统方案,自定义方案 + QList m_colorSchemeList; + + // 备份的颜色方案 + QList m_systemSchemeList; + + QString m_modulName; // 用于保存参数的组织和模块名 + int m_currentSchemIndex; // 当前正在使用的颜色方案 + int m_systemShcemeNum; // 系统缺省的颜色方案数目 + bool m_polatationSystemColor; + + // 设置数据的最小和最大范围 + float m_flMinVal,m_flMaxVal; + + QSharedMemory m_SharedMemory; +}; + + +class QTPROPERTYBROWSER_EXPORT QtColorSchemeComboBox:public QtComboBox +{ +public: + QtColorSchemeComboBox(QWidget *parent=0); + virtual ~QtColorSchemeComboBox(); + + void setSchemeColor(const QList &schemeList); + + void ShowText(bool showText=true); +private: + QPixmap getColorLabelPixmap(const QVector &colorList,int colorNumber); + void freeColorScheme(); +private: + bool m_isShowText; + QList m_colorSchemeList; +}; + +#endif /* QtColorSchemeComboBox_H_ */ diff --git a/qtpropertybrowser/qtComboBox.cpp b/qtpropertybrowser/qtComboBox.cpp new file mode 100644 index 0000000..7b748a3 --- /dev/null +++ b/qtpropertybrowser/qtComboBox.cpp @@ -0,0 +1,530 @@ +/** + * @file QtComboBox.cpp + * @date 2011-10-17 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qtComboBox.h" + +/** + * @class QtComboBoxItemDelegate + * @brief 用来绘制ComboBox弹出选择框Item + */ +class QTPROPERTYBROWSER_EXPORT QtComboBoxItemDelegate : public QStyledItemDelegate +{ +public: + QtComboBoxItemDelegate(QObject *pParent = 0) : + QStyledItemDelegate(pParent) + { + } + +protected: + /** + * @brief 重新实现重绘函数 + * @param[in] pPainter 画笔 + * @param[in] option 类型选项 + * @param[in] index Model 索引 + */ + void paint(QPainter *pPainter, const QStyleOptionViewItem & option, const QModelIndex & index) const + { + QStyleOptionViewItemV4 opt = option; + initStyleOption(&opt, index); + opt.state = opt.state & ~QStyle::State_Selected; + + if((option.state & QStyle::State_Selected) && (option.state & QStyle::State_Enabled)) + { + QLinearGradient linearGrad(opt.rect.topLeft(), opt.rect.bottomLeft()); + linearGrad.setColorAt(0, QColor("#FFFFFF")); + linearGrad.setColorAt(1, QColor("#EAF2F4")); + opt.backgroundBrush = QBrush(linearGrad); + } + else + { + opt.backgroundBrush = QBrush("#EFF5FA"); + } + + const QWidget *pWidget = opt.widget; + if(pWidget == NULL) + { + return; + } + QStyle *pStyle = pWidget ? pWidget->style() : QApplication::style(); + + pStyle->drawControl(QStyle::CE_ItemViewItem, &opt, pPainter, pWidget); + + if((option.state & QStyle::State_Selected) && (option.state & QStyle::State_Enabled)) + { + pPainter->save(); + + pPainter->setPen(QColor("#AACEDB")); + pPainter->drawRoundedRect(option.rect.adjusted(1, 1, -2, -2), 1, 1); + + pPainter->restore(); + } + } + + /** + * @brief 重设高度 + * @param[in] option 类型选项 + */ + QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & /*index*/) const + { + return QSize(option.rect.width(), 24); + } +}; + +///////////////////////////////////////////////////////////////////// +QtComboBox::QtComboBox(QWidget *pParent) : + QComboBox(pParent), + m_AddButton(false) +{ + InitComboBox(); +} + +QtComboBox::QtComboBox(bool showAddButton, QWidget *pParent) + : QComboBox(pParent), + m_AddButton(showAddButton) +{ + InitComboBox(); + SetShowAddButton(m_AddButton); +} + +QtComboBox::~QtComboBox() +{ +} + +void QtComboBox::InitComboBox() +{ + m_pEditButton = NULL; + m_RealTimeValidate = false; + m_MaxVisibleItems = 10; // 默认显示10个 + + QAbstractItemView *pView = view(); + // 将view初始设置为最小,防止调整位置和大小时闪烁 + pView->parentWidget()->setFixedSize(QSize(0, 0)); + pView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + // 当Item文本过长,则在右侧用“...”代替 + pView->setTextElideMode(Qt::ElideRight); + const QObjectList objs = view()->parentWidget()->children (); + // 隐藏多余控件 + foreach(QObject *pObj, objs) + { + QWidget *pWgt = qobject_cast(pObj); + if(pWgt && (pWgt != pView)) + { + pWgt->setMaximumHeight(0); + } + } + + setItemDelegate(new QtComboBoxItemDelegate(this)); +} + +void QtComboBox::SetShowAddButton(bool show) +{ + if (show && m_pEditButton == NULL) + { + m_AddButton = true; + m_pEditButton = new QToolButton(this); + m_pEditButton->setIcon(QIcon(":/Edit.png")); + m_pEditButton->setStyleSheet( + "QToolButton{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," + "stop: 0.0 #FFFFFF, stop: 0.4 #F7FAFD,stop: 0.4 #E5EFF8, stop: 1.0 #BDD7EC);" + "border: 1px solid #839CB6; border-left:0px;" + "border-top-right-radius: 2px; border-bottom-right-radius: 2px}" + "QToolButton:hover { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," + "stop: 0.0 #F1F9FE, stop: 0.4 #E1F3FC, stop: 0.4 #C9E9F9, stop: 1.0 #9BD7F1);}" + "QToolButton:focus { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," + "stop: 0 #E6F5FB, stop: 0.38 #D0ECF8, stop: 0.39 #AADDF2, stop: 1.0 #70C5EA);}" + ); + + connect(m_pEditButton, SIGNAL(clicked()), this, SIGNAL(EditButtonClicked())); + } + else if(!show && m_pEditButton) + { + // 去掉按钮所占空间 + setStyleSheet(QString::fromUtf8("QComboBox{margin-right:0px}")); + + m_pEditButton->hide(); + } +} + +void QtComboBox::showPopup () +{ + QComboBox::showPopup(); + + if(count() == 0) + { + return; + } + + // 每条Item的高度为24; + const int ITEM_HEIGHT = 24; + int popWidgetHeight = ITEM_HEIGHT * (m_MaxVisibleItems < count() ? m_MaxVisibleItems : count()) + 2; + QPoint popWidgetPos(0, 0); + + // 屏幕高度 + int iHeightOfScreen = QApplication::desktop()->height(); + // 下方空间高度 + int iBottomSpace = iHeightOfScreen - mapToGlobal(rect().bottomLeft()).y(); + // 上方空间高度 + int iTopSpace = mapToGlobal(rect().topLeft()).y(); + + if(iBottomSpace >= popWidgetHeight) //如果下方区域足够显示选择列表则在下方显示 + { + popWidgetPos = mapToGlobal(rect().bottomLeft()) - QPoint( -m_margin.left(), m_margin.bottom()); + } + else if(iTopSpace >= popWidgetHeight) //如果下方空间不足,而上方空间充足,则上方显示 + { + popWidgetPos = mapToGlobal(rect().topLeft()) - QPoint(0, popWidgetHeight) + QPoint(m_margin.left(), m_margin.top()); + } + else // 如果上下空间都不足,则调整显示条数 + { + if(iBottomSpace > iTopSpace) + { + popWidgetHeight = iBottomSpace; + popWidgetPos = mapToGlobal(rect().bottomLeft()) - QPoint( -m_margin.left(), m_margin.bottom()); + } + else + { + popWidgetHeight = iTopSpace; + popWidgetPos = mapToGlobal(rect().topLeft()) - QPoint(0, popWidgetHeight) + QPoint(m_margin.left(), m_margin.top()); + } + } + + // 调整view的位置和大小 + QAbstractItemView *pView = view(); + if(pView && pView->parentWidget()) + { + pView->parentWidget()->setFixedHeight(popWidgetHeight); + pView->parentWidget()->move(popWidgetPos); + + int minWidth = rect().width() - m_margin.left() - m_margin.right(); + int widthOfScreen = QApplication::desktop()->width(); + // 如果ComboBox的宽度小于屏幕三分之一,根据每行Item文字长度调节下拉框宽度 + if(rect().width() < widthOfScreen / 3) + { + // 根据每行Item文字长度,确定List的最小宽度 + QFontMetrics metrics(pView->font()); + QString text; + + for(int i = 0; i < count(); i++) + { + text = itemText(i) + " ";//添空格为边框占位 + minWidth = minWidth > metrics.width(text) ? minWidth : metrics.width(text); + } + // 如果下拉框宽度超过显示屏宽度三分之一,则将其宽度设置为屏幕宽度的三分之一 + if(minWidth > widthOfScreen / 3) + { + minWidth = widthOfScreen / 3; + } + } + + pView->parentWidget()->setFixedWidth(minWidth); + } +} + +int QtComboBox::GetMaxVisibleItems() const +{ + return m_MaxVisibleItems; +} + +void QtComboBox::SetMaxVisibleItems(const int count) +{ + m_MaxVisibleItems = count; +} + +void QtComboBox::setStyleSheet(const QString & styleSheet) +{ + QComboBox::setStyleSheet(styleSheet); + QRegExp reg("(margin)\\s*:\\s*\\d+\\s*(px)(.*);"); + + int offset = styleSheet.toLower().indexOf(reg); + if(offset != -1) + { + int end = styleSheet.indexOf(";", offset); + QString str = styleSheet.mid(offset, end - offset); + QStringList items = str.split(" "); + + if(items.size() == 1) + { + QRegExp num("(\\d+)"); + int pos = num.indexIn(items[0]); + QString value; + if (pos > -1) + { + value = num.cap(1); + } + + bool ok; + int margin = value.toInt(&ok, 10); + if(ok) + { + m_margin = QMargins(margin, margin, margin, margin); + } + } + else if(items.size() == 4) + { + QRegExp num("(\\d+)"); + int pos; + bool ok; + QString value; + int left, top, right, bottom; + + pos = num.indexIn(items[0]); + if (pos > -1) + { + value = num.cap(1); + } + left = value.toInt(&ok, 10); + + if(!ok) + { + return; + } + + pos = num.indexIn(items[1]); + if (pos > -1) + { + value = num.cap(1); + } + top = value.toInt(&ok, 10); + + if(!ok) + { + return; + } + + pos = num.indexIn(items[2]); + if (pos > -1) + { + value = num.cap(1); + } + right = value.toInt(&ok, 10); + + if(!ok) + { + return; + } + + pos = num.indexIn(items[3]); + if (pos > -1) + { + value = num.cap(1); + } + bottom = value.toInt(&ok, 10); + + if(!ok) + { + return; + } + + m_margin = QMargins(left, top, right, bottom); + } + } + else + { + int left; + QRegExp regLeft("(margin-left)\\s*:\\s*\\d+\\s*(px)\\s*;"); + offset = styleSheet.toLower().indexOf(regLeft); + + if(offset == -1) + { + left = 0; + } + else + { + int end = styleSheet.indexOf(";", offset); + QString str = styleSheet.mid(offset, end - offset); + + QRegExp num("(\\d+)"); + int pos = num.indexIn(str); + QString value; + if (pos > -1) + { + value = num.cap(1); + } + + bool ok; + int margin = value.toInt(&ok, 10); + if(ok) + { + left = margin; + } + } + + int top; + QRegExp regTop("(margin-top)\\s*:\\s*\\d+\\s*(px)\\s*;"); + offset = styleSheet.toLower().indexOf(regTop); + + if(offset == -1) + { + top = 0; + } + else + { + int end = styleSheet.indexOf(";", offset); + QString str = styleSheet.mid(offset, end - offset); + + QRegExp num("(\\d+)"); + int pos = num.indexIn(str); + QString value; + if (pos > -1) + { + value = num.cap(1); + } + + bool ok; + int margin = value.toInt(&ok, 10); + if(ok) + { + top = margin; + } + } + + int right; + QRegExp regRight("(margin-right)\\s*:\\s*\\d+\\s*(px)\\s*;"); + offset = styleSheet.toLower().indexOf(regRight); + + if(offset == -1) + { + right = 0; + } + else + { + int end = styleSheet.indexOf(";", offset); + QString str = styleSheet.mid(offset, end - offset); + + QRegExp num("(\\d+)"); + int pos = num.indexIn(str); + QString value; + if (pos > -1) + { + value = num.cap(1); + } + + bool ok; + int margin = value.toInt(&ok, 10); + if(ok) + { + right = margin; + } + } + + int bottom; + QRegExp regBottom("(margin-top)\\s*:\\s*\\d+\\s*(px)\\s*;"); + offset = styleSheet.toLower().indexOf(regBottom); + + if(offset == -1) + { + bottom = 0; + } + else + { + int end = styleSheet.indexOf(";", offset); + QString str = styleSheet.mid(offset, end - offset); + + QRegExp num("(\\d+)"); + int pos = num.indexIn(str); + QString value; + if (pos > -1) + { + value = num.cap(1); + } + + bool ok; + int margin = value.toInt(&ok, 10); + if(ok) + { + bottom = margin; + } + } + m_margin = QMargins(left, top, right, bottom); + } +} + +void QtComboBox::SetRealTimeValidate(bool flag) +{ + m_RealTimeValidate = flag; +} + + +void QtComboBox::keyPressEvent(QKeyEvent *pEvent) +{ + if(pEvent->key() == Qt::Key_Return) + { + QComboBox::keyPressEvent(pEvent); + pEvent->accept(); // 过滤事件,使其不往父窗体传递 + return; + } + + if((!m_RealTimeValidate) || (pEvent->key() == Qt::Key_Backspace) || (pEvent->key() == Qt::Key_Delete)) + { + QComboBox::keyPressEvent(pEvent); + return; + } + + QString currentStr = currentText(); + QLineEdit *pLineEdit = lineEdit(); + QString selectedText = pLineEdit->selectedText(); + QString pressAfterStr; + int pos = pLineEdit->cursorPosition(); + if(selectedText.isEmpty()) + { + pressAfterStr = currentStr.insert(pos, pEvent->text()); + } + else + { + pressAfterStr = currentStr.replace(pLineEdit->selectionStart(), selectedText.size(), pEvent->text()); + } + + const QValidator *pValidator = validator(); + int postion = pressAfterStr.size(); + if(pValidator && (pValidator->validate(pressAfterStr, postion) == QValidator::Invalid)) + { + pEvent->accept(); + } + else + { + QComboBox::keyPressEvent(pEvent); + } + + return; +} + +void QtComboBox::resizeEvent(QResizeEvent *pEvent) +{ + QComboBox::resizeEvent(pEvent); + // 请不要添加m_pEditButton->isVisible()条件,因为没有paint之前控件是不可见的 + if(m_AddButton && m_pEditButton) + { + // 为按钮所准备空间 + setStyleSheet(QString::fromUtf8("QComboBox{margin-right:%1px}").arg(height())); + } +} + +void QtComboBox::paintEvent(QPaintEvent *pEvent) +{ + QComboBox::paintEvent(pEvent); + if(m_AddButton && m_pEditButton && m_pEditButton->isVisible()) + { + // 添加限制条件确保这里不会频繁的调用 + QRect rect(width()-height() - 1, 0, height() + 1, height()); + if(m_pEditButton->geometry() != rect) + { + m_pEditButton->setGeometry(rect); + } + + QPainter painter(this); + painter.setPen(QColor("#839CB6")); + painter.drawLine(width()-height() - 2, 6, width() - height() - 2, height() - 6); + } +} diff --git a/qtpropertybrowser/qtComboBox.h b/qtpropertybrowser/qtComboBox.h new file mode 100644 index 0000000..cc9ec01 --- /dev/null +++ b/qtpropertybrowser/qtComboBox.h @@ -0,0 +1,115 @@ +/** + * @file QtComboBox.h + * @brief ComboBox控件 + * @date 2011-10-17 + */ +#ifndef PAI_FRAME_WIDGET_QtComboBox_H +#define PAI_FRAME_WIDGET_QtComboBox_H + +#include +#include +#include +#include "qtpropertybrowser.h" + +/** + * @class QtComboBox + * @brief QtComboBox是P.A.I系统定制发布的组合框 + */ +class QTPROPERTYBROWSER_EXPORT QtComboBox : public QComboBox +{ + Q_OBJECT +public: + /** + * @brief 构造函数 + * @param[in] pParent 父窗口句柄 + */ + QtComboBox(QWidget *pParent = NULL); + + /** + * @brief 构造函数 + * @param[in] showAddButton 是否显示右侧按钮 + * @param[in] pParent 父窗口句柄 + */ + QtComboBox(bool showAddButton, QWidget *pParent = NULL); + + /** + * @brief 析构函数 + */ + virtual ~QtComboBox(); + + /** + * @brief 设置是否使用实时过滤,默认为false不使用。 + * @param[in] flag true 使用实时过滤,反之关闭实时过滤 + */ + void SetRealTimeValidate(bool flag); + + /** + * @brief 设置是否添加Editbutton。 + * @param[in] show true 添加Editbutton,反之则不添加 + */ + void SetShowAddButton(bool show); + + /** + * @brief 重写函数,实现对显示数量的设定 + */ + virtual void showPopup (); + + /** + * @brief 获取选择列表一次显示的项目最大条数 + * @return 最大条数 + */ + int GetMaxVisibleItems() const; + + /** + * @brief 设置选择列表一次显示的项目最大条数 + * @param[in] count 最大显示条数 + */ + void SetMaxVisibleItems(const int count); + + /** + * @brief 重写系统函数,使得在对ComboBox设置styleSheet的时候, + * 它的下拉列表能够作出一些对应的调整,以使外观更加合适。 + * @param[in] styleSheet sytleSheet字符串 + */ + void setStyleSheet(const QString & styleSheet); + +protected: + /** + * @brief 重写keyPressEvent,用来处理输入限制的问题 + * @param[in] pEvent 键盘按压事件 + */ + virtual void keyPressEvent(QKeyEvent *pEvent); + + /** + * @brief 重写resizeEvent,用来处理变换大小的问题 + * @param[in] pEvent 重置大小事件 + */ + virtual void resizeEvent (QResizeEvent *pEvent); + + /** + * @brief 重绘 + * @param[in] pEvent 重画事件 + */ + virtual void paintEvent(QPaintEvent *pEvent); + +private: + /** + * @brief 初始化组件 + */ + void InitComboBox(); + +private: + QToolButton *m_pEditButton; ///< 编辑按钮 + bool m_RealTimeValidate; ///< 实时校验标志 + bool m_AddButton; ///< 添加按钮 + int m_MaxVisibleItems; ///< 最大可视条数 + QMargins m_margin; ///< 间隔区域 + +signals: + /** + * @brief EditButton的点击事件 + */ + void EditButtonClicked(); +}; + +#endif ///< PAI_FRAME_WIDGET_QtComboBox_H diff --git a/qtpropertybrowser/qteditorfactory.cpp b/qtpropertybrowser/qteditorfactory.cpp index 664667c..3e969c9 100644 --- a/qtpropertybrowser/qteditorfactory.cpp +++ b/qtpropertybrowser/qteditorfactory.cpp @@ -75,64 +75,6 @@ static inline void setupTreeViewEditorMargin(QLayout *lt) lt->setContentsMargins(0, 0, DecorationMargin, 0); } -// ---------- EditorFactoryPrivate : -// Base class for editor factory private classes. Manages mapping of properties to editors and vice versa. - -template -class EditorFactoryPrivate -{ -public: - - typedef QList EditorList; - typedef QMap PropertyToEditorListMap; - typedef QMap EditorToPropertyMap; - - Editor *createEditor(QtProperty *property, QWidget *parent); - void initializeEditor(QtProperty *property, Editor *e); - void slotEditorDestroyed(QObject *object); - - PropertyToEditorListMap m_createdEditors; - EditorToPropertyMap m_editorToProperty; -}; - -template -Editor *EditorFactoryPrivate::createEditor(QtProperty *property, QWidget *parent) -{ - Editor *editor = new Editor(parent); - initializeEditor(property, editor); - return editor; -} - -template -void EditorFactoryPrivate::initializeEditor(QtProperty *property, Editor *editor) -{ - typename PropertyToEditorListMap::iterator it = m_createdEditors.find(property); - if (it == m_createdEditors.end()) - it = m_createdEditors.insert(property, EditorList()); - it.value().append(editor); - m_editorToProperty.insert(editor, property); -} - -template -void EditorFactoryPrivate::slotEditorDestroyed(QObject *object) -{ - const typename EditorToPropertyMap::iterator ecend = m_editorToProperty.end(); - for (typename EditorToPropertyMap::iterator itEditor = m_editorToProperty.begin(); itEditor != ecend; ++itEditor) { - if (itEditor.key() == object) { - Editor *editor = itEditor.key(); - QtProperty *property = itEditor.value(); - const typename PropertyToEditorListMap::iterator pit = m_createdEditors.find(property); - if (pit != m_createdEditors.end()) { - pit.value().removeAll(editor); - if (pit.value().empty()) - m_createdEditors.erase(pit); - } - m_editorToProperty.erase(itEditor); - return; - } - } -} - // ------------ QtSpinBoxFactory class QtSpinBoxFactoryPrivate : public EditorFactoryPrivate diff --git a/qtpropertybrowser/qteditorfactory.h b/qtpropertybrowser/qteditorfactory.h index 46099fa..443d4ef 100644 --- a/qtpropertybrowser/qteditorfactory.h +++ b/qtpropertybrowser/qteditorfactory.h @@ -48,6 +48,65 @@ QT_BEGIN_NAMESPACE class QtSpinBoxFactoryPrivate; + +// ---------- EditorFactoryPrivate : +// Base class for editor factory private classes. Manages mapping of properties to editors and vice versa. +template +class EditorFactoryPrivate +{ +public: + + typedef QList EditorList; + typedef QMap PropertyToEditorListMap; + typedef QMap EditorToPropertyMap; + + Editor *createEditor(QtProperty *property, QWidget *parent); + void initializeEditor(QtProperty *property, Editor *e); + void slotEditorDestroyed(QObject *object); + + PropertyToEditorListMap m_createdEditors; + EditorToPropertyMap m_editorToProperty; +}; + +template +Editor *EditorFactoryPrivate::createEditor(QtProperty *property, QWidget *parent) +{ + Editor *editor = new Editor(parent); + initializeEditor(property, editor); + return editor; +} + +template +void EditorFactoryPrivate::initializeEditor(QtProperty *property, Editor *editor) +{ + typename PropertyToEditorListMap::iterator it = m_createdEditors.find(property); + if (it == m_createdEditors.end()) + it = m_createdEditors.insert(property, EditorList()); + it.value().append(editor); + m_editorToProperty.insert(editor, property); +} + +template +void EditorFactoryPrivate::slotEditorDestroyed(QObject *object) +{ + const typename EditorToPropertyMap::iterator ecend = m_editorToProperty.end(); + for (typename EditorToPropertyMap::iterator itEditor = m_editorToProperty.begin(); itEditor != ecend; ++itEditor) { + if (itEditor.key() == object) { + Editor *editor = itEditor.key(); + QtProperty *property = itEditor.value(); + const typename PropertyToEditorListMap::iterator pit = m_createdEditors.find(property); + if (pit != m_createdEditors.end()) { + pit.value().removeAll(editor); + if (pit.value().empty()) + m_createdEditors.erase(pit); + } + m_editorToProperty.erase(itEditor); + return; + } + } +} + + class QTPROPERTYBROWSER_EXPORT QtSpinBoxFactory : public QtAbstractEditorFactory { Q_OBJECT diff --git a/qtpropertybrowser/qtpropertybrowser.pro b/qtpropertybrowser/qtpropertybrowser.pro index a07fa75..50eca9a 100644 --- a/qtpropertybrowser/qtpropertybrowser.pro +++ b/qtpropertybrowser/qtpropertybrowser.pro @@ -40,7 +40,10 @@ SOURCES += $$PWD/qtpropertybrowser.cpp \ $$PWD/qttreepropertybrowser.cpp \ $$PWD/qtbuttonpropertybrowser.cpp \ $$PWD/qtgroupboxpropertybrowser.cpp \ - $$PWD/qtpropertybrowserutils.cpp + $$PWD/qtpropertybrowserutils.cpp \ + ColorSchemeComboBox.cpp \ + qtColorSchemeComboBox.cpp \ + qtComboBox.cpp HEADERS += $$PWD/qtpropertybrowser.h \ $$PWD/qtpropertymanager.h \ @@ -49,7 +52,10 @@ HEADERS += $$PWD/qtpropertybrowser.h \ $$PWD/qttreepropertybrowser.h \ $$PWD/qtbuttonpropertybrowser.h \ $$PWD/qtgroupboxpropertybrowser.h \ - $$PWD/qtpropertybrowserutils_p.h + $$PWD/qtpropertybrowserutils_p.h \ + ColorSchemeComboBox.h \ + qtColorSchemeComboBox.h \ + qtComboBox.h RESOURCES += $$PWD/qtpropertybrowser.qrc @@ -60,11 +66,11 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target CONFIG(debug, debug|release){ - DESTDIR = ../Bin - DLLDESTDIR = ../Bin + DESTDIR = ../../Bin + DLLDESTDIR = ../../Bin TARGET = $$join(TARGET,,,d) #为debug版本生成的文件增加d的后缀 } else { - DESTDIR = ../Bin - DLLDESTDIR = ../Bin + DESTDIR = ../../Bin + DLLDESTDIR = ../../Bin TARGET = $$join(TARGET,,,) }