Пример #1
0
QVariant TimeProp::data(const QModelIndex & index)
{
	if (!index.isValid() || !object() || -1 == objectProperty())
		return QVariant();
	switch (index.column())
	{
		case 0:
			return object()->metaObject()->property(objectProperty()).name();
		case 1:
			return value().toTime().toString("hh:mm:ss");
	}
	return QVariant();
}
Пример #2
0
QVariant Font::data(const QModelIndex & index)
{
	if (!index.isValid() || !object() || -1 == objectProperty())
		return QVariant();
	switch (index.column())
	{
		case 0:
			return object()->metaObject()->property(objectProperty()).name();
		case 1:
			return value();
	}
	return QVariant();
}
Пример #3
0
void Enums::setValue(int item)
{
//    PropertyInterface::setValue(cb->itemData(item));
    QVariant data = cb->itemData(item);

    QVariant old_data = object()->metaObject()->property(objectProperty()).read(object());
    QVariant newValue(old_data);
    int * intData = reinterpret_cast<int*>(newValue.data());
    *intData = data.toInt();
    bool ret = object()->metaObject()->property(objectProperty()).write(object(), newValue);

    if (ret)
        emit(propertyChanged(object(), QString(object()->metaObject()->property(objectProperty()).name()), old_data, data));
}
Пример #4
0
QWidget* Enums::createEditor(QWidget * parent, const QModelIndex & index)
{
    Q_UNUSED(index);

    const QMetaObject * metaObject = object()->metaObject();
    QMetaProperty metaProperty = metaObject->property(objectProperty());
    const char *typeName = metaProperty.typeName();
    int enumIdx = metaObject->indexOfEnumerator(typeName);

    QStringList excludeList;

    if (int index = metaObject->indexOfProperty(QString("_%1_exclude").arg(metaProperty.name()).toLatin1())) {
        excludeList = metaObject->property(index).read(object()).toStringList();
    }

    cb = new QComboBox(parent);

    for (int en = 0; en < metaObject->enumerator(enumIdx).keyCount(); ++en) {
        QString itemName = metaObject->enumerator(enumIdx).key(en);
        int itemData = metaObject->enumerator(enumIdx).value(en);
        if (!excludeList.contains(itemName))
            cb->insertItem(en, itemName, itemData);
    }

    connect(cb, SIGNAL(currentIndexChanged(int)), this, SLOT(setValue(int)));

    return cb;
}
Пример #5
0
QVariant Size::data(const QModelIndex & index)
{
	switch (index.column())
	{
		case 0:
			return object()->metaObject()->property(objectProperty()).name();
		case 1:
			return QString("[%1,%2]").arg(value().toSize().width()).arg(value().toSize().height());
	}
	return QVariant();
}
Пример #6
0
QVariant Enums::data(const QModelIndex & index)
{
    const QMetaObject * metaObject = object()->metaObject();
    QMetaProperty metaProperty = metaObject->property(objectProperty());
    const char *typeName = metaProperty.typeName();
    int enumIdx = metaObject->indexOfEnumerator(typeName);

    if (!index.isValid() || !object() || -1 == objectProperty())
        return QVariant();

    switch (index.column())
    {
        case 0:
            return metaProperty.name();
        case 1: {
            return metaObject->enumerator(enumIdx).valueToKey(*reinterpret_cast<int*>(value().data()));
            }
    }
    return QVariant();
}
Пример #7
0
QVariant PointF::data(const QModelIndex & index)
{
	switch (index.column())
	{
		case 0:
			return object()->metaObject()->property(objectProperty()).name();
        case 1:{
                int precision = propertyPrecision();
                return QString("[%1,%2]").arg(value().toPointF().x(), 0, 'f', precision).arg(value().toPointF().y(), 0, 'f', precision);
                }
	}
	return QVariant();
}
Пример #8
0
QVariant Flags::data(const QModelIndex & index)
{
	if (!index.isValid() || !object() || -1 == objectProperty())
		return QVariant();
	switch (index.column())
	{
		case 0:
			return object()->metaObject()->property(objectProperty()).name();

		case 1:
			QString s = "[";
			for (int en = 0;en < object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).keyCount();en++)
				if (value().toInt() & object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).value(en))
				{
					if (s.size() > 1)
						s += QString("|") + QString(object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).key(en));
					else
						s += QString(object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).key(en));
				}
			s += "]";
			return s;
	}
	return QVariant();
}
Пример #9
0
void Flags::buttonPressed()
{
	FlagsList f;
	f.setWindowTitle(QString(object()->metaObject()->property(objectProperty()).name()) + tr(" flags"));
	f.list->clear();

	for (int en = 0;en < object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).keyCount();en++)
	{
		f.list->addItem(object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).key(en));
		f.list->item(en)->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
		f.list->item(en)->setCheckState((value().toInt() & object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).value(en)) ? Qt::Checked : Qt::Unchecked);
	}

	if (f.exec() == QDialog::Rejected)
		return;

	int flags = 0;
	for (int fl = 0;fl < f.list->count();fl++)
		if (f.list->item(fl)->checkState() == Qt::Checked)
			flags |= object()->metaObject()->enumerator(object()->metaObject()->indexOfEnumerator(object()->metaObject()->property(objectProperty()).typeName())).value(fl);

	setValue(flags);
}
Пример #10
0
// ---
void QGAMES::Background::initialize ()
{
	// The initial values...
	int fadeGrade = 255;
	bool autMove = false;
	QGAMES::Vector movDirection (__BD 1, __BD 0, __BD 0);
	int speed = 0, pixels = 0;
	QGAMES::Background* linkedBackground = NULL;
	int linkedSpeed = 0;
	bool roll = false;
	bool fix = false;

	// Has the fasdegrade property been defined?
	if (existObjProperty (_FADEGRADEPROPERTY))
		fadeGrade = std::stoi (objectProperty (_FADEGRADEPROPERTY));

	// Has the automatic movement property been defined?
	if (existObjProperty (_AUTOMATICMOVEPROPERTY))
		autMove = (objectProperty (_AUTOMATICMOVEPROPERTY) == 
			std::string (__YES_STRING__)) ? true : false ;

	// Has the movement direction property been defined?
	if (existObjProperty (_MOVDIRECTIONPROPERTY))
	{
		std::vector <int> cV;
		std::string m = objectProperty (_MOVDIRECTIONPROPERTY);
		while (m != std::string (__NULL_STRING__))
		{
			int cP = m.find_first_of (','); // The vector dta is separated by comma!
			if (cP != -1)
			{
				cV.push_back (std::stoi (m.substr (0, cP)));
				m = (cP != m.length () - 1) 
					? m.substr (cP + 1) : std::string (__NULL_STRING__);
			}
			else
			{
				cV.push_back (std::stoi (m));
				m = std::string (__NULL_STRING__);
			}
		}

		movDirection = QGAMES::Vector ((cV.size () > 0) ? __BD cV [0] : __BD 0,
			(cV.size () > 1) ? __BD cV [1] : __BD 0, (cV.size () > 2) ? __BD cV [2] : __BD 0);
	}

	// Has the speed property been defined?
	if (existObjProperty (_SPEEDPROPERTY))
		speed = std::stoi (objectProperty (_SPEEDPROPERTY));
	// Has the pixels property been defined?
	if (existObjProperty (_PIXELSPROPERTY))
		pixels = std::stoi (objectProperty (_PIXELSPROPERTY));
	
	// Has the background linked been defined?
	if (existObjProperty (_LINKEDBKPROPERTY))
	{
		assert (game ()); // The game has to have been defined...
		linkedBackground = (QGAMES::Background*) game () -> objectBuilder () -> 
			object (std::stoi (objectProperty (_LINKEDBKPROPERTY)));
		linkedBackground -> initialize ();
	}
	
	// Has the speed of the background linked been defined?
	if (existObjProperty (_SPEEDLINKEDBKPROPERTY))
		linkedSpeed = std::stoi (objectProperty (_SPEEDLINKEDBKPROPERTY));

	// Has to roll?
	if (existObjProperty (_ROLLPROPERTY))
		roll = (objectProperty (_ROLLPROPERTY) == 
			std::string (__YES_STRING__)) ? true : false ;

	// The position is fixed?
	if (existObjProperty (_FIXPOSITIONPROPERTY))
		fix = (objectProperty (_FIXPOSITIONPROPERTY) == 
			std::string (__YES_STRING__)) ? true : false ;

	// The background is a mandatory attribute...
	// Sets the fadegrade
	setFade (fadeGrade);
	// Sets the movement
	setMove (autMove, movDirection);
	// Sets the movement data
	setMovementData (speed, pixels);
	// Sets the linked background if any...
	setLinkedBackground (linkedSpeed, linkedBackground);
	// Sets whether it rolls or not!
	setRoll (roll);
	// Sets whether the position is or not fix...
	setFixPosition (fix);

	// Restats the counters...
	reStartAllCounters ();

	// Initially the position of the background is to 0...
	setPosition (QGAMES::Position::_cero);
}
Пример #11
0
int PointF::_current_property_precision()
{
    object()->setProperty("_current_property", objectProperty());
    return object()->property("_current_property_precision").toInt();
}