Example #1
0
static inline void applyProperties(ModelNode &node, const QHash<PropertyName, QVariant> &propertyHash)
{
    QHash<PropertyName, QVariant> auxiliaryData  = node.auxiliaryData();

    foreach (const PropertyName &propertyName, auxiliaryData.keys()) {
        if (node.hasAuxiliaryData(propertyName))
            node.setAuxiliaryData(propertyName, QVariant());
    }

    QHashIterator<PropertyName, QVariant> propertyIterator(propertyHash);
    while (propertyIterator.hasNext()) {
        propertyIterator.next();
        const PropertyName propertyName = propertyIterator.key();
        if (propertyName == "width" || propertyName == "height") {
            node.setAuxiliaryData(propertyIterator.key(), propertyIterator.value());
        } else if (node.property(propertyIterator.key()).isDynamic() &&
                   node.property(propertyIterator.key()).dynamicTypeName() == "alias" &&
                   node.property(propertyIterator.key()).isBindingProperty()) {
            AbstractProperty targetProperty = node.bindingProperty(propertyIterator.key()).resolveToProperty();
            if (targetProperty.isValid())
                targetProperty.parentModelNode().setAuxiliaryData(targetProperty.name() + "@NodeInstance", propertyIterator.value());
        } else {
            node.setAuxiliaryData(propertyIterator.key() + "@NodeInstance", propertyIterator.value());
        }
    }
}
Example #2
0
void demo_1() {

    Player p;
    auto reflection = StructFactory::instance().structByType<Player>();

    std::cout << "\n-----------relection:set ------------\n";
    {
        reflection->set<int>(p, "id", 100);
        reflection->set<std::string>(p, "name", "david");

        std::cout << p.id << std::endl;
        std::cout << p.name << std::endl;
    }

    std::cout << "\n-----------relection:get ------------\n";
    {
        std::cout << reflection->get<int>(p, "id") << std::endl;
        std::cout << reflection->get<std::string>(p, "name") << std::endl;
    }

    std::cout << "\n-----------relection:iteration ------------\n";
    {
        for (auto prop : reflection->propertyIterator()) {
            if (prop->type() == typeid(int))
                std::cout << prop->name() << ":" << reflection->get<int>(p, prop->name()) << std::endl;
            else if (prop->type() == typeid(std::string))
                std::cout << prop->name() << ":" << reflection->get<std::string>(p, prop->name()) << std::endl;
        }
    }
}
Example #3
0
/**
 * @brief Returns the weakest passwort strength of any children of the item.
 *
 * All password strength should be computed because of speed issues (in other
 * words, no wait cursor or something else is displayed in this function).
 *
 * @return the password strength, Property::PUndefined should be never returned
 * @exception PasswordCheckException if recomputing is necessary and the PasswordChecker
 *            threw a PasswordCheckException
 */
Property::PasswordStrength TreeEntry::weakestChildrenPassword() const throw (PasswordCheckException)
{
    Property::PasswordStrength lowest = Property::PUndefined;

    if (m_isCategory) {
        TreeEntry* item = dynamic_cast<TreeEntry*>(firstChild());
        while (item) {
            Property::PasswordStrength strength = item->weakestChildrenPassword();
            if (strength < lowest) {
                lowest = strength;
                if (lowest == Property::PWeak)
                    break;
            }
            item = dynamic_cast<TreeEntry*>(item->nextSibling());
        }
    } else {
        bool hadPasswords = false;
        PropertyIterator it = propertyIterator();
        Property* current;
        while ( (current = it.current()) != 0 ) {
            ++it;
            if (current->getType() == Property::PASSWORD) {
                hadPasswords = true;
                Property::PasswordStrength strength = current->getPasswordStrength();
                if (strength < lowest) {
                    lowest = strength;
                    if (lowest == Property::PWeak)
                        break;
                }
            }
        }
    }

    return lowest;
}
Example #4
0
/**
 * @brief Appends the tree entry as text representation to the given stream.
 *
 * The text is formatted for export.
 *
 * @param stream the stream where the text is appended
 */
