docstrings and beautification

This commit is contained in:
signedav 2018-09-05 07:57:09 +02:00
parent 4ad7067348
commit ae3176fef7
6 changed files with 47 additions and 85 deletions

View File

@ -31,6 +31,7 @@ the Free Software Foundation; either version 2 of the License, or *
#include "qgsqmlwidgetwrapper.h"
%End
public:
QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
virtual bool valid() const;
@ -43,13 +44,22 @@ the Free Software Foundation; either version 2 of the License, or *
void reinitWidget();
%Docstring
Clears the content and makes new intialisaton
%End
void setQmlCode( const QString &qmlCode );
%Docstring
writes the ``qmlCode`` into a temporary file
%End
public slots:
virtual void setFeature( const QgsFeature &feature );
%Docstring
passes the ``feature`` into the context property of the widget
%End
};
@ -64,6 +74,9 @@ class QmlExpression : QObject
void setExpressionContext( const QgsExpressionContext &context );
QVariant evaluate( const QString &expression ) const;
%Docstring
evaluates the value regarding the /a expression and the context
%End
};

View File

@ -507,7 +507,8 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged()
}
case DnDTreeItemData::QmlWidget:
{
mAttributeRelationEdit->setVisible( false );
mAttributeTypeDialog->setVisible( false );
break;
}
@ -854,7 +855,7 @@ QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormPro
break;
case QgsAttributesFormProperties::DnDTreeItemData::QmlWidget:
newItem->setIcon( 0, QgsApplication::getThemeIcon( "/mQmlWidgetIcon.svg" ) );
//no icon for QmlWidget
break;
}
}
@ -1124,16 +1125,14 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
//update preview on text change
QgsFeature previewFeature;
mLayer->getFeatures().nextFeature( previewFeature );
qmlWrapper->setFeature( previewFeature );
//update preview on text change
connect( qmlCode, &QPlainTextEdit::textChanged, this, [ = ]
{
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
qmlWrapper->reinitWidget();
QgsFeature previewFeature;
mLayer->getFeatures().nextFeature( previewFeature );
qmlWrapper->setFeature( previewFeature );
} );
@ -1141,7 +1140,8 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
QComboBox *qmlObjectTemplate = new QComboBox();
qmlObjectTemplate->addItem( tr( "Free text..." ) );
qmlObjectTemplate->addItem( tr( "Rectangle" ) );
qmlObjectTemplate->addItem( tr( "Pie Chart" ) );
qmlObjectTemplate->addItem( tr( "Pie chart" ) );
qmlObjectTemplate->addItem( tr( "Bar chart" ) );
connect( qmlObjectTemplate, QOverload<int>::of( &QComboBox::currentIndexChanged ), qmlCode, [ = ]( int index )
{
qmlCode->clear();
@ -1182,6 +1182,27 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
"}\n" ) );
break;
}
case 3:
{
qmlCode->insertPlainText( QStringLiteral( "import QtQuick 2.0\n"
"import QtCharts 2.0\n"
"\n"
"ChartView {\n"
"title: \"Bar series\"\n"
"width: 600\n"
"height:400\n"
"legend.alignment: Qt.AlignBottom\n"
"antialiasing: true\n"
"\n"
"BarSeries {\n"
"id: mySeries\n"
"axisX: BarCategoryAxis { categories: [\"2007\", \"2008\", \"2009\", \"2010\", \"2011\", \"2012\" ] }\n"
"BarSet { label: \"Bob\"; values: [2, 2, 3, 4, 5, 6] }\n"
"BarSet { label: \"Susan\"; values: [5, 1, 2, 4, 1, 7] }\n"
"BarSet { label: \"James\"; values: [3, 5, 8, 13, 5, 8] }\n"
"}\n" ) );
break;
}
default:
break;
}

View File

@ -1,71 +0,0 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="geometry" >
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -443,7 +443,7 @@ class CORE_EXPORT QgsFeature
* \see setFields
*/
#ifndef SIP_RUN
Q_INVOKABLE QVariant attribute( const QString &name ) const;
QVariant attribute( const QString &name ) const;
#else
SIP_PYOBJECT attribute( const QString &name ) const;
% MethodCode

View File

@ -26,6 +26,7 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
Q_OBJECT
public:
QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
bool valid() const override;
@ -34,17 +35,19 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
void initWidget( QWidget *editor ) override;
//! Clears the content and makes new intialisaton
void reinitWidget();
//! writes the \a qmlCode into a temporary file
void setQmlCode( const QString &qmlCode );
public slots:
//! passes the \a feature into the context property of the widget
void setFeature( const QgsFeature &feature ) override;
private:
QTemporaryFile mQmlFile;
QQuickWidget *mWidget = nullptr;
};
@ -56,6 +59,7 @@ class GUI_EXPORT QmlExpression : public QObject
public:
void setExpressionContext( const QgsExpressionContext &context );
//! evaluates the value regarding the /a expression and the context
Q_INVOKABLE QVariant evaluate( const QString &expression ) const;
private:

View File

@ -1775,16 +1775,11 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
const QgsAttributeEditorQmlElement *elementDef = static_cast<const QgsAttributeEditorQmlElement *>( widgetDef );
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
qmlWrapper->setQmlCode( elementDef->qmlCode() );
//qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( elementDef->name()) );
qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( elementDef->name() ) );
qmlWrapper->setContext( context );
// QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this );
mWidgets.append( qmlWrapper );
// mFormWidgets.append( formWidget );
newWidgetInfo.widget = qmlWrapper->widget();
newWidgetInfo.labelText = elementDef->name();