Skip to content

Commit

Permalink
Added scrool area, 'select all' and 'clear' buttons to attribute dialog
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12843 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 28, 2010
1 parent 7e272d2 commit db6f814
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ SET (QGIS_APP_MOC_HDRS
qgsundowidget.h
qgsquerybuilder.h

composer/qgsattributeselectiondialog.h
composer/qgscomposer.h
composer/qgscomposerarrowwidget.h
composer/qgscomposeritemwidget.h
Expand Down
80 changes: 67 additions & 13 deletions src/app/composer/qgsattributeselectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>

QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer* vLayer, const QSet<int>& enabledAttributes, const QMap<int, QString>& aliasMap,
QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vLayer )
{
if ( vLayer )
{
mGridLayout = new QGridLayout( this );
QScrollArea* attributeScrollArea = new QScrollArea( this );
QWidget* attributeWidget = new QWidget();

mAttributeGridLayout = new QGridLayout( attributeWidget );
QLabel* attributeLabel = new QLabel( QString( "<b>" ) + tr( "Attribute" ) + QString( "</b>" ), this );
attributeLabel->setTextFormat( Qt::RichText );
mGridLayout->addWidget( attributeLabel, 0, 0 );
mAttributeGridLayout->addWidget( attributeLabel, 0, 0 );
QLabel* aliasLabel = new QLabel( QString( "<b>" ) + tr( "Alias" ) + QString( "</b>" ), this );
aliasLabel->setTextFormat( Qt::RichText );
mGridLayout->addWidget( aliasLabel, 0, 1 );
mAttributeGridLayout->addWidget( aliasLabel, 0, 1 );

QgsFieldMap fieldMap = vLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
Expand All @@ -50,22 +55,37 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer*
{
attributeCheckBox->setCheckState( Qt::Unchecked );
}
mGridLayout->addWidget( attributeCheckBox, layoutRowCounter, 0 );
mAttributeGridLayout->addWidget( attributeCheckBox, layoutRowCounter, 0 );

QLineEdit* attributeLineEdit = new QLineEdit( this );
QMap<int, QString>::const_iterator aliasIt = aliasMap.find( fieldIt.key() );
if ( aliasIt != aliasMap.constEnd() )
{
attributeLineEdit->setText( aliasIt.value() );
}
mGridLayout->addWidget( attributeLineEdit, layoutRowCounter, 1 );
mAttributeGridLayout->addWidget( attributeLineEdit, layoutRowCounter, 1 );
++layoutRowCounter;
}

attributeScrollArea->setWidget( attributeWidget );

QVBoxLayout* verticalLayout = new QVBoxLayout( this );
verticalLayout->addWidget( attributeScrollArea );

QHBoxLayout* selectClearLayout = new QHBoxLayout( this );
QPushButton* mSelectAllButton = new QPushButton( tr( "Select all" ), this );
QObject::connect( mSelectAllButton, SIGNAL( clicked() ), this, SLOT( selectAllAttributes() ) );
QPushButton* mClearButton = new QPushButton( tr( "Clear" ), this );
QObject::connect( mClearButton, SIGNAL( clicked() ), this, SLOT( clearAttributes() ) );
selectClearLayout->addWidget( mSelectAllButton );
selectClearLayout->addWidget( mClearButton );
verticalLayout->addLayout( selectClearLayout );


QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
QObject::connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
QObject::connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
mGridLayout->addWidget( buttonBox, layoutRowCounter, 0, 3, 1 );
verticalLayout->addWidget( buttonBox );
}
}

