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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Apr 5 13:19:07 EDT 2010


Author: jef
Date: 2010-04-05 13:19:07 -0400 (Mon, 05 Apr 2010)
New Revision: 13252

Modified:
   trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp
   trunk/qgis/src/app/qgsattributetypedialog.cpp
   trunk/qgis/src/app/qgsvectorlayerproperties.cpp
   trunk/qgis/src/core/qgsvectorlayer.h
   trunk/qgis/src/gui/qgsattributeeditor.cpp
   trunk/qgis/src/gui/qgsattributeeditor.h
   trunk/qgis/src/ui/qgsattributetypeedit.ui
Log:
add widget support for dials and calendar

Modified: trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp	2010-04-05 17:17:05 UTC (rev 13251)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp	2010-04-05 17:19:07 UTC (rev 13252)
@@ -69,7 +69,8 @@
     QgsAttributeTableView *tv = dynamic_cast<QgsAttributeTableView *>( parent->parentWidget() );
     w->setMinimumWidth( tv->columnWidth( index.column() ) );
 
-    if ( vl->editType( fieldIdx( index ) ) == QgsVectorLayer::FileName )
+    if ( vl->editType( fieldIdx( index ) ) == QgsVectorLayer::FileName ||
+         vl->editType( fieldIdx( index ) ) == QgsVectorLayer::Calendar )
     {
       QLineEdit *le = w->findChild<QLineEdit*>();
       le->adjustSize();

Modified: trunk/qgis/src/app/qgsattributetypedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetypedialog.cpp	2010-04-05 17:17:05 UTC (rev 13251)
+++ trunk/qgis/src/app/qgsattributetypedialog.cpp	2010-04-05 17:19:07 UTC (rev 13252)
@@ -217,6 +217,7 @@
 
     case QgsVectorLayer::EditRange:
     case QgsVectorLayer::SliderRange:
+    case QgsVectorLayer::DialRange:
       setPage( 2 );
       break;
 
@@ -252,6 +253,9 @@
     case QgsVectorLayer::TextEdit:
       setPage( 10 );
 
+    case QgsVectorLayer::Calendar:
+      setPage( 11 );
+
     case QgsVectorLayer::LineEdit:
       setPage( 0 );
       break;
@@ -297,7 +301,8 @@
   //calculate min and max for range for this field
   if ( mLayer->pendingFields()[index].type() == QVariant::Int )
   {
-    sliderRadioButton->setDisabled( false );
+    rangeWidget->clear();
+    rangeWidget->addItems( QStringList() << tr( "Editable" ) << tr( "Slider" ) << tr( "Dial" ) );
     int min = INT_MIN;
     int max = INT_MAX;
     while ( mLayer->nextFeature( f ) )
@@ -319,8 +324,8 @@
     double dMin = -DBL_MAX;
     double dMax = DBL_MAX;
 
-    sliderRadioButton->setDisabled( true );
-    editableRadioButton->setChecked( true );
+    rangeWidget->clear();
+    rangeWidget->addItems( QStringList() << tr( "Editable" ) << tr( "Slider" ) );
     while ( mLayer->nextFeature( f ) )
     {
       QVariant val = f.attributeMap()[index];
@@ -386,6 +391,7 @@
 
     case QgsVectorLayer::EditRange:
     case QgsVectorLayer::SliderRange:
+    case QgsVectorLayer::DialRange:
     {
       if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int )
       {
@@ -400,9 +406,17 @@
         stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() );
       }
       if ( editType == QgsVectorLayer::EditRange )
-        editableRadioButton->setChecked( true );
-      else //slider range
-        sliderRadioButton->setChecked( true );
+      {
+        rangeWidget->setCurrentIndex( 0 );
+      }
+      else if ( editType == QgsVectorLayer::SliderRange )
+      {
+        rangeWidget->setCurrentIndex( 1 );
+      }
+      else
+      {
+        rangeWidget->setCurrentIndex( 2 );
+      }
     }
     break;
 
@@ -418,13 +432,13 @@
 
 void QgsAttributeTypeDialog::setPage( int index )
 {
-  this->selectionComboBox->setCurrentIndex( index );
+  selectionComboBox->setCurrentIndex( index );
   setStackPage( index );
 }
 
 void QgsAttributeTypeDialog::setStackPage( int index )
 {
-  this->stackedWidget->setCurrentIndex( index );
+  stackedWidget->setCurrentIndex( index );
 
   bool okDisabled = false;
   if ( index == 2 )
@@ -436,7 +450,7 @@
     }
     else if ( mLayer->pendingFields()[mIndex].type() != QVariant::Double )
     {
-      this->rangeStackedWidget->setCurrentIndex( 0 );
+      rangeStackedWidget->setCurrentIndex( 0 );
       //load data
       minimumSpinBox->setValue( mRangeData.mMin.toInt() );
       maximumSpinBox->setValue( mRangeData.mMax.toInt() );
@@ -444,7 +458,7 @@
     }
     else
     {
-      this->rangeStackedWidget->setCurrentIndex( 1 );
+      rangeStackedWidget->setCurrentIndex( 1 );
       //load data
       minimumDoubleSpinBox->setValue( mRangeData.mMin.toDouble() );
       maximumDoubleSpinBox->setValue( mRangeData.mMax.toDouble() );
@@ -497,14 +511,18 @@
                                                 stepDoubleSpinBox->value() );
       }
       //select correct one
