[QGIS Commit] r11681 - in trunk/qgis/src: app app/attributetable core ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Sep 19 18:56:54 EDT 2009


Author: jef
Date: 2009-09-19 18:56:53 -0400 (Sat, 19 Sep 2009)
New Revision: 11681

Modified:
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.h
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgsattributedialog.cpp
   trunk/qgis/src/app/qgsattributedialog.h
   trunk/qgis/src/app/qgsattributeeditor.cpp
   trunk/qgis/src/app/qgsattributetypedialog.cpp
   trunk/qgis/src/app/qgsidentifyresults.cpp
   trunk/qgis/src/app/qgsidentifyresults.h
   trunk/qgis/src/app/qgsmaptoolidentify.cpp
   trunk/qgis/src/app/qgsvectorlayerproperties.cpp
   trunk/qgis/src/core/qgsvectorlayer.cpp
   trunk/qgis/src/core/qgsvectorlayer.h
   trunk/qgis/src/ui/qgsattributetypeedit.ui
   trunk/qgis/src/ui/qgsidentifyresultsbase.ui
Log:
vector editing update:
- show mapped value instead of attribute value for value maps in attribute table and identify results.
- alternating background color in identify results
- allow hiding of attributes
- add actions (including edit action) into identify results



Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -34,9 +34,30 @@
   mLastRow = NULL;
   mLayer = theLayer;
   mFeatureCount = mLayer->pendingFeatureCount();
-  mFieldCount = mLayer->pendingFields().size();
-  mAttributes = mLayer->pendingAllAttributesList();
 
+  mFieldCount = 0;
+  mAttributes.clear();
+  mValueMaps.clear();
+
+  for ( QgsFieldMap::const_iterator it = theLayer->pendingFields().constBegin(); it != theLayer->pendingFields().end(); it++ )
+  {
+    switch ( mLayer->editType( it.key() ) )
+    {
+      case QgsVectorLayer::Hidden:
+        continue;
+
+      case QgsVectorLayer::ValueMap:
+        mValueMaps.insert( it.key(), &mLayer->valueMap( it.key() ) );
+        break;
+
+      default:
+        break;
+    }
+
+    mFieldCount++;
+    mAttributes << it.key();
+  }
+
   connect( mLayer, SIGNAL( layerModified( bool ) ), this, SLOT( layerModified( bool ) ) );
   //connect(mLayer, SIGNAL(attributeAdded(int)), this, SLOT( attributeAdded(int)));
   //connect(mLayer, SIGNAL(attributeDeleted(int)), this, SLOT( attributeDeleted(int)));
@@ -173,7 +194,7 @@
 // QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() -1));
   }
 
-  mLayer->select( QgsAttributeList(), QgsRectangle(), false );
+  mLayer->select( mAttributes, QgsRectangle(), false );
 
   // preallocate data before inserting
   mRowIdMap.reserve( pendingFeatureCount + 50 );
@@ -187,7 +208,7 @@
 
   // not needed when we have featureAdded signal
   mFeatureCount = pendingFeatureCount;
-  mFieldCount = mLayer->pendingFields().size();
+  mFieldCount = mAttributes.size();
 
   if ( ins )
   {
@@ -369,7 +390,7 @@
   if ( !mLastRow )
     return QVariant( "ERROR" );
 
-  QVariant &val = ( *mLastRow )[ mAttributes[index.column()] ];
+  const QVariant &val = ( *mLastRow )[ mAttributes[index.column()] ];
 
   if ( val.isNull() )
   {
@@ -384,6 +405,11 @@
     }
   }
 
+  if ( role == Qt::DisplayRole && mValueMaps.contains( index.column() ) )
+  {
+    return mValueMaps[ index.column()]->key( val.toString(), QString( "(%1)" ).arg( val.toString() ) );
+  }
+
   // force also numeric data for EditRole to be strings
   // otherwise it creates spinboxes instead of line edits
   // (probably not what we do want)

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2009-09-19 22:56:53 UTC (rev 11681)
@@ -188,6 +188,7 @@
 
     mutable QgsAttributeMap *mLastRow;
     QgsAttributeList mAttributes;
