In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Qt implements loading properties. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
I. Preface
Control can load drag and stretch, these are the basic premise work, the next focus is to dynamically load the properties of the selected control, the property mechanism of Qt is extremely powerful, can only be described as powerful. If custom controls are written in Qt, if the properties have been described by Q_PROPERTY, they all support the loading of various application scenarios in the entire Qt ecological environment, such as the property design of widget. Attribute recognition in qml is very convenient. A careful look at the QtDesigner designer property control, looks like a table control is very similar, if you re-create a whole wheel, need to spend a huge price, in fact, Qt already has this open source component in qt-solutions-master, called qtpropertybrowser, search under the use of many of this component, demo is also very detailed, I changed part of the code in order to filter parent class properties and Chinese attribute mapping and so on.
Second, the functions realized
Automatically load all the controls in the plug-in file to generate a list, with more than 120 controls by default.
Drag to the canvas to automatically generate the corresponding control, WYSIWYG.
On the right side of the Chinese attribute bar, change the corresponding attributes immediately applied to the corresponding selected controls, intuitive and concise, very suitable for rookies to use.
The original attribute bar text translation mapping mechanism is extremely efficient, and it is very convenient to expand the attribute bar of other languages.
The properties of all controls are automatically extracted and displayed in the right property bar, including the enumerated value drop-down box.
Support manual selection of plug-in files, external import plug-in files.
You can export all control configuration information for the current canvas to a xml file.
You can manually select the xml file to open the control layout and automatically load the control according to the xml file.
Can pull the slider, check the analog data check box, text box input, three ways to generate data to apply all controls.
The control supports eight azimuth pull adjustments, adapts to any resolution, and fine-adjusts the position up and down the keyboard.
Through the serial port acquisition, network acquisition, database collection of three ways to set data.
The code is extremely concise, the comments are very detailed, and can be used as an embryonic form of configuration to expand more functions.
Pure Qt writing, support any Qt version + any compiler + any system.
Third, effect picture
4. Core code void QtObjectController::setObject (QObject * object) {/ / if the control set is already the current control, it does not deal with if (dwindptra-> m_object = = object) {return;} if (dumbptra-> m_object) {dumbptra-> saveExpandedState (); QListIterator it (dwindptre-> m_topLevelProperties) While (it.hasNext ()) {droomptra-> masked browser-> removeProperty (it.next ());} dumbptra-> m_topLevelProperties.clear ();} droomptre-> m_object = object; if (! dumbptra-> m_object) {return } / / load the properties of the parent class droomptra-> addClassPropertiesParent (dumbptra-> masked object-> metaObject ()-> superClass ()); / / load the properties of the current control droomptra-> addClassProperties (droomptr- > massively object-> metaObject ()); / / store the node state droomptr- > restoreExpandedState (); / / collapse all nodes droomptr- > collapseAll () } void QtObjectControllerPrivate::addClassProperties (const QMetaObject * metaObject) {if (! metaObject) {return;} QtProperty * classProperty = m_classToProperty.value (metaObject); if (! classProperty) {QString className = QLatin1String (metaObject- > className ()); classProperty = QtVariantPropertyManager::groupTypeId () > addProperty (QtVariantPropertyManager::groupTypeId (), className); m _ classToProperty [metaObject] = classProperty; m _ propertyToClass [classProperty] = metaObject For (int idx = metaObject- > propertyOffset (); idx
< metaObject->PropertyCount (); idx++) {QMetaProperty metaProperty = metaObject- > property (idx); int type = metaProperty.userType (); QtVariantProperty * subProperty = 0; / / replace English attribute with Chinese attribute QString propertyName = metaProperty.name (); propertyName = QtPropertyName::maps.value (propertyName, propertyName) If (! metaProperty.isReadable ()) {subProperty = mreadOnlyManager-> addProperty (QVariant::String, propertyName); subProperty- > setValue (QLatin1String ("
< Non Readable >");} else if (metaProperty.isEnumType ()) {if (metaProperty.isFlagType ()) {subProperty = madministrator-> addProperty (QtVariantPropertyManager::flagTypeId (), propertyName); QMetaEnum metaEnum = metaProperty.enumerator (); QMap valueMap; QStringList flagNames; for (int I = 0; I)
< metaEnum.keyCount(); i++) { int value = metaEnum.value(i); if (!valueMap.contains(value) && isPowerOf2(value)) { valueMap[value] = true; flagNames.append(QLatin1String(metaEnum.key(i))); } subProperty->SetAttribute (QLatin1String ("flagNames"), flagNames); subProperty- > setValue (flagToInt (metaEnum, metaProperty.read (m_object). ToInt ());}} else {subProperty = madministrator-> addProperty (QtVariantPropertyManager::enumTypeId (), propertyName); QMetaEnum metaEnum = metaProperty.enumerator (); QMap valueMap / / dont show multiple enum values which have the same values QStringList enumNames; for (int I = 0; I
< metaEnum.keyCount(); i++) { int value = metaEnum.value(i); if (!valueMap.contains(value)) { valueMap[value] = true; //将枚举类型强制转为中文 QString enumName = metaEnum.key(i); enumName = QtPropertyName::maps.value(enumName, enumName); enumNames.append(enumName); } } subProperty->SetAttribute (QLatin1String ("enumNames"), enumNames); subProperty- > setValue (enumToInt (metaEnum, metaProperty.read (m_object). ToInt ());}} else if (masking manager-> isPropertyTypeSupported (type)) {if (! metaProperty.isWritable ()) {subProperty = mreadreadOnlyManager-> addProperty (type, propertyName + QLatin1String ("(Non Writable)")) } if (! metaProperty.isDesignable ()) {subProperty = mreadOnlyManager-> addProperty (type, propertyName + QLatin1String ("(Non Designable)");} else {subProperty = mabilistic manager-> addProperty (type, propertyName);} subProperty- > setValue (metaProperty.read (m_object)) } else {subProperty = mreadOnlyManager-> addProperty (QVariant::String, propertyName); subProperty- > setValue (QLatin1String ("
< Unknown Type >"); subProperty- > setEnabled (false);} classProperty- > addSubProperty (subProperty); m _ propertyToIndex [subproperty] = idx; mclassToIndexToProperty [idx] = subProperty;}} else {updateClassProperties (metaObject, false);} m_topLevelProperties.append (classProperty); masking browser-> addProperty (classProperty) } void QtObjectControllerPrivate::addClassPropertiesParent (const QMetaObject * metaObject) {if (! metaObject) {return;} / / stores the properties that need to be filtered. Sometimes most properties do not use QStringList keyName; keyName className (); classProperty = QtVariantPropertyManager::groupTypeId manager-> addProperty (QtVariantPropertyManager::groupTypeId (), className); m _ classToProperty [metaObject] = classProperty; m _ propertyToClass [classProperty] = metaObject For (int idx = metaObject- > propertyOffset (); idx
< metaObject->PropertyCount (); idx++) {QMetaProperty metaProperty = metaObject- > property (idx); int type = metaProperty.userType (); QtVariantProperty * subProperty = 0; / / if the current attribute is not among the attributes to be filtered, proceed to the next attribute judgment QString propertyName = metaProperty.name (); if (! keyName.contains (propertyName)) {continue } propertyName = QtPropertyName::maps.value (propertyName, propertyName); if (! metaProperty.isReadable ()) {subProperty = mreadOnlyManager-> addProperty (QVariant::String, propertyName); subProperty- > setValue (QLatin1String ("
< Non Readable >");} else if (metaProperty.isEnumType ()) {if (metaProperty.isFlagType ()) {subProperty = madministrator-> addProperty (QtVariantPropertyManager::flagTypeId (), propertyName); QMetaEnum metaEnum = metaProperty.enumerator (); QMap valueMap; QStringList flagNames; for (int I = 0; I)
< metaEnum.keyCount(); i++) { int value = metaEnum.value(i); if (!valueMap.contains(value) && isPowerOf2(value)) { valueMap[value] = true; flagNames.append(QLatin1String(metaEnum.key(i))); } subProperty->SetAttribute (QLatin1String ("flagNames"), flagNames); subProperty- > setValue (flagToInt (metaEnum, metaProperty.read (m_object). ToInt ());}} else {subProperty = madministrator-> addProperty (QtVariantPropertyManager::enumTypeId (), propertyName); QMetaEnum metaEnum = metaProperty.enumerator (); QMap valueMap / / dont show multiple enum values which have the same values QStringList enumNames; for (int I = 0; I
< metaEnum.keyCount(); i++) { int value = metaEnum.value(i); if (!valueMap.contains(value)) { valueMap[value] = true; enumNames.append(QLatin1String(metaEnum.key(i))); } } subProperty->SetAttribute (QLatin1String ("enumNames"), enumNames); subProperty- > setValue (enumToInt (metaEnum, metaProperty.read (m_object). ToInt ());}} else if (masking manager-> isPropertyTypeSupported (type)) {if (! metaProperty.isWritable ()) {subProperty = mreadreadOnlyManager-> addProperty (type, propertyName + QLatin1String ("(Non Writable)")) } if (! metaProperty.isDesignable ()) {subProperty = mreadOnlyManager-> addProperty (type, propertyName + QLatin1String ("(Non Designable)");} else {subProperty = mabilistic manager-> addProperty (type, propertyName);} subProperty- > setValue (metaProperty.read (m_object)) } else {subProperty = mreadOnlyManager-> addProperty (QVariant::String, propertyName); subProperty- > setValue (QLatin1String ("
< Unknown Type >"); subProperty- > setEnabled (false);} classProperty- > addSubProperty (subProperty); m _ propertyToIndex [subproperty] = idx; mclassToIndexToProperty [idx] = subProperty;}} else {updateClassProperties (metaObject, false);} m_topLevelProperties.append (classProperty); masking browser-> addProperty (classProperty);} Thank you for reading! This is the end of this article on "how to load attributes in Qt". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.