-      if ( editableRadioButton->isChecked() )
+      switch ( rangeWidget->currentIndex() )
       {
-        mEditType = QgsVectorLayer::EditRange;
+        case 0:
+          mEditType = QgsVectorLayer::EditRange;
+          break;
+        case 1:
+          mEditType = QgsVectorLayer::SliderRange;
+          break;
+        case 2:
+          mEditType = QgsVectorLayer::DialRange;
+          break;
       }
-      else
-      {
-        mEditType = QgsVectorLayer::SliderRange;
-      }
       break;
     case 3:
       if ( editableUniqueValues->isChecked() )
@@ -550,6 +568,9 @@
     case 10:
       mEditType = QgsVectorLayer::TextEdit;
       break;
+    case 11:
+      mEditType = QgsVectorLayer::Calendar;
+      break;
   }
 
   QDialog::accept();

Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2010-04-05 17:17:05 UTC (rev 13251)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2010-04-05 17:19:07 UTC (rev 13252)
@@ -271,6 +271,7 @@
       break;
     case QgsVectorLayer::EditRange:
     case QgsVectorLayer::SliderRange:
+    case QgsVectorLayer::DialRange:
       mRanges.insert( index, attributeTypeDialog.rangeData() );
       break;
     case QgsVectorLayer::CheckBox:
@@ -532,12 +533,14 @@
   editTypeMap.insert( QgsVectorLayer::ValueMap, tr( "Value map" ) );
   editTypeMap.insert( QgsVectorLayer::EditRange, tr( "Edit range" ) );
   editTypeMap.insert( QgsVectorLayer::SliderRange, tr( "Slider range" ) );
+  editTypeMap.insert( QgsVectorLayer::DialRange, tr( "Dial range" ) );
   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" ) );
   editTypeMap.insert( QgsVectorLayer::CheckBox, tr( "Checkbox" ) );
   editTypeMap.insert( QgsVectorLayer::TextEdit, tr( "Text edit" ) );
+  editTypeMap.insert( QgsVectorLayer::Calendar, tr( "Calendar" ) );
 }
 
 QString QgsVectorLayerProperties::editTypeButtonText( QgsVectorLayer::EditType type )