+    QMap< int, const QMap<QString, QVariant> * > mValueMaps;
 
     QList<QgsAttributeTableIdColumnPair> mSortList;
     QHash<int, int> mIdRowMap;

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgisapp.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -3667,9 +3667,6 @@
       {
         QgsDebugMsg( "unable to load project " + fileName );
       }
-      else
-      {
-      }
     }
     catch ( QgsIOException & io_exception )
     {

Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsattributedialog.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -43,7 +43,8 @@
 
   const QgsFieldMap &theFieldMap = vl->pendingFields();
 
-  if ( theFieldMap.isEmpty() ) return;
+  if ( theFieldMap.isEmpty() )
+    return;
 
   QgsAttributeMap myAttributes = mpFeature->attributeMap();
   //
@@ -64,8 +65,6 @@
   mypScrollArea->setWidgetResizable( true );
   QGridLayout * mypInnerLayout = new QGridLayout( mypInnerFrame );
 
-
-
   int index = 0;
   for ( QgsAttributeMap::const_iterator it = myAttributes.begin();
         it != myAttributes.end();
@@ -77,6 +76,10 @@
     QString myFieldName = vl->attributeDisplayName( it.key() );
     int myFieldType = field.type();
 
+    QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, vl, it.key(), it.value() );
+    if ( !myWidget )
+      continue;
+
     QLabel * mypLabel = new QLabel();
     mypInnerLayout->addWidget( mypLabel, index, 0 );
     if ( myFieldType == QVariant::Int )
@@ -93,9 +96,8 @@
       mypLabel->setText( myFieldName + tr( " (txt)" ) );
     }
 
-    QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, vl, it.key(), it.value() );
-
     mypInnerLayout->addWidget( myWidget, index, 1 );
+    mpIndizes << it.key();
     mpWidgets << myWidget;
     ++index;
   }
@@ -124,8 +126,9 @@
   {
     QVariant value;
 
-    if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, it.key(), value ) )
-      mpFeature->changeAttribute( it.key(), value );
+    int idx = mpIndizes.value( myIndex );
+    if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
+      mpFeature->changeAttribute( idx, value );
 
     ++myIndex;
   }

Modified: trunk/qgis/src/app/qgsattributedialog.h
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.h	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsattributedialog.h	2009-09-19 22:56:53 UTC (rev 11681)
@@ -55,6 +55,7 @@
   private:
     QString mSettingsPath;
     QList<QWidget *> mpWidgets;
+    QList<int> mpIndizes;
     QgsVectorLayer *mLayer;
     QgsFeature *  mpFeature;
 

Modified: trunk/qgis/src/app/qgsattributeeditor.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributeeditor.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsattributeeditor.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -228,6 +228,10 @@
     }
     break;
 
