加强属性例子
This commit is contained in:
parent
0c02c01f3f
commit
9fa699ea63
|
|
@ -45,6 +45,10 @@ set(H_HEADER_FILES
|
|||
include/designerView.h
|
||||
include/operationCommand.h
|
||||
|
||||
include/propertyType/CustomGadget.h
|
||||
include/propertyType/CustomType.h
|
||||
include/propertyType/PropertyTypeCustomization_CustomType.h
|
||||
|
||||
include/util/baseSelector.h
|
||||
include/util/creatingSelector.h
|
||||
include/util/movingSelector.h
|
||||
|
|
@ -69,6 +73,8 @@ set(CPP_SOURCE_FILES
|
|||
source/designerView.cpp
|
||||
source/operationCommand.cpp
|
||||
|
||||
source/propertyType/PropertyTypeCustomization_CustomType.cpp
|
||||
|
||||
source/util/baseSelector.cpp
|
||||
source/util/creatingSelector.cpp
|
||||
source/util/movingSelector.cpp
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
Type get##Name(){ return Name; } \
|
||||
void set##Name(Type var){ \
|
||||
Name = var; \
|
||||
qDebug() << "Set" << static_cast<QObject*>(this) <<#Name <<": " <<var; \
|
||||
qDebug() << "Set" <<#Name <<": " <<var; \
|
||||
} \
|
||||
Type Name
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,23 @@
|
|||
#ifndef GRAPHICSBUSSECTIONITEM_H
|
||||
#define GRAPHICSBUSSECTIONITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <qvectornd.h>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QColor>
|
||||
#include <QMatrix4x4>
|
||||
|
||||
#include "CommonInclude.h"
|
||||
#include "propertyType/CustomType.h"
|
||||
#include "propertyType/CustomGadget.h"
|
||||
|
||||
#include "graphicsItem/graphicsBaseItem.h"
|
||||
|
||||
class GraphicsBusSectionItem : public GraphicsBaseItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("LimitedDouble", "Min=0,Max=10")
|
||||
|
||||
public:
|
||||
explicit GraphicsBusSectionItem(const QRect &rect, QGraphicsItem *parent = nullptr);
|
||||
|
|
@ -18,8 +28,35 @@ public:
|
|||
void move(const QPointF&) override;
|
||||
void editShape(int, const QPointF&) override;
|
||||
|
||||
public:
|
||||
public:
|
||||
enum QCustomEnum {
|
||||
One,
|
||||
Two,
|
||||
Three
|
||||
};
|
||||
Q_ENUM(QCustomEnum);
|
||||
|
||||
public:
|
||||
Q_PROPERTY_VAR(int, Int) = 0;
|
||||
Q_PROPERTY_VAR(float, Float) = 1.23f;
|
||||
Q_PROPERTY_VAR(double, LimitedDouble) = 5;
|
||||
Q_PROPERTY_VAR(QString, String);
|
||||
Q_PROPERTY_VAR(QDir, Directory) = QDir(".");
|
||||
Q_PROPERTY_VAR(QVector2D, Vec2) = QVector2D(1, 2);
|
||||
Q_PROPERTY_VAR(QVector3D, Vec3) = QVector3D(1, 2, 3);
|
||||
Q_PROPERTY_VAR(QVector4D, Vec4) = QVector4D(1, 2, 3, 4);
|
||||
Q_PROPERTY_VAR(QMatrix4x4, Mat4);
|
||||
Q_PROPERTY_VAR(QColor, Color);
|
||||
Q_PROPERTY_VAR(QList<QColor>, ColorList) = { Qt::red,Qt::green,Qt::blue };
|
||||
|
||||
typedef QMap<QString, QColor> StringColorMap;
|
||||
Q_PROPERTY_VAR(StringColorMap, ColorMap) = { {"Red",Qt::red},{"Green",Qt::green},{"Blue",Qt::blue} };
|
||||
|
||||
Q_PROPERTY_VAR(QCustomEnum, CustomEnum) = QCustomEnum::One;
|
||||
Q_PROPERTY_VAR(QCustomType, CustomType);
|
||||
Q_PROPERTY_VAR(QCustomGadget, CustomGadget);
|
||||
Q_PROPERTY_VAR(QCustomGadget*, CustomGadgetPtr) = new QCustomGadget;
|
||||
Q_PROPERTY_VAR(QSharedPointer<QCustomGadget>, CustomGadgetSharedPtr) = QSharedPointer<QCustomGadget>::create();
|
||||
|
||||
protected:
|
||||
virtual QPainterPath shape() override;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef CustomGadget_h__
|
||||
#define CustomGadget_h__
|
||||
|
||||
#include "CommonInclude.h"
|
||||
|
||||
class QCustomGadget {
|
||||
Q_GADGET
|
||||
Q_CLASSINFO("LimitedDouble", "Min=0,Max=10")
|
||||
public:
|
||||
Q_PROPERTY_VAR(double, LimitedDouble) = 1;
|
||||
Q_PROPERTY_VAR(QString, Desc) = "This is inline Gadget";
|
||||
};
|
||||
|
||||
static QDebug operator<<(QDebug debug, const QCustomGadget& gadget) {
|
||||
return debug << gadget.LimitedDouble << gadget.Desc;
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QSharedPointer<QCustomGadget>);
|
||||
|
||||
#endif // CustomGadget_h__
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef CustomType_h__
|
||||
#define CustomType_h__
|
||||
|
||||
#include <QVector>
|
||||
#include <QMetaType>
|
||||
|
||||
struct QCustomType {
|
||||
unsigned int ArraySize = 0;
|
||||
QVector<int> Array;
|
||||
};
|
||||
|
||||
static QDebug operator<<(QDebug debug, const QCustomType& it) {
|
||||
return debug << it.Array;
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QCustomType)
|
||||
|
||||
#endif // CustomType_h__
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef PropertyTypeCustomization_CustomType_h__
|
||||
#define PropertyTypeCustomization_CustomType_h__
|
||||
|
||||
#include "IPropertyTypeCustomization.h"
|
||||
|
||||
class PropertyTypeCustomization_CustomType : public IPropertyTypeCustomization {
|
||||
protected:
|
||||
virtual void customizeHeaderRow(QPropertyHandle* inPropertyHandle, QQuickDetailsViewRowBuilder* inBuilder) override;
|
||||
virtual void customizeChildren(QPropertyHandle* inPropertyHandle, QQuickDetailsViewLayoutBuilder* inBuilder) override;
|
||||
};
|
||||
|
||||
#endif // PropertyTypeCustomization_CustomType_h__
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
#include "FloatingDockContainer.h"
|
||||
#include "DockComponentsFactory.h"
|
||||
|
||||
#include "QQuickDetailsViewMananger.h"
|
||||
#include "propertyType/PropertyTypeCustomization_CustomType.h"
|
||||
#include "propertyType/CustomType.h"
|
||||
#include "QDetailsView.h"
|
||||
#include "util/selectorManager.h"
|
||||
|
||||
|
|
@ -87,12 +90,15 @@ void CMainWindow::initializeDockUi()
|
|||
m_pDockManager->addDockWidget(DockWidgetArea::LeftDockWidgetArea, grapicElementsDockWidget);
|
||||
ui->menuView->addAction(grapicElementsDockWidget->toggleViewAction());
|
||||
|
||||
QQuickDetailsViewManager::Get()->registerPropertyTypeCustomization<QCustomType, PropertyTypeCustomization_CustomType>();
|
||||
|
||||
m_pPropertiesEditorView = new QDetailsView();
|
||||
CDockWidget* propertiesDockWidget = new CDockWidget(QString::fromWCharArray(L"属性编辑器"));
|
||||
propertiesDockWidget->setWidget(m_pPropertiesEditorView);
|
||||
propertiesDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
|
||||
propertiesDockWidget->resize(250, 150);
|
||||
propertiesDockWidget->setMinimumSize(200,150);
|
||||
propertiesDockWidget->resize(550, 150);
|
||||
propertiesDockWidget->setMinimumSize(500,150);
|
||||
m_pPropertiesEditorView->setObject(m_pDrawingPanel->getQGraphicsScene());
|
||||
m_pDockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, propertiesDockWidget, centralDockArea);
|
||||
ui->menuView->addAction(propertiesDockWidget->toggleViewAction());
|
||||
}
|
||||
|
|
@ -171,7 +177,6 @@ void CMainWindow::onSignal_addItem(GraphicsBaseItem* item)
|
|||
{
|
||||
if(item)
|
||||
{
|
||||
// m_pPropertiesEditorView->setObject(static_cast<QObject*>(item));
|
||||
QUndoCommand* addItemCommand = new AddItemCommand(item, item->scene());
|
||||
m_pUndoStack->push(addItemCommand);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
#include "propertyType/PropertyTypeCustomization_CustomType.h"
|
||||
#include "QQuickDetailsViewLayoutBuilder.h"
|
||||
#include "QPropertyHandle.h"
|
||||
#include <QMetaType>
|
||||
#include <QObject>
|
||||
#include <QRandomGenerator>
|
||||
#include "QQuickDetailsViewModel.h"
|
||||
#include "propertyType/CustomType.h"
|
||||
#include "QQuickFunctionLibrary.h"
|
||||
|
||||
void PropertyTypeCustomization_CustomType::customizeHeaderRow(QPropertyHandle* inPropertyHandle, QQuickDetailsViewRowBuilder* inBuilder)
|
||||
{
|
||||
auto editorSlot = inBuilder->makeNameValueSlot();
|
||||
inPropertyHandle->setupNameEditor(editorSlot.first);
|
||||
auto buttonItem = inBuilder->setupItem(editorSlot.second, R"(
|
||||
import QtQuick;
|
||||
import QtQuick.Controls;
|
||||
Button{
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 80
|
||||
height: 20
|
||||
text: "Sort"
|
||||
}
|
||||
)");
|
||||
|
||||
|
||||
QQuickFunctionLibrary::connect(buttonItem, SIGNAL(clicked()), inPropertyHandle, [inPropertyHandle]() {
|
||||
QCustomType customType = inPropertyHandle->getVar().value<QCustomType>();
|
||||
std::sort(customType.Array.begin(), customType.Array.end());
|
||||
inPropertyHandle->setVar(QVariant::fromValue(customType));
|
||||
if (auto arrayHandle = inPropertyHandle->findChild("Array")) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void PropertyTypeCustomization_CustomType::customizeChildren(QPropertyHandle* inPropertyHandle, QQuickDetailsViewLayoutBuilder* inBuilder)
|
||||
{
|
||||
auto arrayHandle = inPropertyHandle->findOrCreateChild(
|
||||
QMetaType::fromType<QVector<int>>(),
|
||||
"Array",
|
||||
[inPropertyHandle]() {
|
||||
return QVariant::fromValue(inPropertyHandle->getVar().value<QCustomType>().Array);
|
||||
},
|
||||
[inPropertyHandle](QVariant var) {
|
||||
QCustomType customType = inPropertyHandle->getVar().value<QCustomType>();
|
||||
customType.Array = var.value<QVector<int>>();
|
||||
inPropertyHandle->setVar(QVariant::fromValue(customType));
|
||||
}
|
||||
);
|
||||
|
||||
auto arraySizeHandle = inPropertyHandle->findOrCreateChild(
|
||||
QMetaType::fromType<unsigned int>(),
|
||||
"ArraySize",
|
||||
[inPropertyHandle]() {
|
||||
return inPropertyHandle->getVar().value<QCustomType>().ArraySize;
|
||||
},
|
||||
[inPropertyHandle, arrayHandle](QVariant var) {
|
||||
QCustomType customType = inPropertyHandle->getVar().value<QCustomType>();
|
||||
customType.ArraySize = var.toUInt();
|
||||
customType.Array.resize(customType.ArraySize);
|
||||
for (int i = 0; i < customType.ArraySize; ++i) {
|
||||
customType.Array[i] = QRandomGenerator::global()->bounded(-100000, 100000);
|
||||
}
|
||||
inPropertyHandle->setVar(QVariant::fromValue(customType));
|
||||
arrayHandle->invalidateStructure();
|
||||
}
|
||||
);
|
||||
|
||||
inBuilder->addProperty(arraySizeHandle);
|
||||
inBuilder->addProperty(arrayHandle);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue