[QGIS Commit] r15054 - in trunk/qgis/src: app app/attributetable gui ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Jan 17 16:51:58 EST 2011


Author: jef
Date: 2011-01-17 13:51:58 -0800 (Mon, 17 Jan 2011)
New Revision: 15054

Modified:
   trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
   trunk/qgis/src/app/qgsattributedialog.cpp
   trunk/qgis/src/app/qgsattributetypeloaddialog.cpp
   trunk/qgis/src/app/qgsclipboard.cpp
   trunk/qgis/src/app/qgsoptions.cpp
   trunk/qgis/src/gui/qgsattributeeditor.cpp
   trunk/qgis/src/gui/qgsattributeeditor.h
   trunk/qgis/src/ui/qgsoptionsbase.ui
Log:
[FEATURE] feature form updates:
- make NULL value string representation configurable
- fix feature updates in feature form from attribute table
- add support for NULL values in value maps (comboboxes)
- use layer names instead of ids in drop down list when loading value
  maps from layers.
- support feature form expression fields: line edits on the form
  which name prefix "expr_" are evaluated.  Their value is interpreted
  as field calculator string and replaced with the calculated value.
- support search for NULL in attribute table

Modified: trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp	2011-01-17 21:51:58 UTC (rev 15054)
@@ -647,11 +647,25 @@
     sensString = "LIKE";
   }
 
-  QString str = QString( "%1 %2 '%3'" )
-                .arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
-                .arg( numeric ? "=" : sensString )
-                .arg( numeric ? mQuery->displayText().replace( "'", "''" ) :
-                      "%" + mQuery->displayText().replace( "'", "''" ) + "%" ); // escape quotes
+  QSettings settings;
+  QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
+
+  QString str;
+  if ( mQuery->displayText() == nullValue )
+  {
+    str = QString( "%1 IS NULL" ).arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) );
+  }
+  else
+  {
+    str = QString( "%1 %2 '%3'" )
+          .arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
+          .arg( numeric ? "=" : sensString )
+          .arg( numeric
+                ? mQuery->displayText().replace( "'", "''" )
+                :
+                "%" + mQuery->displayText().replace( "'", "''" ) + "%" ); // escape quotes
+  }
+
   doSearch( str );
 }
 

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2011-01-17 21:51:58 UTC (rev 15054)
@@ -414,7 +414,8 @@
     }
     else
     {
-      return QVariant( "NULL" );
+      QSettings settings;
+      return settings.value( "qgis/nullValue", "NULL" );
     }
   }
 
@@ -497,6 +498,7 @@
   QgsFeature f;
   QgsAttributeMap attributes;
 
+  f.setFeatureId( rowToId( idx.row() ) );
   for ( int i = 0; i < mAttributes.size(); i++ )
   {
     f.changeAttribute( i, data( index( idx.row(), i ), Qt::EditRole ) );

Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/app/qgsattributedialog.cpp	2011-01-17 21:51:58 UTC (rev 15054)
@@ -25,6 +25,8 @@
 #include "qgssymbol.h"
 #include "qgsattributeeditor.h"
 #include "qgsrubberband.h"
+#include "qgssearchstring.h"
+#include "qgssearchtreenode.h"
 
 #include "qgisapp.h"
 
@@ -193,6 +195,48 @@
       mpIndizes << it.key();
       mpWidgets << myWidget;
     }
+
+    foreach( QLineEdit *le, mDialog->findChildren<QLineEdit*>() )
+    {
+      if ( !le->objectName().startsWith( "expr_" ) )
+        continue;
+
+      le->setReadOnly( true );
+      QString expr = le->text();
+      le->setText( tr( "Error" ) );
+
+      QgsSearchString ss;
+      if ( !ss.setString( expr ) )
+        continue;
+
+      QgsSearchTreeNode *st = ss.tree();
+      if ( !st )
+        continue;
+
+      if ( !mFeature->geometry() && st->needsGeometry() )
+      {
+        QgsFeature f;
+        if ( vl->featureAtId( mFeature->id(), f, true, false ) && f.geometry() )
+        {
+          mFeature->setGeometry( *f.geometry() );
+        }
+      }
+
+      QgsSearchTreeValue value;
+      st->getValue( value, st, vl->pendingFields(), *mFeature );
+
+      if ( !value.isError() )
+      {
+        if ( value.isNumeric() )
+          le->setText( QString::number( value.number() ) );
+        else
+          le->setText( value.string() );
+      }
+      else
+      {
+        le->setText( tr( "Error: %1" ).arg( st->errorMsg() ) );
+      }
+    }
   }
 
   if ( mDialog )