+    case QgsVectorLayer::Hidden:
+      myWidget = NULL;
+      break;
+
     case QgsVectorLayer::FileName:
     {
       QLineEdit *le = new QLineEdit();
@@ -252,6 +256,9 @@
 
 bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value )
 {
+  if ( !widget )
+    return false;
+
   const QgsField &theField = vl->pendingFields()[idx];
   QgsVectorLayer::EditType editType = vl->editType( idx );
   bool modified = false;
@@ -349,6 +356,9 @@
 
 bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
 {
+  if ( !editor )
+    return false;
+
   QgsVectorLayer::EditType editType = vl->editType( idx );
   const QgsField &field = vl->pendingFields()[idx];
   QVariant::Type myFieldType = field.type();
@@ -362,7 +372,8 @@
       QComboBox *cb = dynamic_cast<QComboBox *>( editor );
       if ( cb == NULL )
         return false;
-      int idx = cb->findText( value.toString() );
+
+      int idx = cb->findData( value );
       if ( idx < 0 )
         return false;
 

Modified: trunk/qgis/src/app/qgsattributetypedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetypedialog.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsattributetypedialog.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -226,6 +226,10 @@
       setPage( 7 );
       break;
 
+    case QgsVectorLayer::Hidden:
+      setPage( 8 );
+      break;
+
     case QgsVectorLayer::LineEdit:
       setPage( 0 );
       break;
@@ -501,6 +505,9 @@
     case 7:
       mEditType = QgsVectorLayer::Immutable;
       break;
+    case 8:
+      mEditType = QgsVectorLayer::Hidden;
+      break;
     default:
       mEditType = QgsVectorLayer::LineEdit;
   }

Modified: trunk/qgis/src/app/qgsidentifyresults.cpp
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsidentifyresults.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -27,6 +27,7 @@
 #include "qgsgeometry.h"
 #include "qgsattributedialog.h"
 #include "qgsmapcanvas.h"
+#include "qgsattributeaction.h"
 
 #include <QCloseEvent>
 #include <QLabel>
@@ -59,14 +60,19 @@
 //
 // layer [userrole: QgsMapLayer]
 //   feature: displayfield|displayvalue [userrole: fid]
-//     derived attributes
+//     derived attributes (if any) [userrole: "derived"]
 //       name value
+//     actions (if any) [userrole: "actions"]
+//       edit [userrole: "edit"]
+//       action [userrole: "action", idx]
 //     name value
 //     name value
 //     name value
 //   feature
-//     derived attributes
+//     derived attributes (if any)
 //       name value
+//     actions (if any)
+//       action
 //     name value
 
 QgsIdentifyResults::QgsIdentifyResults( QgsMapCanvas *canvas, QWidget *parent, Qt::WFlags f )
@@ -99,6 +105,9 @@
 
   connect( lstResults, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
            this, SLOT( handleCurrentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) );
+
+  connect( lstResults, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ),
+           this, SLOT( itemClicked( QTreeWidgetItem*, int ) ) );
 }
 
 QgsIdentifyResults::~QgsIdentifyResults()
@@ -108,11 +117,10 @@
 
 QTreeWidgetItem *QgsIdentifyResults::layerItem( QObject *layer )
 {
-  QTreeWidgetItem *item;
-
   for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
   {
-    item = lstResults->topLevelItem( i );
+    QTreeWidgetItem *item = lstResults->topLevelItem( i );
+
     if ( item->data( 0, Qt::UserRole ).value<QObject*>() == layer )
       return item;
   }
@@ -126,6 +134,7 @@
                                      const QMap<QString, QString> &derivedAttributes )
 {
   QTreeWidgetItem *layItem = layerItem( layer );
+  QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer*>( layer );
 
   if ( layItem == 0 )
   {
@@ -133,11 +142,18 @@
     layItem->setData( 0, Qt::UserRole, QVariant::fromValue( dynamic_cast<QObject*>( layer ) ) );
     lstResults->addTopLevelItem( layItem );
 
-    connect( layer, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
-
     QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer*>( layer );
     if ( vlayer )
+    {
+      connect( vlayer, SIGNAL( layerDeleted() ), this, SLOT( layerDestroyed() ) );
       connect( vlayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
+      connect( vlayer, SIGNAL( editingStarted() ), this, SLOT( addEditAction() ) );
+      connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( removeEditAction() ) );
+    }
+    else
+    {
+      connect( layer, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
+    }
   }
 
   QTreeWidgetItem *featItem = new QTreeWidgetItem( QStringList() << displayField << displayValue );
@@ -151,6 +167,7 @@
   if ( derivedAttributes.size() >= 0 )
   {
     QTreeWidgetItem *derivedItem = new QTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
+    derivedItem->setData( 0, Qt::UserRole, "derived" );
     featItem->addChild( derivedItem );
 
     for ( QMap< QString, QString>::const_iterator it = derivedAttributes.begin(); it != derivedAttributes.end(); it++ )
@@ -159,6 +176,31 @@
     }
   }
 
+  if ( vlayer && (vlayer->actions()->size() > 0 || vlayer->isEditable() ) )
+  {
+    QTreeWidgetItem *actionItem = new QTreeWidgetItem( QStringList() << tr( "(Actions)" ) );
+    actionItem->setData( 0, Qt::UserRole, "actions" );
+    featItem->addChild( actionItem );
+
+    QTreeWidgetItem *twi;
+
+    if ( vlayer->isEditable() )
+    {
+      addEditAction( actionItem );
+    }
+
+    for ( int i = 0; i < vlayer->actions()->size(); i++ )
+    {
+      QgsAttributeAction::aIter iter = vlayer->actions()->retrieveAction( i );
+
+      twi = new QTreeWidgetItem( QStringList() << "" << iter->name() );
+      twi->setIcon( 0, QgisApp::getThemeIcon( "/mAction.png" ) );
+      twi->setData( 0, Qt::UserRole, "action" );
+      twi->setData( 0, Qt::UserRole + 1, QVariant::fromValue( i ) );
+      actionItem->addChild( twi );
+    }
+  }
+
   layItem->addChild( featItem );
 }
 
@@ -177,12 +219,17 @@
     if ( layItem->childCount() == 1 )
     {
       QgsVectorLayer *layer = dynamic_cast<QgsVectorLayer *>( layItem->data( 0, Qt::UserRole ).value<QObject *>() );
-      if ( layer && layer->isEditable() )
+      if ( layer )
       {
-        // if this is the only feature, it's on a vector layer and that layer is editable:
-        // don't show the edit dialog instead of the results window
-        editFeature( featItem );
-        return;
+        highlightFeature( featItem );
+
+        if ( layer->isEditable() )
+        {
+          // if this is the only feature, it's on a vector layer and that layer is editable:
+          // don't show the edit dialog instead of the results window
+          editFeature( featItem );
+          return;
+        }
       }
     }
 
@@ -209,6 +256,90 @@
   close();
 }
 
