mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Add different widget style
This commit is contained in:
parent
8b4cb049ae
commit
a6c88c1166
@ -44,6 +44,15 @@ class QgsAttributeTableConfig
|
||||
bool mHidden; //!< Flag that controls if the column is hidden
|
||||
};
|
||||
|
||||
/**
|
||||
* The style of the action widget in the attribute table.
|
||||
*/
|
||||
enum ActionWidgetStyle
|
||||
{
|
||||
ButtonList, //!< A list of buttons
|
||||
DropDown //!< A tool button with a dropdown to select the current action
|
||||
};
|
||||
|
||||
QgsAttributeTableConfig();
|
||||
|
||||
/**
|
||||
@ -66,6 +75,26 @@ class QgsAttributeTableConfig
|
||||
*/
|
||||
void update( const QgsFields& fields );
|
||||
|
||||
/**
|
||||
* Returns true if the action widget is visible
|
||||
*/
|
||||
bool actionWidgetVisible() const;
|
||||
|
||||
/**
|
||||
* Set if the action widget is visible
|
||||
*/
|
||||
void setActionWidgetVisible( bool visible );
|
||||
|
||||
/**
|
||||
* Get the style of the action widget
|
||||
*/
|
||||
ActionWidgetStyle actionWidgetStyle() const;
|
||||
|
||||
/**
|
||||
* Set the style of the action widget
|
||||
*/
|
||||
void setActionWidgetStyle( const ActionWidgetStyle& actionWidgetStyle );
|
||||
|
||||
/**
|
||||
* Serialize to XML on layer save
|
||||
*/
|
||||
|
@ -56,10 +56,10 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( const QgsActionManager& acti
|
||||
connect( mAddButton, SIGNAL( clicked( bool ) ), this, SLOT( insert() ) );
|
||||
connect( mAddDefaultActionsButton, SIGNAL( clicked() ), this, SLOT( addDefaultActions() ) );
|
||||
|
||||
init( actions );
|
||||
init( actions, mLayer->attributeTableConfig() );
|
||||
}
|
||||
|
||||
void QgsAttributeActionDialog::init( const QgsActionManager& actions )
|
||||
void QgsAttributeActionDialog::init( const QgsActionManager& actions, const QgsAttributeTableConfig& attributeTableConfig )
|
||||
{
|
||||
// Start from a fresh slate.
|
||||
mAttributeActionTable->setRowCount( 0 );
|
||||
@ -72,6 +72,13 @@ void QgsAttributeActionDialog::init( const QgsActionManager& actions )
|
||||
}
|
||||
|
||||
updateButtons();
|
||||
|
||||
QgsAttributeTableConfig::ColumnConfig visibleActionWidgetConfig = QgsAttributeTableConfig::ColumnConfig();
|
||||
visibleActionWidgetConfig.mType = QgsAttributeTableConfig::Action;
|
||||
visibleActionWidgetConfig.mHidden = false;
|
||||
|
||||
mShowInAttributeTable->setChecked( attributeTableConfig.actionWidgetVisible() );
|
||||
mAttributeTableWidgetType->setCurrentIndex( attributeTableConfig.actionWidgetStyle() );
|
||||
}
|
||||
|
||||
QList<QgsAction> QgsAttributeActionDialog::actions() const
|
||||
@ -86,6 +93,16 @@ QList<QgsAction> QgsAttributeActionDialog::actions() const
|
||||
return actions;
|
||||
}
|
||||
|
||||
bool QgsAttributeActionDialog::showWidgetInAttributeTable() const
|
||||
{
|
||||
return mShowInAttributeTable->isChecked();
|
||||
}
|
||||
|
||||
QgsAttributeTableConfig::ActionWidgetStyle QgsAttributeActionDialog::attributeTableWidgetStyle() const
|
||||
{
|
||||
return static_cast<QgsAttributeTableConfig::ActionWidgetStyle>( mAttributeTableWidgetType->currentIndex() );
|
||||
}
|
||||
|
||||
void QgsAttributeActionDialog::insertRow( int row, const QgsAction& action )
|
||||
{
|
||||
QTableWidgetItem* item;
|
||||
|
@ -26,6 +26,7 @@ back to QgsVectorLayer.
|
||||
#include "ui_qgsattributeactiondialogbase.h"
|
||||
#include "qgsactionmanager.h"
|
||||
#include "qgsfield.h"
|
||||
#include "qgsattributetableconfig.h"
|
||||
#include <QMap>
|
||||
|
||||
class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttributeActionDialogBase
|
||||
@ -48,11 +49,13 @@ class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib
|
||||
|
||||
~QgsAttributeActionDialog() {}
|
||||
|
||||
void init( const QgsActionManager& action );
|
||||
void init( const QgsActionManager& action , const QgsAttributeTableConfig& attributeTableConfig );
|
||||
|
||||
QList<QgsAction> actions() const;
|
||||
|
||||
void apply();
|
||||
bool showWidgetInAttributeTable() const;
|
||||
|
||||
QgsAttributeTableConfig::ActionWidgetStyle attributeTableWidgetStyle() const;
|
||||
|
||||
private slots:
|
||||
void moveUp();
|
||||
|
@ -449,7 +449,7 @@ void QgsVectorLayerProperties::syncToLayer()
|
||||
// load appropriate symbology page (V1 or V2)
|
||||
updateSymbologyPage();
|
||||
|
||||
mActionDialog->init( *mLayer->actions() );
|
||||
mActionDialog->init( *mLayer->actions(), mLayer->attributeTableConfig() );
|
||||
|
||||
if ( labelingDialog )
|
||||
labelingDialog->adaptToLayer();
|
||||
@ -558,6 +558,21 @@ void QgsVectorLayerProperties::apply()
|
||||
{
|
||||
mLayer->actions()->addAction( action );
|
||||
}
|
||||
QgsAttributeTableConfig attributeTableConfig = mLayer->attributeTableConfig();
|
||||
attributeTableConfig.setActionWidgetStyle( mActionDialog->attributeTableWidgetStyle() );
|
||||
QVector<QgsAttributeTableConfig::ColumnConfig> columns = attributeTableConfig.columns();
|
||||
|
||||
for ( int i = 0; i < columns.size(); ++i )
|
||||
{
|
||||
if ( columns.at( i ).mType == QgsAttributeTableConfig::Action )
|
||||
{
|
||||
columns[i].mHidden = !mActionDialog->showWidgetInAttributeTable();
|
||||
}
|
||||
}
|
||||
|
||||
attributeTableConfig.setColumns( columns );
|
||||
|
||||
mLayer->setAttributeTableConfig( attributeTableConfig );
|
||||
|
||||
Q_NOWARN_DEPRECATED_PUSH
|
||||
if ( mOptsPage_LabelsOld )
|
||||
|
@ -82,6 +82,37 @@ void QgsAttributeTableConfig::update( const QgsFields& fields )
|
||||
}
|
||||
}
|
||||
|
||||
bool QgsAttributeTableConfig::actionWidgetVisible() const
|
||||
{
|
||||
Q_FOREACH ( const ColumnConfig& columnConfig, mColumns )
|
||||
{
|
||||
if ( columnConfig.mType == Action && columnConfig.mHidden == false )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void QgsAttributeTableConfig::setActionWidgetVisible( bool visible )
|
||||
{
|
||||
for ( int i = 0; i < mColumns.size(); ++i )
|
||||
{
|
||||
if ( mColumns.at( i ).mType == Action )
|
||||
{
|
||||
mColumns[i].mHidden = !visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QgsAttributeTableConfig::ActionWidgetStyle QgsAttributeTableConfig::actionWidgetStyle() const
|
||||
{
|
||||
return mActionWidgetStyle;
|
||||
}
|
||||
|
||||
void QgsAttributeTableConfig::setActionWidgetStyle( const ActionWidgetStyle& actionWidgetStyle )
|
||||
{
|
||||
mActionWidgetStyle = actionWidgetStyle;
|
||||
}
|
||||
|
||||
|
||||
void QgsAttributeTableConfig::readXml( const QDomNode& node )
|
||||
{
|
||||
@ -115,6 +146,11 @@ void QgsAttributeTableConfig::readXml( const QDomNode& node )
|
||||
mColumns.append( column );
|
||||
}
|
||||
}
|
||||
|
||||
if ( configNode.toElement().attribute( "actionWidgetStyle" ) == "buttonList" )
|
||||
mActionWidgetStyle = ButtonList;
|
||||
else
|
||||
mActionWidgetStyle = DropDown;
|
||||
}
|
||||
|
||||
void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
|
||||
@ -122,6 +158,7 @@ void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
|
||||
QDomDocument doc( node.ownerDocument() );
|
||||
|
||||
QDomElement configElement = doc.createElement( "attributetableconfig" );
|
||||
configElement.setAttribute( "actionWidgetStyle", mActionWidgetStyle == ButtonList ? "buttonList" : "dropDown" );
|
||||
|
||||
QDomElement columnsElement = doc.createElement( "columns" );
|
||||
|
||||
|
@ -49,6 +49,15 @@ class CORE_EXPORT QgsAttributeTableConfig
|
||||
bool mHidden; //!< Flag that controls if the column is hidden
|
||||
};
|
||||
|
||||
/**
|
||||
* The style of the action widget in the attribute table.
|
||||
*/
|
||||
enum ActionWidgetStyle
|
||||
{
|
||||
ButtonList, //!< A list of buttons
|
||||
DropDown //!< A tool button with a dropdown to select the current action
|
||||
};
|
||||
|
||||
QgsAttributeTableConfig();
|
||||
|
||||
/**
|
||||
@ -71,6 +80,26 @@ class CORE_EXPORT QgsAttributeTableConfig
|
||||
*/
|
||||
void update( const QgsFields& fields );
|
||||
|
||||
/**
|
||||
* Returns true if the action widget is visible
|
||||
*/
|
||||
bool actionWidgetVisible() const;
|
||||
|
||||
/**
|
||||
* Set if the action widget is visible
|
||||
*/
|
||||
void setActionWidgetVisible( bool visible );
|
||||
|
||||
/**
|
||||
* Get the style of the action widget
|
||||
*/
|
||||
ActionWidgetStyle actionWidgetStyle() const;
|
||||
|
||||
/**
|
||||
* Set the style of the action widget
|
||||
*/
|
||||
void setActionWidgetStyle( const ActionWidgetStyle& actionWidgetStyle );
|
||||
|
||||
/**
|
||||
* Serialize to XML on layer save
|
||||
*/
|
||||
@ -81,8 +110,10 @@ class CORE_EXPORT QgsAttributeTableConfig
|
||||
*/
|
||||
void readXml( const QDomNode& node );
|
||||
|
||||
|
||||
private:
|
||||
QVector<ColumnConfig> mColumns;
|
||||
ActionWidgetStyle mActionWidgetStyle;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( QgsAttributeTableConfig::ColumnConfig )
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QToolButton>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "qgsactionmanager.h"
|
||||
#include "qgsattributetableview.h"
|
||||
@ -122,6 +123,7 @@ void QgsAttributeTableView::setModel( QgsAttributeTableFilterModel* filterModel
|
||||
|
||||
mActionWidget = createActionWidget( 0 );
|
||||
mActionWidget->setVisible( false );
|
||||
updateActionImage( mActionWidget );
|
||||
}
|
||||
|
||||
void QgsAttributeTableView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager )
|
||||
@ -137,11 +139,25 @@ void QgsAttributeTableView::setFeatureSelectionManager( QgsIFeatureSelectionMana
|
||||
|
||||
QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
|
||||
{
|
||||
QToolButton* toolButton = new QToolButton( this );
|
||||
toolButton->setPopupMode( QToolButton::MenuButtonPopup );
|
||||
|
||||
QgsAttributeTableConfig attributeTableConfig = mFilterModel->layer()->attributeTableConfig();
|
||||
QgsActionManager* actions = mFilterModel->layer()->actions();
|
||||
|
||||
QToolButton* toolButton = nullptr;
|
||||
QWidget* container = nullptr;
|
||||
|
||||
if ( attributeTableConfig.actionWidgetStyle() == QgsAttributeTableConfig::DropDown )
|
||||
{
|
||||
toolButton = new QToolButton( this );
|
||||
toolButton->setPopupMode( QToolButton::MenuButtonPopup );
|
||||
container = toolButton;
|
||||
}
|
||||
else
|
||||
{
|
||||
container = new QWidget( this );
|
||||
container->setLayout( new QHBoxLayout() );
|
||||
container->layout()->setMargin( 0 );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < actions->size(); ++i )
|
||||
{
|
||||
const QgsAction& action = actions->at( i );
|
||||
@ -156,18 +172,27 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
|
||||
|
||||
connect( act, SIGNAL( triggered( bool ) ), this, SLOT( actionTriggered() ) );
|
||||
|
||||
toolButton->addAction( act );
|
||||
if ( attributeTableConfig.actionWidgetStyle() == QgsAttributeTableConfig::DropDown )
|
||||
{
|
||||
toolButton->addAction( act );
|
||||
|
||||
if ( actions->defaultAction() == i )
|
||||
toolButton->setDefaultAction( act );
|
||||
if ( actions->defaultAction() == i )
|
||||
toolButton->setDefaultAction( act );
|
||||
|
||||
container = toolButton;
|
||||
}
|
||||
else
|
||||
{
|
||||
QToolButton* btn = new QToolButton;
|
||||
btn->setDefaultAction( act );
|
||||
container->layout()->addWidget( btn );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !toolButton->actions().isEmpty() && actions->defaultAction() == -1 )
|
||||
if ( toolButton && !toolButton->actions().isEmpty() && actions->defaultAction() == -1 )
|
||||
toolButton->setDefaultAction( toolButton->actions().first() );
|
||||
|
||||
updateActionImage( toolButton );
|
||||
|
||||
return toolButton;
|
||||
return container;
|
||||
}
|
||||
|
||||
void QgsAttributeTableView::closeEvent( QCloseEvent *e )
|
||||
|
@ -47,12 +47,12 @@ QgsOrganizeTableColumnsDialog::QgsOrganizeTableColumnsDialog( const QgsVectorLay
|
||||
setupUi( this );
|
||||
if ( vl )
|
||||
{
|
||||
QgsAttributeTableConfig config = vl->attributeTableConfig();
|
||||
config.update( vl->fields() );
|
||||
mConfig = vl->attributeTableConfig();
|
||||
mConfig.update( vl->fields() );
|
||||
|
||||
mFieldsList->clear();
|
||||
|
||||
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig& columnConfig, config.columns() )
|
||||
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig& columnConfig, mConfig.columns() )
|
||||
{
|
||||
QListWidgetItem* item;
|
||||
if ( columnConfig.mType == QgsAttributeTableConfig::Action )
|
||||
@ -110,7 +110,7 @@ QgsAttributeTableConfig QgsOrganizeTableColumnsDialog::config() const
|
||||
columns.append( columnConfig );
|
||||
}
|
||||
|
||||
QgsAttributeTableConfig config;
|
||||
QgsAttributeTableConfig config = mConfig;
|
||||
config.setColumns( columns );
|
||||
return config;
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ class GUI_EXPORT QgsOrganizeTableColumnsDialog : public QDialog, private Ui::Qgs
|
||||
* Get the updated configuration
|
||||
*/
|
||||
QgsAttributeTableConfig config() const;
|
||||
|
||||
private:
|
||||
QgsAttributeTableConfig mConfig;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>609</width>
|
||||
<width>653</width>
|
||||
<height>731</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -227,15 +227,15 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<widget class="QComboBox" name="mAttributeTableWidgetType">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Combo Box</string>
|
||||
<string>Separate Buttons</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Separate Buttons</string>
|
||||
<string>Combo Box</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
|
Loading…
x
Reference in New Issue
Block a user