mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-02 00:02:12 -05:00
remove old valuerelation model
This commit is contained in:
parent
fda6324823
commit
54660aaf0b
@ -18,7 +18,6 @@ SET(QGIS_QUICK_GUI_MOC_HDRS
|
||||
qgsquickscalebarkit.h
|
||||
qgsquicksimulatedpositionsource.h
|
||||
qgsquickutils.h
|
||||
qgsquickvaluerelationlistmodel.h
|
||||
qgsquickfeatureslistmodel.h
|
||||
)
|
||||
|
||||
@ -45,7 +44,6 @@ SET(QGIS_QUICK_GUI_SRC
|
||||
qgsquickscalebarkit.cpp
|
||||
qgsquicksimulatedpositionsource.cpp
|
||||
qgsquickutils.cpp
|
||||
qgsquickvaluerelationlistmodel.cpp
|
||||
qgsquickfeatureslistmodel.cpp
|
||||
)
|
||||
|
||||
|
@ -46,7 +46,6 @@
|
||||
#include "qgsquickscalebarkit.h"
|
||||
#include "qgsquicksubmodel.h"
|
||||
#include "qgsquickutils.h"
|
||||
#include "qgsquickvaluerelationlistmodel.h"
|
||||
#include "qgsquickfeatureslistmodel.h"
|
||||
|
||||
static QObject *_utilsProvider( QQmlEngine *engine, QJSEngine *scriptEngine )
|
||||
@ -88,7 +87,6 @@ void QgsQuickPlugin::registerTypes( const char *uri )
|
||||
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
|
||||
qmlRegisterType< QgsQuickSubModel >( uri, 0, 1, "SubModel" );
|
||||
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
|
||||
qmlRegisterType< QgsQuickValueRelationListModel > ( uri, 0, 1, "ValueRelationListModel" );
|
||||
qmlRegisterType< QgsQuickFeaturesListModel >( uri, 0, 1, "FeaturesListModel" );
|
||||
|
||||
qmlRegisterSingletonType< QgsQuickUtils >( uri, 0, 1, "Utils", _utilsProvider );
|
||||
|
@ -1,72 +0,0 @@
|
||||
/***************************************************************************
|
||||
qgsquickvaluerelationlistmodel.cpp
|
||||
--------------------------------------
|
||||
Date : March 2020
|
||||
Copyright : (C) 2020 by Martin Dobias
|
||||
Email : wonder dot sk at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* 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 "qgsquickvaluerelationlistmodel.h"
|
||||
|
||||
#include "qgslogger.h"
|
||||
|
||||
|
||||
QgsQuickValueRelationListModel::QgsQuickValueRelationListModel( QObject *parent )
|
||||
: QAbstractListModel( parent )
|
||||
{
|
||||
}
|
||||
|
||||
void QgsQuickValueRelationListModel::populate( const QVariantMap &config, const QgsFeature &formFeature )
|
||||
{
|
||||
beginResetModel();
|
||||
mCache = QgsValueRelationFieldFormatter::createCache( config, formFeature );
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant QgsQuickValueRelationListModel::keyForRow( int row ) const
|
||||
{
|
||||
if ( row < 0 || row >= mCache.count() )
|
||||
{
|
||||
QgsDebugMsg( "keyForRow: access outside of range " + QString::number( row ) );
|
||||
return QVariant();
|
||||
}
|
||||
return mCache[row].key;
|
||||
}
|
||||
|
||||
int QgsQuickValueRelationListModel::rowForKey( const QVariant &key ) const
|
||||
{
|
||||
for ( int i = 0; i < mCache.count(); ++i )
|
||||
{
|
||||
if ( mCache[i].key == key )
|
||||
return i;
|
||||
}
|
||||
QgsDebugMsg( "rowForKey: key not found: " + key.toString() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
int QgsQuickValueRelationListModel::rowCount( const QModelIndex & ) const
|
||||
{
|
||||
return mCache.count();
|
||||
}
|
||||
|
||||
QVariant QgsQuickValueRelationListModel::data( const QModelIndex &index, int role ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
if ( row < 0 || row >= mCache.count() )
|
||||
return QVariant();
|
||||
|
||||
if ( role == Qt::DisplayRole )
|
||||
return mCache[row].value;
|
||||
|
||||
return QVariant();
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/***************************************************************************
|
||||
qgsquickvaluerelationlistmodel.h
|
||||
--------------------------------------
|
||||
Date : March 2020
|
||||
Copyright : (C) 2020 by Martin Dobias
|
||||
Email : wonder dot sk at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* 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 QGSQUICKVALUERELATIONLISTMODEL_H
|
||||
#define QGSQUICKVALUERELATIONLISTMODEL_H
|
||||
|
||||
#include "qgis_quick.h"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
#include "qgsvaluerelationfieldformatter.h"
|
||||
|
||||
/**
|
||||
* \ingroup quick
|
||||
* List model for combo box in Value Relation widget.
|
||||
* The model keeps a list of key-value pairs fetched from a vector layer. "Values" are the human readable
|
||||
* descriptions (QString), "keys" are unique identifiers of items (QVariant).
|
||||
*
|
||||
* \note QML Type: ValueRelationListModel
|
||||
*
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
class QUICK_EXPORT QgsQuickValueRelationListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//! Constructs an empty list model
|
||||
QgsQuickValueRelationListModel( QObject *parent = nullptr );
|
||||
|
||||
//! Populates the model from vector layer's widget configuration
|
||||
Q_INVOKABLE void populate( const QVariantMap &config, const QgsFeature &formFeature = QgsFeature() );
|
||||
|
||||
//! Returns key for the given rown number (invalid variant if outside of the valid range)
|
||||
Q_INVOKABLE QVariant keyForRow( int row ) const;
|
||||
//! Returns row number
|
||||
Q_INVOKABLE int rowForKey( const QVariant &key ) const;
|
||||
|
||||
int rowCount( const QModelIndex & ) const override;
|
||||
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
|
||||
|
||||
private:
|
||||
QgsValueRelationFieldFormatter::ValueRelationCache mCache;
|
||||
};
|
||||
|
||||
#endif // QGSQUICKVALUERELATIONLISTMODEL_H
|
Loading…
x
Reference in New Issue
Block a user