+void QgsIdentifyResults::addEditAction( QTreeWidgetItem *item )
+{
+  QTreeWidgetItem *editItem = new QTreeWidgetItem( QStringList() << "" << tr( "Edit feature" ) );
+  editItem->setIcon( 0, QgisApp::getThemeIcon( "/mIconEditable.png" ) );
+  editItem->setData( 0, Qt::UserRole, "edit" );
+  item->addChild( editItem );
+}
+
+void QgsIdentifyResults::addOrRemoveEditAction( bool addItem )
+{
+  QTreeWidgetItem *layItem = layerItem( sender() );
+
+  for ( int i = 0; i < layItem->childCount(); i++ )
+  {
+    QTreeWidgetItem *featItem = layItem->child( i );
+    QTreeWidgetItem *actionsItem = 0;
+
+    for ( int j = 0; j < featItem->childCount(); j++ )
+    {
+      QTreeWidgetItem *attrItem = featItem->child( j );
+
+      if ( attrItem->childCount() == 0 || attrItem->data( 0, Qt::UserRole ).toString() != "actions" )
+        continue;
+
+      actionsItem = attrItem;
+      break;
+    }
+
+    if ( addItem )
+    {
+      if( !actionsItem )
+      {
+        actionsItem = new QTreeWidgetItem( QStringList() << tr( "(Actions)" ) );
+        actionsItem->setData( 0, Qt::UserRole, "actions" );
+        featItem->addChild( actionsItem );
+      }
+
+      addEditAction( actionsItem );
+    }
+    else if( actionsItem )
+    {
+      for ( int k = 0; k < actionsItem->childCount(); k++ )
+      {
+        QTreeWidgetItem *editItem = actionsItem->child( k );
+        if ( editItem->data( 0, Qt::UserRole ).toString() != "edit" )
+          continue;
+
+        delete editItem;
+
+        if( actionsItem->childCount()==0 )
+          delete actionsItem;
+         
+        break;
+      }
+    }
+    else
+    {
+      QgsDebugMsg( "actions item not found" );
+    }
+  }
+}
+
+void QgsIdentifyResults::addEditAction()
+{
+  addOrRemoveEditAction( true );
+}
+
+void QgsIdentifyResults::removeEditAction()
+{
+  addOrRemoveEditAction( false );
+}
+
+void QgsIdentifyResults::itemClicked( QTreeWidgetItem *item, int column )
+{
+  if ( item->data( 0, Qt::UserRole ).toString() == "edit" )
+  {
+    editFeature( item );
+  }
+  else if ( item->data( 0, Qt::UserRole ).toString() == "action" )
+  {
+    doAction( item, item->data( 0, Qt::UserRole + 1 ).toInt() );
+  }
+}
+
 // Popup (create if necessary) a context menu that contains a list of
 // actions that can be applied to the data in the identify results
 // dialog box.
