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