Ejemplo n.º 1
0
void ShaderEffectItem::connectPropertySignals()
{
    QSet<QByteArray>::const_iterator it;
    for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) {
        int pi = metaObject()->indexOfProperty(it->constData());
        if (pi >= 0) {
            QMetaProperty mp = metaObject()->property(pi);
            if (!mp.hasNotifySignal())
                qWarning("ShaderEffectItem: property '%s' does not have notification method!", it->constData());
            QByteArray signalName("2");
            signalName.append(mp.notifySignal().signature());
            connect(this, signalName, this, SLOT(markDirty()));
        } else {
            qWarning("ShaderEffectItem: '%s' does not have a matching property!", it->constData());
        }
    }
    for (int i = 0; i < m_sources.size(); ++i) {
        SourceData &source = m_sources[i];
        int pi = metaObject()->indexOfProperty(source.name.constData());
        if (pi >= 0) {
            QMetaProperty mp = metaObject()->property(pi);
            QByteArray signalName("2");
            signalName.append(mp.notifySignal().signature());
            connect(this, signalName, source.mapper, SLOT(map()));
            source.mapper->setMapping(this, i);
            connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
        } else {
Ejemplo n.º 2
0
qObjectnode::
qObjectnode(QObject *data, QGraphicsItem *parent, bool autodelete) : GraphicsNode(parent),m_autodelete(autodelete)
{
	m_data=data;
	if(m_data==0)
		qWarning("NULL Data Object!");
	else {
		QWidget* tst = dynamic_cast<QWidget*>(data);
		if(tst!=0)
			setCentralWidget(tst);

		const QMetaObject* m = m_data->metaObject();
		int property_count = m->propertyCount()-1;

		for(;property_count>=0;property_count--) {
			QMetaProperty prop = m->property(property_count);
			if(prop.isConstant() || !prop.isUser())
				continue;
			if(prop.isReadable() && prop.hasNotifySignal())
			{
				add_source(QString(prop.name()) + "[" +QString(prop.typeName())  +"]",m_data,property_count);
			}
			if(prop.isWritable())
				add_sink(QString(prop.name()) + "[" +QString(prop.typeName())  +"]",m_data,property_count);
		}
	}
}
void QConnectedReplicaPrivate::initializeMetaObject(const QMetaObjectBuilder &builder, const QVariantList &values)
{
    QRemoteObjectReplicaPrivate::initializeMetaObject(builder, values);
    foreach (QRemoteObjectReplica *obj, m_parentsNeedingConnect)
        configurePrivate(obj);
    m_parentsNeedingConnect.clear();

    //initialized and validChanged need to be sent manually, since they are not in the derived classes
    //We should emit initialized before emitting any changed signals in case connections are made in a
    //Slot responding to initialized/validChanged.
    if (isSet.fetchAndStoreRelease(2) > 0) {
        //We are already initialized, now we are valid again
        emitValidChanged();
    } else {
        //We need to send the initialized signal, too
        emitInitialized();
        emitValidChanged();
    }

    void *args[] = {Q_NULLPTR, Q_NULLPTR};
    for (int index = m_metaObject->propertyOffset(); index < m_metaObject->propertyCount(); ++index) {
        const QMetaProperty mp = m_metaObject->property(index);
        if (mp.hasNotifySignal()) {
            qCDebug(QT_REMOTEOBJECT) << " Before activate" << index << m_metaObject->property(index).name();
            args[1] = this->m_propertyStorage[index-m_propertyOffset].data();
            QMetaObject::activate(this, metaObject(), mp.notifySignalIndex(), args);
        }
    }

    qCDebug(QT_REMOTEOBJECT) << "isSet = true for" << m_objectName;
}
Ejemplo n.º 4
0
QBinding::QBinding(const QObject *sourceObject, const char *sourcePropertyName, QState *state, QObject *targetObject, const char *targetPropertyName)
{
    qimsysDebugIn() << sourceObject << sourcePropertyName << state << targetObject << targetPropertyName;
    d = new Private;
    if (!sourceObject || !sourcePropertyName || !targetObject || !targetPropertyName) {
        qWarning() << sourceObject << sourcePropertyName << targetObject << targetPropertyName;
        deleteLater();
        qimsysDebugOut();
        return;
    }
    d->sourceObject = sourceObject;
    d->sourcePropertyName = sourcePropertyName;
    d->state = state;
    d->targetObject = targetObject;
    d->targetPropertyName = targetPropertyName;

    const QMetaObject *sourceMetaObject = sourceObject->metaObject();
    int sourcePropertyIndex = sourceMetaObject->indexOfProperty(sourcePropertyName);
    QMetaProperty sourceProperty = d->sourceObject->metaObject()->property(sourcePropertyIndex);
    if (sourceProperty.hasNotifySignal()) {
        connect(sourceObject, QByteArray("2") + sourceProperty.notifySignal().methodSignature(), this, SLOT(setProperty()));
    } else {
        qWarning() << sourceObject <<  "doesn't notify change for" << sourcePropertyName;
        deleteLater();
    }

    connect(sourceObject, SIGNAL(destroyed()), this, SLOT(deleteLater()));
    connect(state, SIGNAL(destroyed()), this, SLOT(deleteLater()));
    connect(targetObject, SIGNAL(destroyed()), this, SLOT(deleteLater()));

    setProperty();
    qimsysDebugOut();
}
Ejemplo n.º 5
0
void QQuickShaderEffectCommon::connectPropertySignals(QQuickItem *item, Key::ShaderType shaderType)
{
    for (int i = 0; i < uniformData[shaderType].size(); ++i) {
        if (signalMappers[shaderType].at(i) == 0)
            continue;
        const UniformData &d = uniformData[shaderType].at(i);
        int pi = item->metaObject()->indexOfProperty(d.name.constData());
        if (pi >= 0) {
            QMetaProperty mp = item->metaObject()->property(pi);
            if (!mp.hasNotifySignal())
                qWarning("QQuickShaderEffect: property '%s' does not have notification method!", d.name.constData());
            const QByteArray signalName = '2' + mp.notifySignal().methodSignature();
            QSignalMapper *mapper = signalMappers[shaderType].at(i);
            QObject::connect(item, signalName, mapper, SLOT(map()));
            QObject::connect(mapper, SIGNAL(mapped(int)), item, SLOT(propertyChanged(int)));
        } else {
            // If the source is set via a dynamic property, like the layer is, then we need this
            // check to disable the warning.
            if (!item->property(d.name.constData()).isValid())
                qWarning("QQuickShaderEffect: '%s' does not have a matching property!", d.name.constData());
        }

        if (d.specialType == UniformData::Sampler) {
            QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value));
            if (source) {
                if (item->window())
                    QQuickItemPrivate::get(source)->refWindow(item->window());
                QObject::connect(source, SIGNAL(destroyed(QObject*)), item, SLOT(sourceDestroyed(QObject*)));
            }
        }
    }
}
Ejemplo n.º 6
0
void StelAction::connectToObject(QObject* obj, const char* slot)
{
	target = obj;
	QVariant prop = obj->property(slot);
	if (prop.isValid()) // Connect to a bool property, use a StelProperty if possible
	{
		Q_ASSERT(prop.type() == QVariant::Bool);

		// Listen to the property notified signal if there is one.
		int propIndex = obj->metaObject()->indexOfProperty(slot);
		QMetaProperty metaProp = obj->metaObject()->property(propIndex);

		//can use a StelProperty for the connection, property name is action name
		boolProperty = StelApp::getInstance().getStelPropertyManager()->registerProperty(objectName(),obj,slot);
		StelPropertyBoolProxy* prox = new StelPropertyBoolProxy(boolProperty,this);
		connect(prox,SIGNAL(propertyChanged(bool)),this,SLOT(propertyChanged(bool)));

		if(!metaProp.hasNotifySignal())
		{
			//warn about missing notify
			qWarning()<<"[StelAction]"<<getId()<<"is connected to property"<<slot<<"of object"<<obj<<" without a NOTIFY signal";
		}

		return;
	}
Ejemplo n.º 7
0
DialogCallbacks::DialogCallbacks(QWidget* dialog, QDeclarativeView* declarative, QObject* view) :
    QObject(dialog),
    m_dialog(dialog),
    m_declarative(declarative),
    m_view(view)
{
    int index = view->metaObject()->indexOfProperty("dialogFullScreen");
    if (index != -1)
    {
        QMetaProperty metaProperty = view->metaObject()->property(index);
        if (metaProperty.hasNotifySignal())
        {
            QMetaObject::connect(view, metaProperty.notifySignalIndex(),
                                 this, metaObject()->indexOfSlot("viewFullScreenChanged()"));
        }
    }

    index = view->metaObject()->indexOfSignal("dialogCloseRequested()");
    if (index != -1)
        QObject::connect(view, SIGNAL(dialogCloseRequested()), dialog, SLOT(close()));

    index = view->metaObject()->indexOfProperty("width");
    if (index != -1)
    {
        QMetaProperty metaProperty = view->metaObject()->property(index);
        if (metaProperty.hasNotifySignal())
        {
            QMetaObject::connect(view, metaProperty.notifySignalIndex(),
                                 this, metaObject()->indexOfSlot("widthChanged()"));
        }
    }

    index = view->metaObject()->indexOfProperty("height");
    if (index != -1)
    {
        QMetaProperty metaProperty = view->metaObject()->property(index);
        if (metaProperty.hasNotifySignal())
        {
            QMetaObject::connect(view, metaProperty.notifySignalIndex(),
                                 this, metaObject()->indexOfSlot("heightChanged()"));
        }
    }

    dialog->installEventFilter(this);
}
QVariant ObjectStaticPropertyModel::data(const QModelIndex &index, int role) const
{
  if (!index.isValid() || !m_obj || index.row() < 0 ||
      index.row() >= m_obj.data()->metaObject()->propertyCount()) {
    return QVariant();
  }

  const QMetaProperty prop = m_obj.data()->metaObject()->property(index.row());
  if (role == Qt::DisplayRole) {
    if (index.column() == 0) {
      return prop.name();
    } else if (index.column() == 1) {
      // QMetaProperty::read sets QVariant::typeName to int for enums,
      // so we need to handle that separately here
      const QVariant value = prop.read(m_obj.data());
      const QString enumStr = Util::enumToString(value, prop.typeName(), m_obj.data());
      if (!enumStr.isEmpty()) {
        return enumStr;
      }
      return VariantHandler::displayString(value);
    } else if (index.column() == 2) {
      return prop.typeName();
    } else if (index.column() == 3) {
      const QMetaObject *mo = m_obj.data()->metaObject();
      while (mo->propertyOffset() > index.row()) {
        mo = mo->superClass();
      }
      return mo->className();
    }
  } else if (role == Qt::DecorationRole) {
    if (index.column() == 1) {
      return VariantHandler::decoration(prop.read(m_obj.data()));
    }
  } else if (role == Qt::EditRole) {
    if (index.column() == 1) {
      return prop.read(m_obj.data());
    }
  } else if (role == Qt::ToolTipRole) {
    const QString toolTip =
      tr("Constant: %1\nDesignable: %2\nFinal: %3\nResetable: %4\n"
         "Has notification: %5\nScriptable: %6\nStored: %7\nUser: %8\nWritable: %9").
      arg(translateBool(prop.isConstant())).
      arg(translateBool(prop.isDesignable(m_obj.data()))).
      arg(translateBool(prop.isFinal())).
      arg(translateBool(prop.isResettable())).
      arg(translateBool(prop.hasNotifySignal())).
      arg(translateBool(prop.isScriptable(m_obj.data()))).
      arg(translateBool(prop.isStored(m_obj.data()))).
      arg(translateBool(prop.isUser(m_obj.data()))).
      arg(translateBool(prop.isWritable()));
    return toolTip;
  }

  return QVariant();
}
Ejemplo n.º 9
0
PropertyField::PropertyField(QObject* subject, const QMetaProperty& prop, QWidget *parent) :
    QLineEdit(parent), m_subject(subject), m_lastChangeTime(QTime::currentTime()), m_prop(prop)
{
    setReadOnly(true);
    if (prop.hasNotifySignal()) {
        QMetaMethod signal = prop.notifySignal();
        QMetaMethod updateSlot = metaObject()->method(metaObject()->indexOfSlot("propertyChanged()"));
        connect(m_subject, signal, this, updateSlot);
    }
    propertyChanged();
}
Ejemplo n.º 10
0
void PropertyEditor::Private::monitorElement(KDSME::Element* element)
{
    if (!element)
        return;

    for (int i = 0; i < element->metaObject()->propertyCount(); ++i) {
        const QMetaProperty prop = element->metaObject()->property(i);
        if (!prop.hasNotifySignal())
            continue;
        q->connect(element, "2" + prop.notifySignal().methodSignature(), q, SLOT(loadFromCurrentElement())); //krazy:exclude=doublequote_chars
    }
}
Ejemplo n.º 11
0
/*!
    Connects the property's change notifier signal to the
    specified \a method of the \a dest object and returns
    true. Returns false if this metaproperty does not
    represent a regular Qt property or if it has no
    change notifier signal, or if the \a dest object does
    not have the specified \a method.
*/
bool QDeclarativeProperty::connectNotifySignal(QObject *dest, int method) const
{
    if (!(type() & Property) || !d->object)
        return false;

    QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex);
    if (prop.hasNotifySignal()) {
        return QMetaObject::connect(d->object, prop.notifySignalIndex(), dest, method, Qt::DirectConnection);
    } else {
        return false;
    }
}
Ejemplo n.º 12
0
void QmlProfilerCanvas::componentComplete()
{
    const QMetaObject *metaObject = this->metaObject();
    int propertyCount = metaObject->propertyCount();
    int requestPaintMethod = metaObject->indexOfMethod("requestPaint()");
    for (int ii = QmlProfilerCanvas::staticMetaObject.propertyCount(); ii < propertyCount; ++ii) {
        QMetaProperty p = metaObject->property(ii);
        if (p.hasNotifySignal())
            QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
    }
    QDeclarativeItem::componentComplete();
}
Ejemplo n.º 13
0
/*!
   \brief TreeModel::connectProperty
    If \a property has got a notify signal, it will be connected to
    TreeModel::itemChanged( QStandardItem *item ).
 */