@@ -235,19 +366,29 @@
   {
     a = mActionPopup->addAction( tr( "Edit feature" ) );
     a->setEnabled( true );
-    a->setData( QVariant::fromValue( -4 ) );
+    a->setData( QVariant::fromValue( -6 ) );
   }
 
   a = mActionPopup->addAction( tr( "Zoom to feature" ) );
   a->setEnabled( true );
-  a->setData( QVariant::fromValue( -3 ) );
+  a->setData( QVariant::fromValue( -5 ) );
 
   a = mActionPopup->addAction( tr( "Copy attribute value" ) );
   a->setEnabled( true );
-  a->setData( QVariant::fromValue( -2 ) );
+  a->setData( QVariant::fromValue( -4 ) );
 
   a = mActionPopup->addAction( tr( "Copy feature attributes" ) );
   a->setEnabled( true );
+  a->setData( QVariant::fromValue( -3 ) );
+
+  mActionPopup->addSeparator();
+
+  a = mActionPopup->addAction( tr( "Expand all" ) );
+  a->setEnabled( true );
+  a->setData( QVariant::fromValue( -2 ) );
+
+  a = mActionPopup->addAction( tr( "Collapse all" ) );
+  a->setEnabled( true );
   a->setData( QVariant::fromValue( -1 ) );
 
   QgsAttributeAction *actions = vlayer->actions();
@@ -310,36 +451,50 @@
 
   if ( action < 0 )
   {
-    if ( action == -4 )
+    switch ( action )
     {
-      editFeature( item );
-    }
-    else if ( action == -3 )
-    {
-      zoomToFeature( item );
-    }
-    else
-    {
-      QClipboard *clipboard = QApplication::clipboard();
-      QString text;
+      case -6:
+        editFeature( item );
+        break;
 
-      if ( action == -2 )
+      case -5:
+        zoomToFeature( item );
+        break;
+
+      case -4:
+      case -3:
       {
-        text = item->data( 1, Qt::DisplayRole ).toString();
-      }
-      else
-      {
-        std::vector< std::pair<QString, QString> > attributes;
-        retrieveAttributes( item, attributes );
+        QClipboard *clipboard = QApplication::clipboard();
+        QString text;
 
-        for ( std::vector< std::pair<QString, QString> >::iterator it = attributes.begin(); it != attributes.end(); it++ )
+        if ( action == -4 )
         {
-          text += QString( "%1: %2\n" ).arg( it->first ).arg( it->second );
+          text = item->data( 1, Qt::DisplayRole ).toString();
         }
+        else
+        {
+          std::vector< std::pair<QString, QString> > attributes;
+          retrieveAttributes( item, attributes );
+
+          for ( std::vector< std::pair<QString, QString> >::iterator it = attributes.begin(); it != attributes.end(); it++ )
+          {
+            text += QString( "%1: %2\n" ).arg( it->first ).arg( it->second );
+          }
+        }
+
+        QgsDebugMsg( QString( "set clipboard: %1" ).arg( text ) );
+        clipboard->setText( text );
       }
+      break;
 
-      QgsDebugMsg( QString( "set clipboard: %1" ).arg( text ) );
-      clipboard->setText( text );
+      case -2:
+        lstResults->expandAll();
+        break;
+
+      case -1:
+        lstResults->collapseAll();
+        break;
+
     }
   }
   else
