io.qt.widgets.QStandardItemEditorCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qtjambi Show documentation
Show all versions of qtjambi Show documentation
QtJambi base module containing QtCore, QtGui and QtWidgets.
/****************************************************************************
**
** Copyright (C) 1992-2009 Nokia. All rights reserved.
** Copyright (C) 2009-2022 Dr. Peter Droste, Omix Visualization GmbH & Co. KG. All rights reserved.
**
** This file is part of Qt Jambi.
**
** ** $BEGIN_LICENSE$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
** $END_LICENSE$
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
package io.qt.widgets;
import java.io.Serializable;
import java.lang.invoke.MethodHandleInfo;
import java.lang.invoke.MethodType;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Objects;
import io.qt.core.QByteArray;
import io.qt.core.QMetaObject;
import io.qt.core.QOperatingSystemVersion;
import io.qt.internal.QtJambiInternal;
/**
* Java wrapper for Qt class QStandardItemEditorCreator
*/
public class QStandardItemEditorCreator implements QItemEditorCreatorBase {
public interface ConstructorHandle extends QItemEditorCreator.ConstructorHandle, Serializable{
}
private final QByteArray valuePropertyName;
private final ConstructorHandle constructorHandle;
public QStandardItemEditorCreator(ConstructorHandle constructor) {
super();
SerializedLambda serializedLambda = QtJambiInternal.serializeLambdaExpression(Objects.requireNonNull(constructor));
QMetaObject metaObject = null;
if(serializedLambda==null) {
Class> implClass = null;
for(Type iface : QtJambiInternal.getClass(constructor).getGenericInterfaces()) {
if(iface instanceof ParameterizedType) {
ParameterizedType piface = (ParameterizedType)iface;
if(piface.getRawType()==ConstructorHandle.class) {
Type[] args = piface.getActualTypeArguments();
for (int i = 0; i < args.length; i++) {
implClass = QtJambiInternal.toClass(args[i]);
}
}
}
}
if(implClass==null) {
if(QOperatingSystemVersion.current().isAnyOfType(QOperatingSystemVersion.OSType.Android)) {
QWidget widget = constructor.create(null);
metaObject = widget.metaObject();
widget.dispose();
}else {
throw new RuntimeException("Constructor handle required as argument, e.g. QWidget::new");
}
}else {
metaObject = QMetaObject.forType(implClass);
}
}else if(serializedLambda.getImplMethodKind()==MethodHandleInfo.REF_newInvokeSpecial){
try {
metaObject = QMetaObject.forType(QtJambiInternal.getClass(constructor).getClassLoader().loadClass(serializedLambda.getImplClass().replace('/', '.')));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}else{
MethodType methodType = MethodType.fromMethodDescriptorString(serializedLambda.getImplMethodSignature(), QtJambiInternal.getClass(constructor).getClassLoader());
metaObject = QMetaObject.forType(methodType.returnType());
}
this.valuePropertyName = new QByteArray(metaObject.userProperty().name());
this.constructorHandle = constructor;
}
public QStandardItemEditorCreator(Class widgetType) {
this(widgetType, QItemEditorCreator.findConstructor("QStandardItemEditorCreator", widgetType));
}
private QStandardItemEditorCreator(Class widgetType, long constructorHandle) {
super();
this.constructorHandle = parent -> QItemEditorCreator.construct(widgetType, constructorHandle, parent);
this.valuePropertyName = new QByteArray(QMetaObject.forType(widgetType).userProperty().name());
}
@Override
public T createWidget(QWidget parent) {
T widget = this.constructorHandle.create(parent);
if(widget!=null && widget.parent()==null) {
QtJambi_LibraryUtilities.internal.setJavaOwnership(widget);
}
return widget;
}
@Override
public QByteArray valuePropertyName() {
return valuePropertyName.clone();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy