mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Fix action widget on attribute table
This commit is contained in:
parent
604da1f24d
commit
d088fe072d
@ -178,6 +178,18 @@ class QgsAttributeTableModel : QAbstractTableModel
|
||||
*/
|
||||
const QgsAttributeEditorContext& editorContext() const;
|
||||
|
||||
/**
|
||||
* Empty extra columns to announce from this model.
|
||||
* Any extra columns need to be implemented by proxy models in front of this model.
|
||||
*/
|
||||
int extraColumns() const;
|
||||
|
||||
/**
|
||||
* Empty extra columns to announce from this model.
|
||||
* Any extra columns need to be implemented by proxy models in front of this model.
|
||||
*/
|
||||
void setExtraColumns(int extraColumns);
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
|
@ -478,15 +478,3 @@ Qt::ItemFlags QgsAttributeTableFilterModel::flags( const QModelIndex& index ) co
|
||||
return masterModel()->flags( source_index );
|
||||
}
|
||||
|
||||
QModelIndex QgsAttributeTableFilterModel::index( int row, int column, const QModelIndex& parent ) const
|
||||
{
|
||||
if ( column > -1 && mColumnMapping.at( column ) == -1 )
|
||||
{
|
||||
QModelIndex index = QSortFilterProxyModel::index( row, 0, parent );
|
||||
return createIndex( row, column, index.internalPointer() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QSortFilterProxyModel::index( row, column, parent );
|
||||
}
|
||||
}
|
||||
|
@ -169,8 +169,6 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
|
||||
|
||||
virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
||||
|
||||
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
|
||||
|
||||
/**
|
||||
* Sort by the given column using the given order.
|
||||
* Prefetches all the data from the layer to speed up sorting.
|
||||
|
@ -40,9 +40,8 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
|
||||
, mLayerCache( layerCache )
|
||||
, mFieldCount( 0 )
|
||||
, mCachedField( -1 )
|
||||
, mExtraColumns( 0 )
|
||||
{
|
||||
QgsDebugMsg( "entered." );
|
||||
|
||||
mExpressionContext << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope()
|
||||
<< QgsExpressionContextUtils::layerScope( layerCache->layer() );
|
||||
@ -80,6 +79,17 @@ bool QgsAttributeTableModel::loadFeatureAtId( QgsFeatureId fid ) const
|
||||
return mLayerCache->featureAtId( fid, mFeat );
|
||||
}
|
||||
|
||||
int QgsAttributeTableModel::extraColumns() const
|
||||
{
|
||||
return mExtraColumns;
|
||||
}
|
||||
|
||||
void QgsAttributeTableModel::setExtraColumns( int extraColumns )
|
||||
{
|
||||
mExtraColumns = extraColumns;
|
||||
loadAttributes();
|
||||
}
|
||||
|
||||
void QgsAttributeTableModel::featuresDeleted( const QgsFeatureIds& fids )
|
||||
{
|
||||
QList<int> rows;
|
||||
@ -212,7 +222,6 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
|
||||
|
||||
void QgsAttributeTableModel::updatedFields()
|
||||
{
|
||||
QgsDebugMsg( "entered." );
|
||||
loadAttributes();
|
||||
emit modelChanged();
|
||||
}
|
||||
@ -235,8 +244,6 @@ void QgsAttributeTableModel::attributeDeleted( int idx )
|
||||
|
||||
void QgsAttributeTableModel::layerDeleted()
|
||||
{
|
||||
QgsDebugMsg( "entered." );
|
||||
|
||||
removeRows( 0, rowCount() );
|
||||
|
||||
mAttributeWidgetCaches.clear();
|
||||
@ -317,15 +324,15 @@ void QgsAttributeTableModel::loadAttributes()
|
||||
}
|
||||
}
|
||||
|
||||
if ( mFieldCount < attributes.size() )
|
||||
if ( mFieldCount + mExtraColumns < attributes.size() + mExtraColumns )
|
||||
{
|
||||
ins = true;
|
||||
beginInsertColumns( QModelIndex(), mFieldCount, attributes.size() - 1 );
|
||||
beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, attributes.size() - 1 );
|
||||
}
|
||||
else if ( attributes.size() < mFieldCount )
|
||||
else if ( attributes.size() + mExtraColumns < mFieldCount + mExtraColumns )
|
||||
{
|
||||
rm = true;
|
||||
beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount - 1 );
|
||||
beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount + mExtraColumns - 1 );
|
||||
}
|
||||
|
||||
mFieldCount = attributes.size();
|
||||
@ -343,8 +350,6 @@ void QgsAttributeTableModel::loadAttributes()
|
||||
|
||||
void QgsAttributeTableModel::loadLayer()
|
||||
{
|
||||
QgsDebugMsg( "entered." );
|
||||
|
||||
// make sure attributes are properly updated before caching the data
|
||||
// (emit of progress() signal may enter event loop and thus attribute
|
||||
// table view may be updated with inconsistent model which may assume
|
||||
@ -493,7 +498,7 @@ int QgsAttributeTableModel::rowCount( const QModelIndex &parent ) const
|
||||
int QgsAttributeTableModel::columnCount( const QModelIndex &parent ) const
|
||||
{
|
||||
Q_UNUSED( parent );
|
||||
return qMax( 1, mFieldCount ); // if there are zero columns all model indices will be considered invalid
|
||||
return qMax( 1, mFieldCount + mExtraColumns ); // if there are zero columns all model indices will be considered invalid
|
||||
}
|
||||
|
||||
QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
||||
@ -519,7 +524,7 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
|
||||
}
|
||||
else
|
||||
{
|
||||
return tr( "feature id" );
|
||||
return tr( "extra column" );
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -551,7 +556,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
|
||||
return rowId;
|
||||
|
||||
if ( index.column() >= mFieldCount )
|
||||
return role == Qt::DisplayRole ? rowId : QVariant();
|
||||
return QVariant();
|
||||
|
||||
int fieldId = mAttributes[index.column()];
|
||||
|
||||
@ -760,7 +765,7 @@ void QgsAttributeTableModel::setRequest( const QgsFeatureRequest& request )
|
||||
mFeatureRequest.setFlags( mFeatureRequest.flags() | QgsFeatureRequest::NoGeometry );
|
||||
}
|
||||
|
||||
const QgsFeatureRequest &QgsAttributeTableModel::request() const
|
||||
const QgsFeatureRequest& QgsAttributeTableModel::request() const
|
||||
{
|
||||
return mFeatureRequest;
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
|
||||
/**
|
||||
* Get the the feature request
|
||||
*/
|
||||
const QgsFeatureRequest &request() const;
|
||||
const QgsFeatureRequest& request() const;
|
||||
|
||||
/**
|
||||
* Sets the context in which this table is shown.
|
||||
@ -223,6 +223,18 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
|
||||
*/
|
||||
const QgsAttributeEditorContext& editorContext() const { return mEditorContext; }
|
||||
|
||||
/**
|
||||
* Empty extra columns to announce from this model.
|
||||
* Any extra columns need to be implemented by proxy models in front of this model.
|
||||
*/
|
||||
int extraColumns() const;
|
||||
|
||||
/**
|
||||
* Empty extra columns to announce from this model.
|
||||
* Any extra columns need to be implemented by proxy models in front of this model.
|
||||
*/
|
||||
void setExtraColumns( int extraColumns );
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* Loads the layer into the model
|
||||
@ -337,6 +349,8 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
|
||||
QRect mChangedCellBounds;
|
||||
|
||||
QgsAttributeEditorContext mEditorContext;
|
||||
|
||||
int mExtraColumns;
|
||||
};
|
||||
|
||||
|
||||
|
@ -166,7 +166,8 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
|
||||
if ( !action.showInAttributeTable() )
|
||||
continue;
|
||||
|
||||
QAction* act = new QAction( action.icon(), action.shortTitle().isEmpty() ? action.name() : action.shortTitle(), toolButton );
|
||||
QString actionTitle = !action.shortTitle().isEmpty() ? action.shortTitle() : action.icon().isNull() ? action.name() : "";
|
||||
QAction* act = new QAction( action.icon(), actionTitle, container );
|
||||
act->setToolTip( action.name() );
|
||||
act->setData( i );
|
||||
act->setProperty( "fid", fid );
|
||||
|
@ -244,6 +244,7 @@ void QgsDualView::initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest&
|
||||
mMasterModel = new QgsAttributeTableModel( mLayerCache, this );
|
||||
mMasterModel->setRequest( request );
|
||||
mMasterModel->setEditorContext( mEditorContext );
|
||||
mMasterModel->setExtraColumns( 1 ); // Add one extra column which we can "abuse" as an action column
|
||||
|
||||
connect( mMasterModel, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );
|
||||
connect( mMasterModel, SIGNAL( finished() ), this, SLOT( finished() ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user