Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value Relation Widget #600

Merged
merged 26 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c2d8f24
add value relation widget
signedav Jun 25, 2019
b201241
add value relation widget to widget handling
signedav Jun 25, 2019
709ae2c
inherit from RelationWidget
signedav Jun 25, 2019
66a6dce
pass FeatureListModel and relation but not that nice
signedav Jun 25, 2019
bbd2cb9
value field of value relation
signedav Jun 25, 2019
3a7ef39
rename and rearrange editorwidget/RelationWidget.qml to RelationCombo…
signedav Jun 27, 2019
8c1489c
use QgsProject->mapLayer to get layer
signedav Jun 27, 2019
ebb9b8f
add mapLayer to qmlRegisterUncreatableType
signedav Jun 27, 2019
a104a38
AllowNull instead of AllowNULL (how it's called in relationreference)
signedav Jun 27, 2019
c83ac1f
add additional role to call displayString manually
signedav Jun 27, 2019
c415622
Basic gui implementation for multi value
signedav Jun 27, 2019
eaab3cd
indents
signedav Jun 27, 2019
cbf571e
Model for multiple selection in ValueRelation
signedav Jul 2, 2019
4388d25
fix the scope
signedav Jul 3, 2019
3415f9f
updating value on model change
signedav Jul 3, 2019
6635af6
beginResetModel / endResetModel and log that has to be removed later
signedav Jul 3, 2019
040c828
- keep index on list
signedav Jul 3, 2019
a5a7161
clear model on adding features
signedav Jul 3, 2019
16cf30e
remove wrong sign
signedav Jul 3, 2019
004d202
handle JSON and HSTORE regarding the field.type
signedav Jul 4, 2019
7a81a1c
Bump SDK
m-kuhn Jul 5, 2019
5c5f6aa
Fix builds with QGIS 3.9
m-kuhn Jul 7, 2019
8ba98ef
Bump SDK
m-kuhn Jul 26, 2019
35bb72b
use of QgsPostgresStringUtils
signedav Aug 11, 2019
e3f6cd0
exclude QgsPostgresStringUtils for android 5
signedav Sep 2, 2019
039d707
clean up
signedav Sep 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ before_install:
- gem --version

script:
- export QFIELD_SDK_VERSION=${QFIELD_SDK_VERSION:-20190528}
- export QFIELD_SDK_VERSION=${QFIELD_SDK_VERSION:-20190726}
- echo "travis_fold:start:docker-pull"
- docker pull opengisch/qfield-sdk:${QFIELD_SDK_VERSION}
- echo "travis_fold:end:docker-pull"
Expand Down
15 changes: 12 additions & 3 deletions qfield.pri
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ android {
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libzip.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libspatialiteprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libdelimitedtextprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libgdalprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libgpxprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libmssqlprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libogrprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libowsprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libpostgresprovider.so \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libspatialiteprovider.so \
Expand All @@ -51,5 +49,16 @@ android {
$$QT_LIBS_DIR/libQt5Sql.so \
$$QT_LIBS_DIR/libQt5Svg.so \
$$QT_LIBS_DIR/libQt5PrintSupport.so
}

# Only here for Android 5 (QGIS <= 3.8) compatibility reasons
exists ( $${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libgdalprovider.so ) {
ANDROID_EXTRA_LIBS += \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libgdalprovider.so
}

# Only here for Android 5 (QGIS <= 3.8) compatibility reasons
exists ( $${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libogrprovider.so ) {
ANDROID_EXTRA_LIBS += \
$${OSGEO4A_STAGE_DIR}/$$ANDROID_TARGET_ARCH$$/lib/libogrprovider.so
}
}
6 changes: 4 additions & 2 deletions src/core/core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ HEADERS += \
linepolygonhighlight.h \
qgsgeometrywrapper.h \
valuemapmodel.h \
referencingfeaturelistmodel.h
referencingfeaturelistmodel.h \
featurechecklistmodel.h

SOURCES += \
appinterface.cpp \
Expand Down Expand Up @@ -102,7 +103,8 @@ SOURCES += \
linepolygonhighlight.cpp \
qgsgeometrywrapper.cpp \
valuemapmodel.cpp \
referencingfeaturelistmodel.cpp
referencingfeaturelistmodel.cpp \
featurechecklistmodel.cpp

INCLUDEPATH += ../../3rdparty/tessellate \
../qgsquick \
Expand Down
178 changes: 178 additions & 0 deletions src/core/featurechecklistmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/***************************************************************************
featurechecklistmodel.cpp - FeatureCheckListModel

---------------------
begin : August 2019
copyright : (C) 2019 by David Signer
email : david (at) opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "featurechecklistmodel.h"
signedav marked this conversation as resolved.
Show resolved Hide resolved
#include "qgsvaluerelationfieldformatter.h"
#include "qgsmessagelog.h"
#if VERSION_INT >= 30600
#include "qgspostgresstringutils.h"
#endif

FeatureCheckListModel::FeatureCheckListModel()
{

}

QVariant FeatureCheckListModel::data( const QModelIndex &index, int role ) const
{
if ( role == CheckedRole )
{
return mCheckedEntries.contains( FeatureListModel::data( index, FeatureListModel::KeyFieldRole ).toString() );
}
else
return FeatureListModel::data( index, role );
}

bool FeatureCheckListModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
if ( data( index, role ) == value )
return true;

switch ( role )
{
case CheckedRole:
{
if ( value.toBool() )
setChecked( index );
else
setUnchecked( index );
break;
}
}
return true;
}

QHash<int, QByteArray> FeatureCheckListModel::roleNames() const
{
QHash<int, QByteArray> roles = FeatureListModel::roleNames();

roles[CheckedRole] = "checked";
signedav marked this conversation as resolved.
Show resolved Hide resolved

return roles;
}

QVariant FeatureCheckListModel::attributeValue() const
{
QVariant value;

QVariantList vl;
//store as QVariantList because the field type supports data structure
for ( const QString &s : qgis::as_const( mCheckedEntries ) )
{
// Convert to proper type
const QVariant::Type type { fkType() };
switch ( type )
{
case QVariant::Type::Int:
vl.push_back( s.toInt() );
break;
case QVariant::Type::LongLong:
vl.push_back( s.toLongLong() );
break;
default:
vl.push_back( s );
break;
}
}

if ( mAttributeField.type() == QVariant::Map ||
mAttributeField.type() == QVariant::List )
{
value = vl;
}
else
{
//make string
#if VERSION_INT >= 30600
value = QgsPostgresStringUtils::buildArray( vl );
#else
QgsMessageLog::logMessage( tr( "Storing of value relation widget checklists not available for Android 5" ), "QField", Qgis::Critical );
#endif
}

return value;
}

void FeatureCheckListModel::setAttributeValue( const QVariant &attributeValue )
{
QStringList checkedEntries;

if ( mAttributeField.type() == QVariant::Map )
{
//store as QVariantList because the field type supports data structure
checkedEntries = attributeValue.toStringList();
}
else
{
//store as a formatted string because the fields supports only string
checkedEntries = QgsValueRelationFieldFormatter::valueToStringList( attributeValue );
}

if ( mCheckedEntries == checkedEntries )
return;

beginResetModel();
mCheckedEntries = checkedEntries;
endResetModel();

emit attributeValueChanged();
}

QgsField FeatureCheckListModel::attributeField() const
{
return mAttributeField;
}

void FeatureCheckListModel::setAttributeField( const QgsField &field )
{
if ( mAttributeField == field )
return;

mAttributeField = field;
}

void FeatureCheckListModel::setChecked( const QModelIndex &index )
{
beginResetModel();
mCheckedEntries.append( FeatureListModel::data( index, FeatureListModel::KeyFieldRole ).toString() );
endResetModel();

emit listUpdated();
}

void FeatureCheckListModel::setUnchecked( const QModelIndex &index )
{
beginResetModel();
mCheckedEntries.removeAll( FeatureListModel::data( index, FeatureListModel::KeyFieldRole ).toString() );
endResetModel();

emit listUpdated();
}


QVariant::Type FeatureCheckListModel::fkType() const
{
if ( currentLayer() )
{
QgsFields fields = currentLayer()->fields();
int idx { fields.indexOf( keyField() ) };
if ( idx >= 0 )
{
return fields.at( idx ).type();
}
}
return QVariant::Type::Invalid;
}
84 changes: 84 additions & 0 deletions src/core/featurechecklistmodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/***************************************************************************
featurechecklistmodel.h - FeatureCheckListModel

---------------------
begin : August 2019
copyright : (C) 2019 by David Signer
email : david (at) opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef FEATURECHECKLISTMODEL_H
#define FEATURECHECKLISTMODEL_H

#include <featurelistmodel.h>
#include <qgsvectorlayer.h>

class FeatureCheckListModel : public FeatureListModel
{
Q_OBJECT

/**
* The attribute value to generate checklist
*/
Q_PROPERTY( QVariant attributeValue READ attributeValue WRITE setAttributeValue NOTIFY attributeValueChanged )

/**
* The attribute field to have information about type (JSON/HSTORE) etc.
*/
Q_PROPERTY( QgsField attributeField READ attributeField WRITE setAttributeField NOTIFY attributeFieldChanged )

public:
FeatureCheckListModel();

enum FeatureListRoles
{
CheckedRole
};

virtual QVariant data( const QModelIndex &index, int role ) const override;
virtual bool setData( const QModelIndex &index, const QVariant &value, int role ) override;

QHash<int, QByteArray> roleNames() const override;

/**
* the attribute value. A QVariantList or an hstore formatted string, depending on the field type.
*/
QVariant attributeValue() const;

/**
* the attribute value. A QVariantList or an hstore formatted string, depending on the field type.
*/
void setAttributeValue( const QVariant &attributeValue );

/**
* the current attribute field
*/
QgsField attributeField() const;

/**
* the current attribute field
*/
void setAttributeField( const QgsField &field );

signals:
void attributeValueChanged();
void attributeFieldChanged();
void listUpdated();

private:
void setChecked( const QModelIndex &index );
void setUnchecked( const QModelIndex &index );
QVariant::Type fkType() const;

QgsField mAttributeField;
QStringList mCheckedEntries;
};

#endif // FEATURECHECKLISTMODEL_H
Loading