Skip to content
Permalink
Browse files

Left align mapped values

Fix #15101
  • Loading branch information
m-kuhn committed Jun 23, 2016
1 parent d1952ba commit 437cb85cd5590eb3525cbb5be4c120a5841fa26e
@@ -123,6 +123,16 @@ class QgsEditorWidgetFactory
*/
virtual QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const;

/**
* Return the alignment for a particular field. By default this will consider the field type but can be overwritten if mapped
* values are represented.
* @param vl The vector layer.
* @param fieldIdx The index of the field.
* @param config The editor widget config.
* @return The alignment flag, normally Qt::AlignRight or Qt::AlignLeft
*/
virtual Qt::AlignmentFlag alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const;

/**
* Create a cache for a given field.
*
@@ -579,23 +579,16 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
if ( role == FieldIndexRole )
return fieldId;

QgsField field = layer()->fields().at( fieldId );

QVariant::Type fldType = field.type();
bool fldRightAlign = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong
|| fldType == QVariant::DateTime || fldType == QVariant::Date || fldType == QVariant::Time );

if ( role == Qt::TextAlignmentRole )
if ( role == SortRole )
{
if ( fldRightAlign )
return QVariant( Qt::AlignRight );
else
return QVariant( Qt::AlignLeft );
return mSortCache[rowId];
}

if ( role == SortRole )
QgsField field = layer()->fields().at( fieldId );

if ( role == Qt::TextAlignmentRole )
{
return mSortCache[rowId];
return mWidgetFactories.at( index.column() )->alignmentFlag( layer(), fieldId, mWidgetConfigs.at( index.column() ) );
}

if ( mFeat.id() != rowId || !mFeat.isValid() )
@@ -134,6 +134,10 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const

return QVariant::fromValue( feat );
}
else if ( role == Qt::TextAlignmentRole )
{
return Qt::AlignLeft;
}

return sourceModel()->data( mapToSource( index ), role );
}
@@ -16,6 +16,7 @@
#include "qgseditorwidgetfactory.h"
#include "qgsdefaultsearchwidgetwrapper.h"
#include "qgssearchwidgetwrapper.h"
#include "qgsfield.h"

#include <QSettings>

@@ -69,6 +70,20 @@ QString QgsEditorWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx
return vl->fields().at( fieldIdx ).displayString( value );
}

Qt::AlignmentFlag QgsEditorWidgetFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
{
Q_UNUSED( config );

QVariant::Type fldType = vl->fields().at( fieldIdx ).type();
bool alignRight = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong
|| fldType == QVariant::DateTime || fldType == QVariant::Date || fldType == QVariant::Time );

if ( alignRight )
return Qt::AlignRight;
else
return Qt::AlignLeft;
}

QVariant QgsEditorWidgetFactory::createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config )
{
Q_UNUSED( vl )
@@ -138,6 +138,16 @@ class GUI_EXPORT QgsEditorWidgetFactory
*/
virtual QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const;

/**
* Return the alignment for a particular field. By default this will consider the field type but can be overwritten if mapped
* values are represented.
* @param vl The vector layer.
* @param fieldIdx The index of the field.
* @param config The editor widget config.
* @return The alignment flag, normally Qt::AlignRight or Qt::AlignLeft
*/
virtual Qt::AlignmentFlag alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const;

/**
* Create a cache for a given field.
*
@@ -97,6 +97,15 @@ QString QgsDateTimeEditFactory::representValue( QgsVectorLayer* vl, int fieldIdx
return result;
}

Qt::AlignmentFlag QgsDateTimeEditFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );

return Qt::AlignLeft;
}

QMap<const char*, int> QgsDateTimeEditFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
@@ -39,6 +39,7 @@ class GUI_EXPORT QgsDateTimeEditFactory : public QgsEditorWidgetFactory
QgsEditorWidgetConfig readConfig( const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
virtual QMap<const char*, int> supportedWidgetTypes() override;
};

@@ -89,6 +89,15 @@ QString QgsValueMapWidgetFactory::representValue( QgsVectorLayer* vl, int fieldI
return config.key( value, QVariant( QString( "(%1)" ).arg( value.toString() ) ).toString() );
}

Qt::AlignmentFlag QgsValueMapWidgetFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );

return Qt::AlignLeft;
}

QMap<const char*, int> QgsValueMapWidgetFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
@@ -35,6 +35,7 @@ class GUI_EXPORT QgsValueMapWidgetFactory : public QgsEditorWidgetFactory
QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
virtual QMap<const char*, int> supportedWidgetTypes() override;
};

@@ -130,6 +130,17 @@ QString QgsValueRelationWidgetFactory::representValue( QgsVectorLayer* vl, int f
return QString( "(%1)" ).arg( value.toString() );
}

Qt::AlignmentFlag QgsValueRelationWidgetFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );

QgsDebugMsg( "Entered" );

return Qt::AlignLeft;
}

QVariant QgsValueRelationWidgetFactory::createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config )
{
Q_UNUSED( vl )
@@ -38,6 +38,7 @@ class GUI_EXPORT QgsValueRelationWidgetFactory : public QgsEditorWidgetFactory
QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
QVariant createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) override;
};

0 comments on commit 437cb85

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