void TreeModel::connectProperty( QObject* object,
                                 const QMetaProperty& metaProperty,
                                 QStandardItem* item )
{
    Q_ASSERT( object );
    if ( metaProperty.hasNotifySignal() )
    {
        int index = object->metaObject()->indexOfProperty( metaProperty.name() );
        m_propertyIndexToItemMap.insert( index, item );
        QMetaMethod signal = metaProperty.notifySignal();
        connect( object, signal, this, m_updateSlot );
    }
}
Ejemplo n.º 14
0
/*!
    Connects the property's change notifier signal to the
    specified \a slot of the \a dest object and returns
    true. Returns false if this metaproperty does not
    represent a regular Qt property or if it has no
    change notifier signal, or if the \a dest object does
    not have the specified \a slot.
*/
bool QDeclarativeProperty::connectNotifySignal(QObject *dest, const char *slot) const
{
    if (!(type() & Property) || !d->object)
        return false;

    QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex);
    if (prop.hasNotifySignal()) {
        QByteArray signal(QByteArray("2") + prop.notifySignal().signature());
        return QObject::connect(d->object, signal.constData(), dest, slot);
    } else  {
        return false;
    }
}
Ejemplo n.º 15
0
void    Properties::monitorStaticProperties( )
{
    if ( getTarget() == nullptr )
        return;
    int staticPropertyCount = getTarget()->metaObject( )->propertyCount( );
    QMetaMethod propertiesModifiedSlot = getTarget()->metaObject( )->method( metaObject( )->indexOfSlot( "propertyChanged()" ) );
    for ( int p = 0; p < staticPropertyCount; p++ ) {
        QMetaProperty staticProperty = getTarget()->metaObject( )->property( p );
        if ( staticProperty.hasNotifySignal( ) ) {
            QMetaMethod propertyNotifySignal = staticProperty.notifySignal( );
            connect( this, propertyNotifySignal, this, propertiesModifiedSlot, Qt::UniqueConnection );
        }
    }
}
void NodeInstanceSignalSpy::registerObject(QObject *spiedObject, const PropertyName &prefix)
{
    if (m_registeredObjectList.contains(spiedObject)) // prevent cycles
        return;

    m_registeredObjectList.append(spiedObject);
    for (int index = QObject::staticMetaObject.propertyOffset();
         index < spiedObject->metaObject()->propertyCount();
         index++) {
             QMetaProperty metaProperty = spiedObject->metaObject()->property(index);

             // handle dot properties and connect the signals to the object
             if (metaProperty.isReadable()
                 && !metaProperty.isWritable()
                 && QDeclarativeMetaType::isQObject(metaProperty.userType())) {
                  QObject *propertyObject = QDeclarativeMetaType::toQObject(metaProperty.read(spiedObject));
                  if (propertyObject)
                      registerObject(propertyObject, prefix + metaProperty.name() + '.');
             } else if (metaProperty.hasNotifySignal()) {
                 QMetaMethod metaMethod = metaProperty.notifySignal();
                 bool isConnecting = QMetaObject::connect(spiedObject, metaMethod.methodIndex(), this, methodeOffset, Qt::DirectConnection);
                 Q_ASSERT(isConnecting);
                 Q_UNUSED(isConnecting);
                 m_indexPropertyHash.insert(methodeOffset, prefix + metaProperty.name());
                 methodeOffset++;
             }

             // search recursive in objects
             if (metaProperty.isReadable()
                 && metaProperty.isWritable()
                 && QDeclarativeMetaType::isQObject(metaProperty.userType())) {
                 QObject *propertyObject = QDeclarativeMetaType::toQObject(metaProperty.read(spiedObject));
                 if (propertyObject)
                     registerObject(propertyObject, prefix + metaProperty.name() + '/');
             }

             // search recursive in objects list
             if (metaProperty.isReadable()
                 && QDeclarativeMetaType::isList(metaProperty.userType())) {
                 QDeclarativeListReference list(spiedObject, metaProperty.name());
                 if (list.canCount() && list.canAt()) {
                     for (int i = 0; i < list.count(); i++) {
                         QObject *propertyObject = list.at(i);
                         if (propertyObject)
                             registerObject(propertyObject, prefix + metaProperty.name() + '/');
                     }
                 }
             }
         }
}
Ejemplo n.º 17
0
QWidget*
GooeyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
	const QAbstractItemModel* model = index.model();
	QVariant data = model->data(index, Qt::EditRole);

	QWidget* result = K_NULL;

	// Static types...
    switch(data.type())
	{
	case QMetaType::Bool:
		result = new GooeyCheckBox(parent);
		break;
	case QMetaType::Double:
	case QMetaType::Float:
		result = new GooeyDoubleSpinBox(parent);
		break;
	case QMetaType::Int:
		result = new GooeySpinBox(parent);
		break;
	case QMetaType::UInt:
		result = new GooeySpinBox(parent);
		static_cast<GooeySpinBox*>(result)->minimum(0); // Unsigned integer !
		break;
	case QMetaType::QString:
		result = new GooeyLineEdit(parent);
		break;
	default:
		result = QStyledItemDelegate::createEditor(parent, option, index);
		break;
	}

	QMetaProperty property = result->metaObject()->userProperty();
	if(property.hasNotifySignal())
	{
		connect(result, SIGNAL(destroyed(QObject*)), SLOT(editorDestroyed(QObject*)));
		_mapper->setMapping(result, result);
		const int index = _mapper->metaObject()->indexOfMethod(QMetaObject::normalizedSignature("map()"));
		Q_ASSERT( index != -1 );
		connect(result, property.notifySignal(), _mapper, _mapper->metaObject()->method(index));
	}
	else
	{
		qWarning("GooeyItemDelegate: The editor widget %s has no notify signal on its USER property!", result->metaObject()->className());
	}

	return result;
}
void ObjectStaticPropertyModel::monitorObject(QObject* obj)
{
  for (int i = 0; i < obj->metaObject()->propertyCount(); ++i) {
    const QMetaProperty prop = obj->metaObject()->property(i);
    if (prop.hasNotifySignal()) {
      connect(obj, QByteArray("2") +
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
      prop.notifySignal().signature()
#else
      prop.notifySignal().methodSignature()
#endif
      , this, SLOT(propertyUpdated()));
      m_notifyToPropertyMap.insert(prop.notifySignalIndex(), i);
    }
  }
}
Ejemplo n.º 19
0
QVariant ObjectStaticPropertyModel::data(const QModelIndex &index, int role) const
{
  if (!index.isValid() || !m_obj || index.row() < 0 ||
      index.row() >= m_obj.data()->metaObject()->propertyCount()) {
    return QVariant();
  }

  const QMetaProperty prop = m_obj.data()->metaObject()->property(index.row());
  if (role == Qt::DisplayRole) {
    if (index.column() == 0) {
      return prop.name();
    } else if (index.column() == 1) {
      return Util::variantToString(prop.read(m_obj.data()));
    } else if (index.column() == 2) {
      return prop.typeName();
    } else if (index.column() == 3) {
      const QMetaObject *mo = m_obj.data()->metaObject();
      while (mo->propertyOffset() > index.row()) {
        mo = mo->superClass();
      }
      return mo->className();
    }
  } else if (role == Qt::EditRole) {
    if (index.column() == 1) {
      return prop.read(m_obj.data());
    }
  } else if (role == Qt::ToolTipRole) {
    const QString toolTip =
      tr("Constant: %1\nDesignable: %2\nFinal: %3\nResetable: %4\n"
         "Has notification: %5\nScriptable: %6\nStored: %7\nUser: %8\nWritable: %9").
      arg(translateBool(prop.isConstant())).
      arg(translateBool(prop.isDesignable(m_obj.data()))).
      arg(translateBool(prop.isFinal())).
      arg(translateBool(prop.isResettable())).
      arg(translateBool(prop.hasNotifySignal())).
      arg(translateBool(prop.isScriptable(m_obj.data()))).
      arg(translateBool(prop.isStored(m_obj.data()))).
      arg(translateBool(prop.isUser(m_obj.data()))).
      arg(translateBool(prop.isWritable()));
    return toolTip;
  }

  return QVariant();
}
Ejemplo n.º 20
0
bool
CQmlViewer::connectToChangeNotify(QObject *item, const QString &propName,
                                  QObject *receiver, const char *slotName)
{
    bool rv = false;
    do {
        const QMetaObject *metaObject = item->metaObject ();
        if (NULL == metaObject) {
            Q_WARN("NULL metaObject");
            break;
        }

        QMetaProperty metaProp;
        for (int i = 0; i < metaObject->propertyCount (); i++) {
            metaProp = metaObject->property (i);
            if (metaProp.name () == propName) {
                rv = true;
                break;
            }
        }

        if (!rv) {
            Q_WARN(QString("Couldn't find property named %1").arg(propName));
            break;
        }
        rv = false;

        if (!metaProp.hasNotifySignal ()) {
            Q_WARN(QString("Property %1 does not have a notify signal")
                   .arg(propName));
            break;
        }

        QString signalName = metaProp.notifySignal().methodSignature();
        signalName = "2" + signalName;

        Q_DEBUG(QString("Connect %1 to %2").arg(signalName).arg(slotName));

        rv =
        connect(item, signalName.toLatin1().constData(), receiver, slotName);
    } while(0);

    return (rv);
}//CQmlViewer::connectToChangeNotify
ObjectMapperForwarder::ObjectMapperForwarder(ObjectMapper *m, QObject *o) :
    QObject(m),
    m_mapper(m),
    m_source(o)
{
    for (int i = 0; i < o->metaObject()->propertyCount(); ++i) {
            
        QMetaProperty property = o->metaObject()->property(i);
            
        if (!property.isStored() ||
            !property.isReadable() ||
            !property.isWritable()) {
            continue;
        }
            
        if (!property.hasNotifySignal()) {
            DEBUG << "ObjectMapperForwarder: No notify signal for property " << property.name() << endl;
            continue;
        }
        
        // Signals can be connected to slots with fewer arguments, so
        // long as the arguments they do have match.  So we connect
        // the property notify signal to our universal
        // property-changed slot, and use the sender() of that to
        // discover which object's property has changed.
        // Unfortunately, we don't then know which property it was
        // that changed, as the identity of the signal that activated
        // the slot is not available to us.  The annoying part of this
        // is that Qt does actually store the identity of the signal
        // in the same structure as used for the sender() object data;
        // it just doesn't (at least as of Qt 4.5) make it available
        // through the public API.

        QString sig = QString("%1%2").arg(QSIGNAL_CODE)
            .arg(property.notifySignal().methodSignature().data());
        QByteArray ba = sig.toLocal8Bit();
        
        if (!connect(o, ba.data(), this, SLOT(objectModified()))) {
            std::cerr << "ObjectMapperForwarder: Failed to connect notify signal" << std::endl;
        }
    }
    
    connect(o, SIGNAL(destroyed(QObject *)), this, SLOT(objectDestroyed()));
}
Ejemplo n.º 22
0
const char *SettingsWidget::lookForWidgetState(QWidget *widget, const char *property, const char *signal)
{
	const QMetaObject *meta = widget->metaObject();
	WidgetInfo info = { widget, NULL, QVariant(), false };
	bool free_signal = false;
	// Firstly try to search this widget in predefined classes
	if (!signal && !property) {
		for (int i = 0, size = sizeof(widget_infos) / sizeof(AbstractWidgetInfo*); i < size; i++) {
			if (widget_infos[i]->handle(widget)) {
				info.property = widget_infos[i]->property;
				signal = widget_infos[i]->signal;
				break;
			}
		}
	}
	// Then try to find "User" property with signal or signal by property
	if (!signal) {
		for (int i = 0, size = meta->propertyCount(); i < size; i++) {
			QMetaProperty prop = meta->property(i);
			if (prop.hasNotifySignal()
				&& ((property && !qstrcmp(prop.name(), property))
					|| (!property && prop.isUser()))) {
				info.property = prop.name();
				const char *sig = prop.notifySignal().signature();
				int len = strlen(sig);
				char *str = (char *)qMalloc(sizeof(char) * (len + 2));
				str[0] = QSIGNAL_CODE;
				qstrcpy(str + 1, sig);
				signal = str;
				free_signal = true;
				break;
			}
		}
	}
	bool result(signal);
	if (result) {
		p->mapper->setMapping(widget, p->infos.size());
		connect(widget, signal, p->mapper, SLOT(map()));
		p->infos << info;
	}
	if (free_signal)
		qFree((void *)signal);
	return result ? info.property : 0;
}
Ejemplo n.º 23
0
QString QMetaPropertyAdaptor::detailString(const QMetaProperty &prop) const
{
    QObject *obj = object().qtObject();
    QStringList s;
    s << tr("Constant: %1").arg(translateBool(prop.isConstant()));
    s << tr("Designable: %1").arg(translateBool(prop.isDesignable(obj)));
    s << tr("Final: %1").arg(translateBool(prop.isFinal()));
    if (prop.hasNotifySignal())
        s << tr("Notification: %1").arg(Util::prettyMethodSignature(prop.notifySignal()));
    else
        s << tr("Notification: no");
    s << tr("Resetable: %1").arg(translateBool(prop.isResettable()));
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
    s << tr("Revision: %1").arg(prop.revision());
#endif
    s << tr("Scriptable: %1").arg(translateBool(prop.isScriptable(obj)));
    s << tr("Stored: %1").arg(translateBool(prop.isStored(obj)));
    s << tr("User: %1").arg(translateBool(prop.isUser(obj)));
    s << tr("Writable: %1").arg(translateBool(prop.isWritable()));
    return s.join(QStringLiteral("\n"));
}
QString ObjectStaticPropertyModel::detailString(const QMetaProperty& prop) const
{
  QStringList s;
  s << tr("Constant: %1").arg(translateBool(prop.isConstant()));
  s << tr("Designable: %1").arg(translateBool(prop.isDesignable(m_obj.data())));
  s << tr("Final: %1").arg(translateBool(prop.isFinal()));
  if (prop.hasNotifySignal()) {
    s << tr("Notification: %1").arg(Util::prettyMethodSignature(prop.notifySignal()));
  } else {
    s << tr("Notification: no");
  }
  s << tr("Resetable: %1").arg(translateBool(prop.isResettable()));
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
  s << tr("Revision: %1").arg(prop.revision());
#endif
  s << tr("Scriptable: %1").arg(translateBool(prop.isScriptable(m_obj.data())));
  s << tr("Stored: %1").arg(translateBool(prop.isStored(m_obj.data())));
  s << tr("User: %1").arg(translateBool(prop.isUser(m_obj.data())));
  s << tr("Writable: %1").arg(translateBool(prop.isWritable()));
  return s.join("\n");
}
Ejemplo n.º 25
0
void DecorationShadowTest::testSizes()
{
    using namespace KDecoration2;
    DecorationShadow shadow;

    QFETCH(QByteArray, propertyName);

    const int propertyIndex = shadow.metaObject()->indexOfProperty(propertyName.constData());
    QVERIFY(propertyIndex != -1);
    QMetaProperty metaProperty = shadow.metaObject()->property(propertyIndex);
    QCOMPARE(metaProperty.isReadable(), true);
    QCOMPARE(metaProperty.hasNotifySignal(), true);
    QCOMPARE(metaProperty.type(), QVariant::Rect);
    QSignalSpy changedSpy(&shadow, SIGNAL(innerShadowRectChanged()));
    QVERIFY(changedSpy.isValid());

    QCOMPARE(shadow.innerShadowRect(), QRect());
    QCOMPARE(shadow.property(propertyName.constData()).isValid(), true);
    QCOMPARE(shadow.property(propertyName.constData()).toRect(), QRect());
    QFETCH(QRect, innerShadowRect);
    QFETCH(QRect, shadowRect);
    QFETCH(QSize, shadowSize);
    shadow.setInnerShadowRect(innerShadowRect);
    QCOMPARE(shadow.innerShadowRect(), innerShadowRect);
    // property should still be invalid as the image is not yet set
    QCOMPARE(shadow.property(propertyName.constData()).toRect(), QRect());
    shadow.setShadow(QImage(shadowSize, QImage::Format_ARGB32));
    QCOMPARE(shadow.property(propertyName.constData()).toRect(), shadowRect);
    QCOMPARE(changedSpy.count(), 1);

    // trying to set to same value shouldn't emit the signal
    shadow.setInnerShadowRect(innerShadowRect);
    QCOMPARE(shadow.property(propertyName.constData()).toRect(), shadowRect);
    QCOMPARE(changedSpy.count(), 1);

    // changing to different value should emit signal
    shadow.setInnerShadowRect(innerShadowRect.adjusted(1, 1, 1, 1));
    QCOMPARE(changedSpy.count(), 2);
    QCOMPARE(shadow.innerShadowRect(), innerShadowRect.adjusted(1, 1, 1, 1));
}
Ejemplo n.º 26
0
void PropertyWidget::setData(Kore::data::Block* block, kint propertyIndex)
{
	_block = block;
	_propertyIndex = propertyIndex;

	QMetaProperty property = _block->metaObject()->property(_propertyIndex);
	if(property.hasNotifySignal())
	{
		static const int slotIndex = staticMetaObject.indexOfMethod(QMetaObject::normalizedSignature("update()"));
		Q_ASSERT(slotIndex != -1);
		connect(_block, property.notifySignal(), this, staticMetaObject.method(slotIndex));
	}
	else
	{
		qWarning(
				"%s / Block %s's property %s has no notify signal, it won't be updated!",
				__FUNCTION__,
				qPrintable(block->objectClassName()),
				property.name()
			);
	}
}
Ejemplo n.º 27
0
void QMetaPropertyAdaptor::doSetObject(const ObjectInstance& oi)
{
    auto mo = oi.metaObject();
    if (!mo || oi.type() != ObjectInstance::QtObject || !oi.qtObject())
        return;

    connect(oi.qtObject(), SIGNAL(destroyed(QObject*)), this, SIGNAL(objectInvalidated()));

    for (int i = 0; i < mo->propertyCount(); ++i) {
        const QMetaProperty prop = mo->property(i);
        if (prop.hasNotifySignal()) {
            connect(oi.qtObject(), QByteArray("2") +
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
                prop.notifySignal().signature()
#else
                prop.notifySignal().methodSignature()
#endif
                , this, SLOT(propertyUpdated()));
            m_notifyToPropertyMap.insert(prop.notifySignalIndex(), i);
        }
    }
}
Ejemplo n.º 28
0
void QDeclarativeVMEMetaObject::connectAlias(int aliasId)
{
    if (!aConnected.testBit(aliasId)) {
        aConnected.setBit(aliasId);

        QDeclarativeContext *context = ctxt->asQDeclarativeContext();
        QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(context);

        QDeclarativeVMEMetaData::AliasData *d = metaData->aliasData() + aliasId;

        QObject *target = ctxtPriv->data->idValues[d->contextIdx].data();
        if (!target) 
            return;

        int sigIdx = methodOffset + aliasId + metaData->propertyCount;
        QMetaObject::connect(context, d->contextIdx + ctxtPriv->notifyIndex, object, sigIdx);

        if (!d->isObjectAlias()) {
            QMetaProperty prop = target->metaObject()->property(d->propertyIndex());
            if (prop.hasNotifySignal())
                QDeclarativePropertyPrivate::connect(target, prop.notifySignalIndex(), object, sigIdx);
        }
    }
}
Ejemplo n.º 29
0
void DecorationShadowTest::testPadding()
{
    using namespace KDecoration2;
    DecorationShadow shadow;

    QFETCH(QByteArray, propertyName);

    const int propertyIndex = shadow.metaObject()->indexOfProperty(propertyName.constData());
    QVERIFY(propertyIndex != -1);
    QMetaProperty metaProperty = shadow.metaObject()->property(propertyIndex);
    QCOMPARE(metaProperty.isReadable(), true);
    QCOMPARE(metaProperty.hasNotifySignal(), true);
    QCOMPARE(metaProperty.type(), QVariant::Int);
    QSignalSpy changedSpy(&shadow, SIGNAL(paddingChanged()));
    QVERIFY(changedSpy.isValid());

    QCOMPARE(shadow.property(propertyName.constData()).isValid(), true);
    QCOMPARE(shadow.property(propertyName.constData()).toInt(), 0);
    QFETCH(QMargins, padding);
    shadow.setPadding(padding);
    QCOMPARE(shadow.padding(), padding);
    QCOMPARE(shadow.property(propertyName.constData()).toInt(), 10);
    QCOMPARE(changedSpy.count(), 1);

    // trying to set to same value shouldn't emit the signal
    shadow.setPadding(padding);
    QCOMPARE(shadow.property(propertyName.constData()).toInt(), 10);
    QCOMPARE(changedSpy.count(), 1);

    // changing to different value should emit signal
    padding += 1;
    shadow.setPadding(padding);
    QCOMPARE(shadow.padding(), padding);
    QCOMPARE(shadow.property(propertyName.constData()).toInt(), 11);
    QCOMPARE(changedSpy.count(), 2);
}
void QJnextMainLoop::introspect(QObject *object, QVariantList& args,
		QByteArray* retval) {
	const QMetaObject * meta = object->metaObject();

	QVariantMap data;
	QVariantList properties;
	for (int i = 0; i < meta->propertyCount(); ++i) {
		QVariantMap propData;
		QMetaProperty prop = meta->property(i);

		propData["name"] = prop.name();
		propData["type"] = prop.typeName();
		if (!prop.isReadable()) {
			if (!prop.isWritable())
				continue;
			propData["writeOnly"] = true;
		}
		if (!prop.isWritable())
			propData["readOnly"] = true;
		if (prop.hasNotifySignal())
			propData["notifySignal"] = getMethodName(prop.notifySignal());
		if (prop.isEnumType())
			propData["enumeration"] = true;

		properties.append(QVariant::fromValue(propData));
	}
	data["properties"] = properties;

	QVariantList methods;
	QVariantList sigs;
	for (int i = 0; i < meta->methodCount(); ++i) {
		QVariantMap methodData;
		QMetaMethod method = meta->method(i);

		QByteArray name = getMethodName(method);
		if (method.access() == QMetaMethod::Private || name.startsWith("_") || name == "deleteLater" || name == "destroyed"
				|| name == "creationCompleted")
			continue;
		else if (method.access() == QMetaMethod::Protected && method.methodType() != QMetaMethod::Signal)
		    continue;
		methodData["name"] = name;

		QByteArray rType(method.typeName());
		if (!rType.isEmpty())
			methodData["type"] = rType;

		QList<QByteArray> pTypes = method.parameterTypes();
		QList<QByteArray> pNames = method.parameterNames();

		QVariantList params;
		for (int i = 0; i < pTypes.count(); ++i) {
			QVariantMap tp;
			tp["type"] = pTypes.at(i);
			tp["name"] = pNames.value(i);
			params.append(tp);
		}
		if (params.size() > 0)
			methodData["parameters"] = params;

		switch (method.methodType()) {
		case QMetaMethod::Method:
			//qDebug() << "=== METHOD ===" << methodData << method.signature();
			methods.append(QVariant::fromValue(methodData));
			break;
		case QMetaMethod::Signal:
			sigs.append(QVariant::fromValue(methodData));
			break;
		case QMetaMethod::Constructor:
			methodData["constructor"] = true;
			methods.append(QVariant::fromValue(methodData));
			break;
		case QMetaMethod::Slot:
			methods.append(QVariant::fromValue(methodData));
			break;
		}

	}
	if (methods.size() > 0)
		data["methods"] = methods;
	if (sigs.size() > 0)
		data["signals"] = sigs;

	data["id"] = args.takeFirst();

	bridge->json()->saveToBuffer(QVariant::fromValue(data), retval);
#ifdef DEBUG_QJnextMainLoop
	qDebug() << "[QJnextMainLoop]\t[INTROSPECT]" << retval;
#endif
}