[QGIS Commit] r12843 - in trunk/qgis/src/app: . composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jan 28 10:26:07 EST 2010


Author: mhugent
Date: 2010-01-28 10:26:05 -0500 (Thu, 28 Jan 2010)
New Revision: 12843

Modified:
   trunk/qgis/src/app/CMakeLists.txt
   trunk/qgis/src/app/composer/qgsattributeselectiondialog.cpp
   trunk/qgis/src/app/composer/qgsattributeselectiondialog.h
Log:
Added scrool area, 'select all' and 'clear' buttons to attribute dialog

Modified: trunk/qgis/src/app/CMakeLists.txt
===================================================================
--- trunk/qgis/src/app/CMakeLists.txt	2010-01-28 14:15:18 UTC (rev 12842)
+++ trunk/qgis/src/app/CMakeLists.txt	2010-01-28 15:26:05 UTC (rev 12843)
@@ -174,6 +174,7 @@
   qgsundowidget.h
   qgsquerybuilder.h
 
+  composer/qgsattributeselectiondialog.h
   composer/qgscomposer.h
   composer/qgscomposerarrowwidget.h
   composer/qgscomposeritemwidget.h

Modified: trunk/qgis/src/app/composer/qgsattributeselectiondialog.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgsattributeselectiondialog.cpp	2010-01-28 14:15:18 UTC (rev 12842)
+++ trunk/qgis/src/app/composer/qgsattributeselectiondialog.cpp	2010-01-28 15:26:05 UTC (rev 12843)
@@ -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();
@@ -50,7 +55,7 @@
       {
         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() );
@@ -58,14 +63,29 @@
       {
         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 );
   }
 }
 
@@ -77,14 +97,14 @@
 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() );
@@ -101,15 +121,15 @@
 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() );
@@ -129,3 +149,37 @@
   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 );
+          }
+        }
+      }
+    }
+  }
+}
+

Modified: trunk/qgis/src/app/composer/qgsattributeselectiondialog.h
===================================================================
--- trunk/qgis/src/app/composer/qgsattributeselectiondialog.h	2010-01-28 14:15:18 UTC (rev 12842)
+++ trunk/qgis/src/app/composer/qgsattributeselectiondialog.h	2010-01-28 15:26:05 UTC (rev 12843)
@@ -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();
+    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;
+    /**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;
+  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



More information about the QGIS-commit mailing list