@@ -604,7 +607,8 @@
       }
     }
     else if ( editType == QgsVectorLayer::EditRange ||
-              editType == QgsVectorLayer::SliderRange )
+              editType == QgsVectorLayer::SliderRange ||
+              editType == QgsVectorLayer::DialRange )
     {
       if ( mRanges.contains( idx ) )
       {
@@ -628,7 +632,6 @@
   }
   else
   {
-
     QgsSingleSymbolDialog *sdialog =
       qobject_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
     QgsGraduatedSymbolDialog *gdialog =

Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h	2010-04-05 17:17:05 UTC (rev 13251)
+++ trunk/qgis/src/core/qgsvectorlayer.h	2010-04-05 17:19:07 UTC (rev 13252)
@@ -75,9 +75,11 @@
       CheckBox,    /* added in 1.4 */
       FileName,
       Enumeration,
-      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 */
-      TextEdit     /*multiline edit @added in 1.4*/
+      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 */
+      TextEdit,    /* multiline edit @added in 1.4*/
+      Calendar,    /* calendar widget @added in 1.5 */
+      DialRange,   /* dial range @added in 1.5 */
     };
 
     struct RangeData

Modified: trunk/qgis/src/gui/qgsattributeeditor.cpp
===================================================================
--- trunk/qgis/src/gui/qgsattributeeditor.cpp	2010-04-05 17:17:05 UTC (rev 13251)
+++ trunk/qgis/src/gui/qgsattributeeditor.cpp	2010-04-05 17:19:07 UTC (rev 13252)
@@ -33,6 +33,9 @@
 #include <QCompleter>
 #include <QHBoxLayout>
 #include <QPlainTextEdit>
+#include <QDial>
+#include <QCalendarWidget>
+#include <QDialogButtonBox>
 
 void QgsAttributeEditor::selectFileName( void )
 {
@@ -55,6 +58,42 @@
   le->setText( fileName );
 }
 
+void QgsAttributeEditor::selectDate( void )
+{
+  QPushButton *pb = qobject_cast<QPushButton *>( sender() );
+  if ( !pb )
+    return;
+
+  QWidget *hbox = qobject_cast<QWidget *>( pb->parent() );
+  if ( !hbox )
+    return;
+
+  QLineEdit *le = hbox->findChild<QLineEdit *>();
+  if ( !le )
+    return;
+
+  QDialog *dlg = new QDialog();
+  dlg->setWindowTitle( tr( "Select a date" ) );
+  QVBoxLayout *vl = new QVBoxLayout( dlg );
+
+  QCalendarWidget *cw = new QCalendarWidget( dlg );
+  cw->setSelectedDate( QDate::fromString( le->text(), Qt::ISODate ) );
+  vl->addWidget( cw );
+
+  QDialogButtonBox *buttonBox = new QDialogButtonBox( dlg );
+  buttonBox->addButton( QDialogButtonBox::Ok );
+  buttonBox->addButton( QDialogButtonBox::Cancel );
+  vl->addWidget( buttonBox );
+
+  connect( buttonBox, SIGNAL( accepted() ), dlg, SLOT( accept() ) );
+  connect( buttonBox, SIGNAL( rejected() ), dlg, SLOT( reject() ) );
+
+  if ( dlg->exec() == QDialog::Accepted )
+  {
+    le->setText( cw->selectedDate().toString( Qt::ISODate ) );
+  }
+}
+
 QComboBox *QgsAttributeEditor::comboBox( QWidget *editor, QWidget *parent )
 {
   QComboBox *cb = NULL;
@@ -180,6 +219,8 @@
     }
     break;
 
+
+    case QgsVectorLayer::DialRange:
     case QgsVectorLayer::SliderRange:
     case QgsVectorLayer::EditRange:
     {
@@ -208,12 +249,20 @@
         }
         else
         {
-          QSlider *sl = NULL;
+          QAbstractSlider *sl = NULL;
 
           if ( editor )
-            sl = qobject_cast<QSlider*>( editor );
+          {
+            sl = qobject_cast<QAbstractSlider*>( editor );
+          }
+          else if ( editType == QgsVectorLayer::DialRange )
+          {
+            sl = new QDial( parent );
+          }
           else
+          {
             sl = new QSlider( Qt::Horizontal, parent );
+          }
 
           if ( sl )
           {
@@ -335,6 +384,7 @@
       break;
 
     case QgsVectorLayer::FileName:
+    case QgsVectorLayer::Calendar:
     {
       QPushButton *pb = NULL;
       QLineEdit *le = qobject_cast<QLineEdit *>( editor );
@@ -365,20 +415,19 @@
       }
 
       if ( pb )
-        connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
+      {
+        if ( editType == QgsVectorLayer::FileName )
+          connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
+        if ( editType == QgsVectorLayer::Calendar )
+          connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) );
+      }
     }
     break;
 
     case QgsVectorLayer::Immutable:
       return NULL;
-
   }
 
