Skip to content
Permalink
Browse files

docstrings and beautification

  • Loading branch information
signedav committed Sep 5, 2018
1 parent 4ad7067 commit ae3176fef7af60fc70d2b4a69cbb862b2daed278
@@ -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

};

@@ -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,24 +1125,23 @@ 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 );
} );

//templates
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;
}

This file was deleted.

@@ -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
@@ -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:
@@ -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();

0 comments on commit ae3176f

Please sign in to comment.
You can’t perform that action at this time.