@@ -356,6 +511,11 @@
 
 void QgsIdentifyResults::clear()
 {
+  for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
+  {
+    disconnectLayer( lstResults->topLevelItem( i )->data( 0, Qt::UserRole ).value<QObject *>() );
+  }
+
   lstResults->clear();
   clearRubberBand();
 }
@@ -431,7 +591,7 @@
     {
       if ( item->parent()->parent()->parent() )
       {
-        // derived attribute item
+        // derived or action attribute item
         featItem = item->parent()->parent();
       }
       else
@@ -508,12 +668,15 @@
 
 void QgsIdentifyResults::layerDestroyed()
 {
-  if ( mRubberBandLayer == sender() )
+  QObject *theSender = sender();
+
+  if ( mRubberBandLayer == theSender )
   {
     clearRubberBand();
   }
 
-  delete layerItem( sender() );
+  disconnectLayer( theSender );
+  delete layerItem( theSender );
 
   if ( lstResults->topLevelItemCount() == 0 )
   {
@@ -521,6 +684,25 @@
   }
 }
 
+void QgsIdentifyResults::disconnectLayer( QObject *layer )
+{
+  if ( !layer )
+    return;
+
+  QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( layer );
+  if ( vlayer )
+  {
+    disconnect( vlayer, SIGNAL( layerDeleted() ), this, SLOT( layerDestroyed() ) );
+    disconnect( vlayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
+    disconnect( vlayer, SIGNAL( editingStarted() ), this, SLOT( addEditAction() ) );
+    disconnect( vlayer, SIGNAL( editingStopped() ), this, SLOT( removeEditAction() ) );
+  }
+  else
+  {
+    disconnect( layer, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
+  }
+}
+
 void QgsIdentifyResults::featureDeleted( int fid )
 {
   QTreeWidgetItem *layItem = layerItem( sender() );

Modified: trunk/qgis/src/app/qgsidentifyresults.h
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.h	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsidentifyresults.h	2009-09-19 22:56:53 UTC (rev 11681)
@@ -93,6 +93,12 @@
     //! sends signal if current feature id has changed
     void handleCurrentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous );
 
+    /* Item in tree was clicked */
+    void itemClicked( QTreeWidgetItem *lvi, int column );
+
+    void addEditAction();
+    void removeEditAction();
+
   private:
     QMenu *mActionPopup;
     QgsVectorLayer *mRubberBandLayer;
@@ -107,6 +113,9 @@
     QTreeWidgetItem *layerItem( QObject *layer );
     QTreeWidgetItem *retrieveAttributes( QTreeWidgetItem *item, std::vector< std::pair<QString, QString> > &attributes );
     void clearRubberBand();
+    void addEditAction( QTreeWidgetItem * );
+    void addOrRemoveEditAction( bool addItem );
+    void disconnectLayer( QObject *object );
 
     void setColumnText( int column, const QString & label );
     void expandColumnsToFit();

Modified: trunk/qgis/src/app/qgsmaptoolidentify.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolidentify.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsmaptoolidentify.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -111,7 +111,7 @@
       QgsMapLayer *layer = mCanvas->layer( i );
 
       emit identifyProgress( i, mCanvas->layerCount() );
-      emit identifyMessage( tr("Identifying on %1...").arg( layer->name() ) );
+      emit identifyMessage( tr( "Identifying on %1..." ).arg( layer->name() ) );
 
       if ( noIdentifyLayerIdList.contains( layer->getLayerID() ) )
         continue;
@@ -125,7 +125,7 @@
     }
 
     emit identifyProgress( mCanvas->layerCount(), mCanvas->layerCount() );
-    emit identifyMessage( tr("Identifying done.") );
+    emit identifyMessage( tr( "Identifying done." ) );
 
     disconnect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
     disconnect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );
@@ -243,15 +243,29 @@
 
     for ( QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it )
     {
-      QString attributeName = layer->attributeDisplayName( it.key() );
+      QString attributeName  = layer->attributeDisplayName( it.key() );
+      QString attributeValue = it->isNull() ? "NULL" : it->toString();
 
+      switch ( layer->editType( it.key() ) )
+      {
+        case QgsVectorLayer::Hidden:
+          continue;
+
+        case QgsVectorLayer::ValueMap:
+          attributeValue = layer->valueMap( it.key() ).key( it->toString(), QString( "(%1)" ).arg( it->toString() ) );
+          break;
+
+        default:
+          break;
+      }
+
       if ( fields[it.key()].name() == layer->displayField() )
       {
         displayField = attributeName;
-        displayValue = it->toString();
+        displayValue = attributeValue;
       }
 
-      attributes.insert( attributeName, it->isNull() ? "NULL" : it->toString() );
+      attributes.insert( attributeName, attributeValue );
     }
 
     // Calculate derived attributes and insert:
@@ -294,6 +308,8 @@
       derivedAttributes.insert( "Y", str );
     }
 