-  if ( editType == QgsVectorLayer::Immutable )
-  {
-    myWidget->setEnabled( false );
-  }
-
   setValue( myWidget, vl, idx, value );
 
   return myWidget;
@@ -448,7 +497,7 @@
     text = QString::number( sb->value() );
   }
 
-  QSlider *slider = qobject_cast<QSlider *>( widget );
+  QAbstractSlider *slider = qobject_cast<QAbstractSlider *>( widget );
   if ( slider )
   {
     text = QString::number( slider->value() );
@@ -467,6 +516,12 @@
     text = ckb->isChecked() ? states.first : states.second;
   }
 
+  QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( widget );
+  if ( cw )
+  {
+    text = cw->selectedDate().toString();
+  }
+
   le = widget->findChild<QLineEdit *>();
   if ( le )
   {
@@ -505,6 +560,20 @@
       }
     }
     break;
+    case QVariant::Date:
+    {
+      QDate myDateValue = QDate::fromString( text, Qt::ISODate );
+      if ( myDateValue.isValid() && !text.isEmpty() )
+      {
+        value = myDateValue;
+        modified = true;
+      }
+      else if ( modified )
+      {
+        value = QVariant( theField.type() );
+      }
+    }
+    break;
     default: //string
       modified = true;
       value = QVariant( text );
@@ -542,6 +611,7 @@
     }
     break;
 
+    case QgsVectorLayer::DialRange:
     case QgsVectorLayer::SliderRange:
     case QgsVectorLayer::EditRange:
     {
@@ -556,7 +626,7 @@
         }
         else
         {
-          QSlider *sl = qobject_cast<QSlider *>( editor );
+          QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor );
           if ( sl == NULL )
             return false;
           sl->setValue( value.toInt() );
@@ -615,6 +685,7 @@
     break;
 
     case QgsVectorLayer::FileName:
+    case QgsVectorLayer::Calendar:
     {
       QLineEdit *le = editor->findChild<QLineEdit *>();
       if ( le == NULL )

Modified: trunk/qgis/src/gui/qgsattributeeditor.h
===================================================================
--- trunk/qgis/src/gui/qgsattributeeditor.h	2010-04-05 17:17:05 UTC (rev 13251)
+++ trunk/qgis/src/gui/qgsattributeeditor.h	2010-04-05 17:19:07 UTC (rev 13252)
@@ -40,6 +40,7 @@
 
   public slots:
     void selectFileName( void );
+    void selectDate( void );
 };
 
 

Modified: trunk/qgis/src/ui/qgsattributetypeedit.ui
===================================================================
--- trunk/qgis/src/ui/qgsattributetypeedit.ui	2010-04-05 17:17:05 UTC (rev 13251)
+++ trunk/qgis/src/ui/qgsattributetypeedit.ui	2010-04-05 17:19:07 UTC (rev 13252)
@@ -71,6 +71,11 @@
        <string>Text edit</string>
       </property>
      </item>
+     <item>
+      <property name="text">
+       <string>Calendar</string>
+      </property>
+     </item>
     </widget>
    </item>
    <item>
@@ -150,6 +155,9 @@
           </widget>
          </item>
          <item>
+          <widget class="QComboBox" name="rangeWidget"/>
+         </item>
+         <item>
           <layout class="QGridLayout" name="gridRangeLayout">
            <item row="0" column="0">
             <widget class="QLabel" name="minimumLabel">
@@ -244,23 +252,6 @@
           </layout>
          </item>
          <item>
-          <widget class="QRadioButton" name="sliderRadioButton">
-           <property name="text">
-            <string>Slider</string>
-           </property>
-           <property name="checked">
-            <bool>true</bool>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QRadioButton" name="editableRadioButton">
-           <property name="text">
-            <string>Editable</string>
-           </property>
-          </widget>
-         </item>
-         <item>
           <widget class="QLabel" name="valuesLabel">
            <property name="text">
             <string>Local minimum/maximum = 0/0</string>
@@ -576,6 +567,30 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="calendarPage">
+      <layout class="QVBoxLayout" name="verticalLayout_6">
+       <item>
+        <widget class="QLabel" name="label_4">
+         <property name="text">
+          <string>A calendar widget to enter a date.</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer_9">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>303</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </item>
    <item>



More information about the QGIS-commit mailing list