void TreeEntry::appendTextForExport(QTextStream& stream)
{
    if (m_isCategory) {
        return;
    }

    QString catString;
    const Q3ListViewItem* item = this;
    while ((item = item->parent())) {
        catString = catString.prepend(dynamic_cast<const TreeEntry*>(item)->getName() + ": ");
    }

    stream << "--------------------------------------------------------------------------------\n";
    stream << catString + m_name << "\n";
    stream << "--------------------------------------------------------------------------------\n";
    stream << "\n";

    PropertyIterator it = propertyIterator();
    Property* current;
    while ((current = it.current()) != 0) {
        ++it;
        current->appendTextForExport(stream);
    }

    stream << "\n\n";
}
Example #5
0
/**
 * @brief This function converts a tree entry to HTML for printing.
 *
 * A TreeEntry represents one big table.
 *
 * @return the RichText
 */
QString TreeEntry::toRichTextForPrint() const
{
    if (m_isCategory)
        return QString("");

    QString catString;


    QString ret;
    ret += QString("<table width=\"100%\"><tr><td bgcolor=grey cellpadding=\"3\">"
            "&nbsp;<b>%1</b></td></tr><tr><td>"
            "<table border=\"0\">").arg(getFullName());

    PropertyIterator it = propertyIterator();
    Property* current;
    while ( (current = it.current()) != 0 ) {
        ++it;
        ret += current->toRichTextForPrint();
    }

    ret += "</table></td></tr></table<p>&nbsp;<p>";
    return ret;
}
void _FSSEnvironment::runStage(const Operation& subject, 
		DynamicArray<StyleTreeNode*>& styleTreePositions,
		HashMap<StyleTreeNode*, bool, HashCollection::pointerHash<StyleTreeNode>,
			HashCollection::pointerMatch<StyleTreeNode>>& styleTreePositionSet,
		Allocator& stackAllocator, FDUint depth) {

#ifdef FD_FSS_DIAGNOSTIC_PRINT
	const char* depthString = "                                         ";
	FDUint depthStringLen = strlen(depthString);
	printf("%s%c/%s\n", depthString + depthStringLen - depth, 
			subject.getName().ownerType, subject.getName().name);
#endif

	int positionsListingStart = styleTreePositions.getSize();
	StyleTree& tree = styleSheet.getTree();
	DynamicArray<StyleTreeNode*> styleTreePositionsToAdd(stackAllocator);
	HashMap<PropertyDef*, void*, HashCollection::pointerHash<PropertyDef>,
			HashCollection::pointerMatch<PropertyDef>> defToProperty(
			stackAllocator);

	// Check the style sheet tree for the properties of the subject.
	{
		Profiler p("FSS check for properties", true);

		Profiler pApplicable("Def Applicable Rules", true);
		DynamicArray<StyleRule*> applicableRules(stackAllocator);
		pApplicable.close();

		// Follow up on rules suggested by the subject.
		// Note that we do not keep such rules in the listing of styleTreePositions
		// - instead we only store multi-atom rules that have a first-atom match.
		{
			Profiler p("FSS check rules", true);

			Array<StyleRule* const> relatedRules = subject.getRelatedRules();
			for (int i = 0; i < relatedRules.length; i++) {
				applicableRules.append(relatedRules[i]);
				Selector& selector = relatedRules[i]->getSelector();
				tree.advanceTopRule(*relatedRules[i], subject, 
						styleTreePositionsToAdd, styleTreePositionSet);
			}
		}

		// Extract properties from the list of rules.
		{
			Profiler p("FSS extract properties", true);

			FDUint ruleCount = applicableRules.getSize();
			for (FDUint i = 0; i < ruleCount; i++) {
				Array<Style> styles = applicableRules[i]->getStyles();

				for (int j = 0; j < styles.length; j++) {
					Style& style = styles[j];
					StyleDef& styleDef = style.getDef();
					PropertyDef& propertyDef = styleDef.getPropertyDef();

					// Create the property if it doesn't already exist.
					void* prop;
					if (!defToProperty.get(&propertyDef, prop)) {
						prop = propertyDef.createProperty(stackAllocator);
						defToProperty[&propertyDef] = prop;
					}

					style.invoke(prop);
				}
			}
		}

		{
			Profiler p("FSS do inline styles.", true);

			Array<const Style> inlineStyles = subject.getInlineStyles();
			FDUint inlineStyleCount = inlineStyles.length;

			for (FDUint i = 0; i < inlineStyleCount; i++) {
				const Style& style = inlineStyles[i];

				StyleDef& styleDef = style.getDef();
				PropertyDef& propertyDef = styleDef.getPropertyDef();

				// Create the property if it doesn't already exist.
				void* prop;
				if (!defToProperty.get(&propertyDef, prop)) {
					Profiler pNF("Not found shit", true);
					prop = propertyDef.createProperty(stackAllocator);
					defToProperty[&propertyDef] = prop;
				}

				Profiler p("Invoke Style", true);
				style.invoke(prop);
			}
		}

		Profiler pC("FSS prop check cleanup.", true);
	}

	
	void* hideVS;
	FDbool hasHideProp = defToProperty.get(environment.hidePDef, hideVS);
	if (!hasHideProp || 
			!((SinglePropertyDef<FDbool>::ValueSpecificity*)hideVS)->value) {

		DoOperation doOp(subject, defToProperty);

		user->onDoOperation(doOp);

		// Recurse on children.
		void* childrenVoid;
		bool hasChildren = defToProperty.get(
				styleSheet.getDefaultDefs().childrenDef, childrenVoid);
		if (hasChildren) {
			Profiler p("FSS Children operations", true);

			DefaultDefCollection::OpSet* children = 
					(DefaultDefCollection::OpSet*)childrenVoid;

			FDUint count = children->getSize();
			OpConstraint* ops = FD_NEW_ARRAY(OpConstraint, count, *allocator, 
					allocator);

			DefaultDefCollection::OpSetIterator childrenIterator(*children);
			Operation* key;
			bool value;
			FDUint i = 0;
			while (childrenIterator.getNext(key, value)) {
				ops[i++].op = key;
			}

			// Set up constraints here
			void* orderVoid;
			bool hasConstraints = defToProperty.get(
					styleSheet.getDefaultDefs().orderDef, orderVoid);
			if (hasConstraints) {
				DefaultDefCollection::ConstraintSet* constraints =
						(DefaultDefCollection::ConstraintSet*)orderVoid;

				// Iterate through constraints.
				DefaultDefCollection::ConstraintSetIterator 
						constraintIterator(*constraints);
				Pair<Selector, Selector>* key;
				bool value;
				while (constraintIterator.getNext(key, value)) {

					// TODO: Make this better. I know this can be better,
					// this is a w f u l.

					// We first obtain a list of the things that are supposed to
					// happen before.
					OpConstraint* priors[100];
					FDUint priorCount = 0;
					for (i = 0; i < count; i++) {
						if (key->first.isAtomMatch(*ops[i].op)) {
							priors[priorCount++] = &ops[i];
						}
					}

					// We then match that list to the things that are supposed to
					// happen after.
					for (i = 0; i < count; i++) {
						if (!key->second.isAtomMatch(*ops[i].op)) {
							continue;
						}

						for (FDUint j = 0; j < priorCount; j++) {

							// We check that i isn't already dependent on j.
							if (ops[i].constraints.contains(priors[j])) {
								continue;
							}

							ops[i].constraints.append(priors[j]);
						}
					}

				}
			}

			p.close();

			// Go through the children, respecting the constraints.
			FDUint renderCount = 0;
			for (i = 0; i < count; i++) {

				FDUint current = i;
				if (!ops[i].alreadyRendered) {
					constraintRecurse(ops[i], styleTreePositions, 
							styleTreePositionSet, stackAllocator, depth);
				}
			}

			FD_FREE(ops, *allocator);
		}

		Profiler p("FSS Undo", true);

		user->onUndoOperation(doOp);
	}

	// Clean up positions listing
	int positionsToAddCount = styleTreePositionsToAdd.getSize();
	for (int i = 0; i < positionsToAddCount; i++) {
		styleTreePositionSet.remove(styleTreePositionsToAdd[i]);
	}

	// Clean up defToProperty listing
	{
		HashMap<PropertyDef*, void*, HashCollection::pointerHash<PropertyDef>,
				HashCollection::pointerMatch<PropertyDef>>::Iterator 
				propertyIterator(defToProperty);
		PropertyDef* key;
		void* value;
		while (propertyIterator.getNext(key, value)) {
			key->deleteProperty(value, stackAllocator);
		}
	}
}