Modified: trunk/qgis/src/app/qgsattributetypeloaddialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetypeloaddialog.cpp	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/app/qgsattributetypeloaddialog.cpp	2011-01-17 21:51:58 UTC (rev 15054)
@@ -74,7 +74,7 @@
   QMap<QString, QgsMapLayer*>::iterator layer_it = QgsMapLayerRegistry::instance()->mapLayers().begin();
   for ( ; layer_it != QgsMapLayerRegistry::instance()->mapLayers().end(); layer_it++ )
   {
-    layerComboBox->addItem( layer_it.key() );
+    layerComboBox->addItem( layer_it.value()->name(), layer_it.key() );
   }
 }
 
@@ -89,7 +89,7 @@
     return;
   }
 
-  QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
+  QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
   QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
   if ( vLayer == NULL )
   {
@@ -120,7 +120,7 @@
   }
   int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
   int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
-  QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
+  QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
   QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
   if ( vLayer == NULL )
   {
@@ -170,7 +170,7 @@
   mValueMap.clear();
   int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
   int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
-  QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
+  QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
   QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
   if ( vLayer == NULL )
   {

Modified: trunk/qgis/src/app/qgsclipboard.cpp
===================================================================
--- trunk/qgis/src/app/qgsclipboard.cpp	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/app/qgsclipboard.cpp	2011-01-17 21:51:58 UTC (rev 15054)
@@ -23,6 +23,7 @@
 #include <QString>
 #include <QStringList>
 #include <QClipboard>
+#include <QSettings>
 
 #include "qgsclipboard.h"
 #include "qgsfeature.h"
@@ -75,7 +76,10 @@
     if ( it->geometry() )
       textFields += it->geometry()->exportToWkt();
     else
-      textFields += "NULL";
+    {
+      QSettings settings;
+      textFields += settings.value( "qgis/nullValue", "NULL" ).toString();
+    }
 
     // QgsDebugMsg("about to traverse fields.");
     //

Modified: trunk/qgis/src/app/qgsoptions.cpp
===================================================================
--- trunk/qgis/src/app/qgsoptions.cpp	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/app/qgsoptions.cpp	2011-01-17 21:51:58 UTC (rev 15054)
@@ -253,6 +253,7 @@
   cbxAddPostgisDC->setChecked( settings.value( "/qgis/addPostgisDC", false ).toBool() );
   cbxAddNewLayersToCurrentGroup->setChecked( settings.value( "/qgis/addNewLayersToCurrentGroup", false ).toBool() );
   cbxCreateRasterLegendIcons->setChecked( settings.value( "/qgis/createRasterLegendIcons", true ).toBool() );
+  leNullValue->setText( settings.value( "qgis/nullValue", "NULL" ).toString() );
 
   //set the color for selections
   int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt();
@@ -524,6 +525,7 @@
   settings.setValue( "qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
   settings.setValue( "qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
   settings.setValue( "qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
+  settings.setValue( "qgis/nullValue", leNullValue->text() );
 
   //overlay placement method
   int overlayIndex = mOverlayAlgorithmComboBox->currentIndex();

Modified: trunk/qgis/src/gui/qgsattributeeditor.cpp
===================================================================
--- trunk/qgis/src/gui/qgsattributeeditor.cpp	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/gui/qgsattributeeditor.cpp	2011-01-17 21:51:58 UTC (rev 15054)
@@ -37,6 +37,7 @@
 #include <QDial>
 #include <QCalendarWidget>
 #include <QDialogButtonBox>
+#include <QSettings>
 
 void QgsAttributeEditor::selectFileName( void )
 {
@@ -451,12 +452,15 @@
   bool modified = false;
   QString text;
 
+  QSettings settings;
+  QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
+
   QLineEdit *le = qobject_cast<QLineEdit *>( widget );
   if ( le )
   {
     text = le->text();
     modified = le->isModified();
-    if ( text == "NULL" )
+    if ( text == nullValue )
     {
       text = QString::null;
     }
@@ -467,7 +471,7 @@
   {
     text = te->toHtml();
     modified = te->document()->isModified();
-    if ( text == "NULL" )
+    if ( text == nullValue )
     {
       text = QString::null;
     }
@@ -478,7 +482,7 @@
   {
     text = pte->toPlainText();
     modified = pte->document()->isModified();
-    if ( text == "NULL" )
+    if ( text == nullValue )
     {
       text = QString::null;
     }
@@ -492,11 +496,16 @@
          editType == QgsVectorLayer::Classification )
     {
       text = cb->itemData( cb->currentIndex() ).toString();
+      if ( text == nullValue )
+      {
+        text = QString::null;
+      }
     }
     else
     {
       text = cb->currentText();
     }
+    modified = true;
   }
 
   QSpinBox *sb = qobject_cast<QSpinBox *>( widget );
@@ -614,6 +623,9 @@
   const QgsField &field = vl->pendingFields()[idx];
   QVariant::Type myFieldType = field.type();
 
+  QSettings settings;
+  QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
+
   switch ( editType )
   {
     case QgsVectorLayer::Classification:
@@ -621,11 +633,17 @@
     case QgsVectorLayer::Enumeration:
     case QgsVectorLayer::ValueMap:
     {
+      QVariant v = value;
       QComboBox *cb = qobject_cast<QComboBox *>( editor );
       if ( cb == NULL )
         return false;
 
-      int idx = cb->findData( value );
+      if ( v.isNull() )
+      {
+        v = nullValue;
+      }
+
+      int idx = cb->findData( v );
       if ( idx < 0 )
         return false;
 
@@ -693,7 +711,7 @@
         if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
           text = "";
         else
-          text = "NULL";
+          text = nullValue;
       else
         text = value.toString();
 

Modified: trunk/qgis/src/gui/qgsattributeeditor.h
===================================================================
--- trunk/qgis/src/gui/qgsattributeeditor.h	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/gui/qgsattributeeditor.h	2011-01-17 21:51:58 UTC (rev 15054)
@@ -31,7 +31,7 @@
     Q_OBJECT
 
   public:
-    QgsAttributeEditor( QObject *parent ) : QObject( parent ) {}
+    QgsAttributeEditor( QObject *parent ) : QObject( parent ) {};
     static QWidget *createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value );
     static bool retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value );
     static bool setValue( QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value );

Modified: trunk/qgis/src/ui/qgsoptionsbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsoptionsbase.ui	2011-01-17 11:30:52 UTC (rev 15053)
+++ trunk/qgis/src/ui/qgsoptionsbase.ui	2011-01-17 21:51:58 UTC (rev 15054)
@@ -59,9 +59,9 @@
           <property name="geometry">
            <rect>
             <x>0</x>
-            <y>0</y>
-            <width>746</width>
-            <height>545</height>
+            <y>-126</y>
+            <width>744</width>
+            <height>586</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_12">
@@ -168,7 +168,7 @@
              <property name="title">
               <string>Application</string>
              </property>
-             <layout class="QVBoxLayout" name="verticalLayout_9">
+             <layout class="QVBoxLayout" name="verticalLayout_2">
               <item>
                <layout class="QHBoxLayout" name="horizontalLayout_3">
                 <item>
@@ -316,6 +316,33 @@
                 </item>
                </layout>
               </item>
+              <item>
+               <layout class="QHBoxLayout" name="horizontalLayout_6">
+                <item>
+                 <widget class="QLabel" name="label_14">
+                  <property name="text">
+                   <string>Representation for NULL values</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="horizontalSpacer_3">
+                  <property name="orientation">
+                   <enum>Qt::Horizontal</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>40</width>
+                    <height>20</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+                <item>
+                 <widget class="QLineEdit" name="leNullValue"/>
+                </item>
+               </layout>
+              </item>
              </layout>
             </widget>
            </item>
@@ -344,7 +371,7 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>596</width>
+            <width>744</width>
             <height>466</height>
            </rect>
           </property>
@@ -515,8 +542,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>507</width>
-            <height>480</height>
+            <width>744</width>
+            <height>469</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_4">
@@ -795,8 +822,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>264</width>
-            <height>86</height>
+            <width>760</width>
+            <height>460</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_10">
@@ -870,8 +897,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>724</width>
-            <height>438</height>
+            <width>838</width>
+            <height>444</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_13">
@@ -1200,8 +1227,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>371</width>
-            <height>557</height>
+            <width>416</width>
+            <height>568</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_15">
@@ -1297,7 +1324,7 @@
             <x>0</x>
             <y>0</y>
             <width>519</width>
-            <height>545</height>
+            <height>567</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_17">
@@ -1387,8 +1414,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>329</width>
-            <height>531</height>
+            <width>407</width>
+            <height>508</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_20">



More information about the QGIS-commit mailing list