+    derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : QString::number( fid ) );
+
     mResults->addFeature( layer, fid, displayField, displayValue, attributes, derivedAttributes );
   }
 

Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -557,6 +557,7 @@
   editTypeMap.insert( QgsVectorLayer::FileName, tr( "File name" ) );
   editTypeMap.insert( QgsVectorLayer::Enumeration, tr( "Enumeration" ) );
   editTypeMap.insert( QgsVectorLayer::Immutable, tr( "Immutable" ) );
+  editTypeMap.insert( QgsVectorLayer::Hidden, tr( "Hidden" ) );
 }
 
 QString QgsVectorLayerProperties::editTypeButtonText( QgsVectorLayer::EditType type )

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2009-09-19 22:56:53 UTC (rev 11681)
@@ -787,7 +787,7 @@
   {
     p.setPen( QColor( 50, 100, 120, 200 ) );
     p.setBrush( QColor( 200, 200, 210, 120 ) );
-    p.drawEllipse( x-m, y-m, m*2+1, m*2+1 );
+    p.drawEllipse( x - m, y - m, m*2 + 1, m*2 + 1 );
   }
   else if ( type == QgsVectorLayer::Cross )
   {
@@ -3499,7 +3499,7 @@
 
       transformPoint( x, y, &renderContext.mapToPixel(), renderContext.coordinateTransform() );
       if ( std::abs( x ) > QgsClipper::MAX_X ||
-             std::abs( y ) > QgsClipper::MAX_Y )
+           std::abs( y ) > QgsClipper::MAX_Y )
       {
         break;
       }
@@ -3695,7 +3695,7 @@
   const QgsFieldMap &fields = pendingFields();
 
   // FIXME: throw an exception!?
-  if ( fields.contains( idx ) )
+  if ( !fields.contains( idx ) )
   {
     QgsDebugMsg( QString( "field %1 not found" ).arg( idx ) );
   }

Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/core/qgsvectorlayer.h	2009-09-19 22:56:53 UTC (rev 11681)
@@ -75,7 +75,8 @@
       SliderRange,
       FileName,
       Enumeration,
-      Immutable /*The attribute value should not be changed in the attribute form*/
+      Immutable,   /*The attribute value should not be changed in the attribute form*/
+      Hidden       /*The attribute value should not be shown in the attribute form @added in 1.4 */
     };
 
     struct RangeData

Modified: trunk/qgis/src/ui/qgsattributetypeedit.ui
===================================================================
--- trunk/qgis/src/ui/qgsattributetypeedit.ui	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/ui/qgsattributetypeedit.ui	2009-09-19 22:56:53 UTC (rev 11681)
@@ -56,15 +56,20 @@
        <string>Immutable</string>
       </property>
      </item>
+     <item>
+      <property name="text">
+       <string>Hidden</string>
+      </property>
+     </item>
     </widget>
    </item>
    <item>
     <widget class="QStackedWidget" name="stackedWidget">
      <property name="currentIndex">
