Skip to content

Commit

Permalink
docstrings and beautification
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Sep 5, 2018
1 parent 4ad7067 commit ae3176f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 85 deletions.
13 changes: 13 additions & 0 deletions python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in
Expand Up @@ -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;
Expand All @@ -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

};

Expand All @@ -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

};

Expand Down
33 changes: 27 additions & 6 deletions src/app/qgsattributesformproperties.cpp
Expand Up @@ -507,7 +507,8 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged()
}
case DnDTreeItemData::QmlWidget:
{

mAttributeRelationEdit->setVisible( false );
mAttributeTypeDialog->setVisible( false );
break;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
71 changes: 0 additions & 71 deletions src/app/qgsqmlwidgetconfig.ui

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/qgsfeature.h
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Expand Up @@ -26,6 +26,7 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
Q_OBJECT

public:

QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );

bool valid() const override;
Expand All @@ -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;
};

Expand All @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit ae3176f

Please sign in to comment.