Expand All @@ -77,14 +97,14 @@ QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog()
QSet<int> QgsAttributeSelectionDialog::enabledAttributes() const
{
QSet<int> result;
if ( !mGridLayout || !mVectorLayer )
if ( !mAttributeGridLayout || !mVectorLayer )
{
return result;
}

for ( int i = 1; i < mGridLayout->rowCount(); ++i )
for ( int i = 1; i < mAttributeGridLayout->rowCount(); ++i )
{
QLayoutItem *checkBoxItem = mGridLayout->itemAtPosition( i, 0 );
QLayoutItem *checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 );
if ( checkBoxItem )
{
QCheckBox *checkBox = qobject_cast< QCheckBox * >( checkBoxItem->widget() );
Expand All @@ -101,15 +121,15 @@ QSet<int> QgsAttributeSelectionDialog::enabledAttributes() const
QMap<int, QString> QgsAttributeSelectionDialog::aliasMap() const
{
QMap<int, QString> result;
if ( !mGridLayout || !mVectorLayer )
if ( !mAttributeGridLayout || !mVectorLayer )
{
return result;
}

for ( int i = 1; i < mGridLayout->rowCount(); ++i )
for ( int i = 1; i < mAttributeGridLayout->rowCount(); ++i )
{
QLayoutItem* lineEditItem = mGridLayout->itemAtPosition( i, 1 );
QLayoutItem* checkBoxItem = mGridLayout->itemAtPosition( i, 0 );
QLayoutItem* lineEditItem = mAttributeGridLayout->itemAtPosition( i, 1 );
QLayoutItem* checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 );
if ( lineEditItem && checkBoxItem )
{
QLineEdit *lineEdit = qobject_cast<QLineEdit*>( lineEditItem->widget() );
Expand All @@ -129,3 +149,37 @@ QMap<int, QString> QgsAttributeSelectionDialog::aliasMap() const
return result;
}

void QgsAttributeSelectionDialog::selectAllAttributes()
{
setAllEnabled( true );
}

void QgsAttributeSelectionDialog::clearAttributes()
{
setAllEnabled( false );
}

void QgsAttributeSelectionDialog::setAllEnabled( bool enabled )
{
if ( mAttributeGridLayout )
{
int nRows = mAttributeGridLayout->rowCount();
for ( int i = 0; i < nRows; ++i )
{
QLayoutItem* checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 );
if ( checkBoxItem )
{
QWidget* checkBoxWidget = checkBoxItem->widget();
if ( checkBoxWidget )
{
QCheckBox* checkBox = dynamic_cast<QCheckBox*>( checkBoxWidget );
if ( checkBox )
{
checkBox->setCheckState( enabled ? Qt::Checked : Qt::Unchecked );
}
}
}
}
}
}

35 changes: 23 additions & 12 deletions src/app/composer/qgsattributeselectiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,33 @@

class QGridLayout;
class QgsVectorLayer;
class QPushButton;

/**A dialog to select what attributes to display (in the table item) and with the possibility to set different aliases*/
class QgsAttributeSelectionDialog: public QDialog
{
public:
QgsAttributeSelectionDialog(const QgsVectorLayer* vLayer, const QSet<int>& enabledAttributes, const QMap<int, QString>& aliasMap, QWidget * parent = 0, Qt::WindowFlags f = 0);
~QgsAttributeSelectionDialog();

/**Returns indices of selected attributes*/
QSet<int> enabledAttributes() const;
/**Returns alias map (alias might be different than for vector layer)*/
QMap<int, QString> aliasMap() const;

private:
const QgsVectorLayer* mVectorLayer;
QGridLayout* mGridLayout;
Q_OBJECT
public:
QgsAttributeSelectionDialog( const QgsVectorLayer* vLayer, const QSet<int>& enabledAttributes, const QMap<int, QString>& aliasMap, QWidget * parent = 0, Qt::WindowFlags f = 0 );
~QgsAttributeSelectionDialog();

/**Returns indices of selected attributes*/
QSet<int> enabledAttributes() const;
/**Returns alias map (alias might be different than for vector layer)*/
QMap<int, QString> aliasMap() const;

private slots:
void selectAllAttributes();
void clearAttributes();

private:
const QgsVectorLayer* mVectorLayer;
QGridLayout* mAttributeGridLayout;
QPushButton* mSelectAllButton;
QPushButton* mClearButton;

/**Enables / disables all check boxes in one go*/
void setAllEnabled( bool enabled );
};

#endif // QGSATTRIBUTESELECTIONDIALOG_H

0 comments on commit db6f814

Please sign in to comment.