-      <number>5</number>
+      <number>0</number>
      </property>
      <widget class="QWidget" name="lineEditPage">
-      <layout class="QVBoxLayout" name="verticalLayout_9">
+      <layout class="QVBoxLayout" name="verticalLayout_1">
        <item>
         <widget class="QLabel" name="lineEditLabel">
          <property name="text">
@@ -432,7 +437,7 @@
        <item>
         <widget class="QLabel" name="immutableLabel">
          <property name="text">
-          <string>Immutable attribute is read-only - user is not able to modify the contents.</string>
+          <string>An immutable attribute is read-only - the user is not able to modify the contents.</string>
          </property>
          <property name="wordWrap">
           <bool>true</bool>
@@ -454,6 +459,33 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="hiddenPage">
+      <layout class="QVBoxLayout" name="verticalLayout_9">
+       <item>
+        <widget class="QLabel" name="hiddenLabel">
+         <property name="text">
+          <string>A hidden attribute will be invisible - the user is not able to see it's contents.</string>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer_7">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>304</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </item>
    <item>

Modified: trunk/qgis/src/ui/qgsidentifyresultsbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsidentifyresultsbase.ui	2009-09-19 13:02:49 UTC (rev 11680)
+++ trunk/qgis/src/ui/qgsidentifyresultsbase.ui	2009-09-19 22:56:53 UTC (rev 11681)
@@ -1,64 +1,73 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>QgsIdentifyResultsBase</class>
- <widget class="QDialog" name="QgsIdentifyResultsBase" >
-  <property name="geometry" >
+ <widget class="QDialog" name="QgsIdentifyResultsBase">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>281</width>
+    <width>301</width>
     <height>316</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Identify Results</string>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
+  <layout class="QVBoxLayout">
+   <property name="spacing">
+    <number>6</number>
+   </property>
+   <property name="margin">
     <number>9</number>
    </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
    <item>
-    <widget class="QTreeWidget" name="lstResults" >
-     <property name="lineWidth" >
+    <widget class="QTreeWidget" name="lstResults">
+     <property name="lineWidth">
       <number>2</number>
      </property>
-     <property name="sortingEnabled" >
+     <property name="alternatingRowColors">
       <bool>true</bool>
      </property>
+     <property name="sortingEnabled">
+      <bool>true</bool>
+     </property>
+     <column>
+      <property name="text">
+       <string notr="true">1</string>
+      </property>
+     </column>
     </widget>
    </item>
    <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
+    <layout class="QHBoxLayout">
+     <property name="spacing">
+      <number>6</number>
+     </property>
+     <property name="margin">
       <number>0</number>
      </property>
-     <property name="spacing" >
-      <number>6</number>
-     </property>
      <item>
-      <widget class="QPushButton" name="buttonHelp" >
-       <property name="text" >
+      <widget class="QPushButton" name="buttonHelp">
+       <property name="text">
         <string>Help</string>
        </property>
-       <property name="shortcut" >
+       <property name="shortcut">
         <string>F1</string>
        </property>
-       <property name="autoDefault" >
+       <property name="autoDefault">
         <bool>true</bool>
        </property>
       </widget>
      </item>
      <item>
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>20</width>
          <height>0</height>
@@ -67,14 +76,14 @@
       </spacer>
      </item>
      <item>
-      <widget class="QPushButton" name="buttonCancel" >
-       <property name="text" >
+      <widget class="QPushButton" name="buttonCancel">
+       <property name="text">
         <string>Close</string>
        </property>
-       <property name="shortcut" >
+       <property name="shortcut">
         <string/>
        </property>
-       <property name="autoDefault" >
+       <property name="autoDefault">
         <bool>true</bool>
        </property>
       </widget>
@@ -83,7 +92,7 @@
    </item>
   </layout>
  </widget>
- <layoutdefault spacing="6" margin="11" />
+ <layoutdefault spacing="6" margin="11"/>
  <resources/>
  <connections/>
 </ui>



More information about the QGIS-commit mailing list