[QGIS Commit] r11761 - trunk/qgis/src/app/attributetable

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Oct 6 17:43:34 EDT 2009


Author: jef
Date: 2009-10-06 17:43:33 -0400 (Tue, 06 Oct 2009)
New Revision: 11761

Modified:
   trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h
   trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp
   trunk/qgis/src/app/attributetable/qgsattributetabledialog.h
   trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h
   trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp
   trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.h
Log:
remove redundancies in QgsAttributeTableMemoryModel and QgsAttributeTableModel

Modified: trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h	2009-10-06 21:43:33 UTC (rev 11761)
@@ -17,7 +17,7 @@
 #define QGSATTRIBUTETABLEDELEGATE_H
 
 #include <QItemDelegate>
-#include "qgsvectorlayer.h"
+
 class QPainter;
 class QgsVectorLayer;
 

Modified: trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp	2009-10-06 21:43:33 UTC (rev 11761)
@@ -218,7 +218,7 @@
 
 void QgsAttributeTableDialog::on_cbxShowSelectedOnly_toggled( bool theFlag )
 {
-  mFilterModel->mHideUnselected = theFlag;
+  mFilterModel->setHideUnselected( theFlag );
   mFilterModel->invalidate();
   //TODO: weird
   //mModel->changeLayout();

Modified: trunk/qgis/src/app/attributetable/qgsattributetabledialog.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledialog.h	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledialog.h	2009-10-06 21:43:33 UTC (rev 11761)
@@ -24,9 +24,6 @@
 
 #include "ui_qgsattributetabledialog.h"
 
-class QgsMapLayer;
-class QgsVectorLayer;
-
 #include "qgsvectorlayer.h" //QgsFeatureIds
 
 class QDialogButtonBox;

Modified: trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h	2009-10-06 21:43:33 UTC (rev 11761)
@@ -20,15 +20,12 @@
 #include <QSortFilterProxyModel>
 #include <QModelIndex>
 
-//QGIS Includes
-#include "qgsvectorlayer.h" //QgsAttributeList
-
 class QgsAttributeTableModel;
+class QgsVectorLayer;
 
 class QgsAttributeTableFilterModel: public QSortFilterProxyModel
 {
   public:
-    bool mHideUnselected;
     /**
      * Constructor
      * @param theLayer initializing layer pointer
@@ -46,6 +43,8 @@
     QgsVectorLayer *layer() const { return mLayer; }
     QgsAttributeTableModel *tableModel() const { return reinterpret_cast<QgsAttributeTableModel*>( sourceModel() ); }
 
+    void setHideUnselected( bool theFlag ) { mHideUnselected = theFlag; }
+
   protected:
     /**
      * Returns true if the source row will be accepted
@@ -55,6 +54,7 @@
     bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
   private:
     QgsVectorLayer* mLayer;
+    bool mHideUnselected;
 };
 
 #endif

Modified: trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp	2009-10-06 21:43:33 UTC (rev 11761)
@@ -46,92 +46,18 @@
   loadLayer();
 }
 
-QVariant QgsAttributeTableMemoryModel::data( const QModelIndex &index, int role ) const
+bool QgsAttributeTableMemoryModel::featureAtId( int fid )
 {
-  if ( !index.isValid() || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole ) )
-    return QVariant();
-
-  QVariant::Type fldType = mLayer->pendingFields()[ mAttributes[index.column()] ].type();
-  bool fldNumeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
-
-  if ( role == Qt::TextAlignmentRole )
+  if ( mFeatureMap.contains( fid ) )
   {
-    if ( fldNumeric )
-      return QVariant( Qt::AlignRight );
-    else
-      return QVariant( Qt::AlignLeft );
+    mFeat = mFeatureMap[ fid ];
+    return true;
   }
-
-  // if we don't have the row in current cache, load it from layer first
-  if ( mLastRowId != rowToId( index.row() ) )
+  else
   {
-    //bool res = mLayer->featureAtId(rowToId(index.row()), mFeat, false, true);
-    bool res = mFeatureMap.contains( rowToId( index.row() ) );
-
-    if ( !res )
-      return QVariant( "ERROR" );
-
-    mLastRowId = rowToId( index.row() );
-    mFeat = mFeatureMap[rowToId( index.row() )];
-    mLastRow = ( QgsAttributeMap * ) & mFeat.attributeMap();
-  }
-
-  if ( !mLastRow )
-    return QVariant( "ERROR" );
-
-  QVariant &val = ( *mLastRow )[ mAttributes[index.column()] ];
-
-  if ( val.isNull() )
-  {
-    // if the value is NULL, show that in table, but don't show "NULL" text in editor
-    if ( role == Qt::EditRole )
-      return QVariant();
-    else
-      return QVariant( "NULL" );
-  }
-
-  // force also numeric data for EditRole to be strings
-  // otherwise it creates spinboxes instead of line edits
-  // (probably not what we do want)
-  if ( fldNumeric && role == Qt::EditRole )
-    return val.toString();
-
-  // convert to QString from some other representation
-  // this prevents displaying greater numbers in exponential format
-  return val.toString();
-}
-
-bool QgsAttributeTableMemoryModel::setData( const QModelIndex &index, const QVariant &value, int role )
-{
-  if ( !index.isValid() || role != Qt::EditRole )
+    QgsDebugMsg( QString( "feature %1 not loaded" ).arg( fid ) );
     return false;
-
-  if ( !mLayer->isEditable() )
-    return false;
-
-  //bool res = mLayer->featureAtId(rowToId(index.row()), mFeat, false, true);
-  bool res = mFeatureMap.contains( rowToId( index.row() ) );
-
-  if ( res )
-  {
-    mLastRowId = rowToId( index.row() );
-    mFeat = mFeatureMap[rowToId( index.row() )];
-    mLastRow = ( QgsAttributeMap * ) & mFeat.attributeMap();
-
-
-// QgsDebugMsg(mFeatureMap[rowToId(index.row())].id());
-    mFeatureMap[rowToId( index.row() )].changeAttribute( mAttributes[ index.column()], value );
-    // propagate back to the layer
-    mLayer->beginEditCommand( tr( "Attribute changed" ) );
-    mLayer->changeAttributeValue( rowToId( index.row() ), mAttributes[ index.column()], value, true );
-    mLayer->endEditCommand();
   }
-
-  if ( !mLayer->isModified() )
-    return false;
-
-  emit dataChanged( index, index );
-  return true;
 }
 
 void QgsAttributeTableMemoryModel::featureDeleted( int fid )
@@ -150,22 +76,6 @@
   QgsAttributeTableModel::featureAdded( fid );
 }
 
-#if 0
-void QgsAttributeTableMemoryModel::attributeAdded( int idx )
-{
-  QgsDebugMsg( "entered." );
-  loadLayer();
-  reload( index( 0, 0 ), index( rowCount(), columnCount() ) );
-}
-
-void QgsAttributeTableMemoryModel::attributeDeleted( int idx )
-{
-  QgsDebugMsg( "entered." );
-  loadLayer();
-  reload( index( 0, 0 ), index( rowCount(), columnCount() ) );
-}
-#endif
-
 void QgsAttributeTableMemoryModel::layerDeleted()
 {
   QgsDebugMsg( "entered." );

Modified: trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h	2009-10-06 21:43:33 UTC (rev 11761)
@@ -57,22 +57,6 @@
 
   private slots:
     /**
-     * Launched when attribute has been added
-     * @param idx attribute index
-     */
-    //virtual void attributeAdded (int idx);
-    /**
-     * Launched when attribute has been deleted
-     * @param idx attribute index
-     */
-    //virtual void attributeDeleted (int idx);
-    /**
-     * Launched when layer has been modified
-     * Rebuilds the model
-     * @param onlyGeometry true if only geometry has changed
-     */
-    //virtual void layerModified(bool onlyGeometry);
-    /**
      * Launched when attribute value has been changed
      * @param fid feature id
      * @param idx attribute index
@@ -82,19 +66,13 @@
 
   private:
     /**
-     * Returns data on the given index
-     * @param index model index
-     * @param role data role
+     * load feature fid into mFeat
+     * @param fid feature id
+     * @return feature exists
      */
-    virtual QVariant data( const QModelIndex &index, int role ) const;
+    virtual bool featureAtId( int fid );
+
     /**
-     * Updates data on given index
-     * @param index model index
-     * @param value new data value
-     * @param role data role
-     */
-    virtual bool setData( const QModelIndex &index, const QVariant &value, int role );
-    /**
      * Loads the layer into the model
      */
     virtual void loadLayer();

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-10-06 21:43:33 UTC (rev 11761)
@@ -68,6 +68,11 @@
   loadLayer();
 }
 
+bool QgsAttributeTableModel::featureAtId( int fid )
+{
+  return mLayer->featureAtId( fid, mFeat, false, true );
+}
+
 void QgsAttributeTableModel::featureDeleted( int fid )
 {
   QgsDebugMsg( "entered." );
@@ -361,6 +366,11 @@
 
 QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const
 {
+  return (( QgsAttributeTableModel * ) this )->data( index, role );
+}
+
+QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role )
+{
   if ( !index.isValid() || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole ) )
     return QVariant();
 
@@ -378,7 +388,7 @@
   // if we don't have the row in current cache, load it from layer first
   if ( mLastRowId != rowToId( index.row() ) )
   {
-    bool res = mLayer->featureAtId( rowToId( index.row() ), mFeat, false, true );
+    bool res = featureAtId( rowToId( index.row() ) );
 
     if ( !res )
       return QVariant( "ERROR" );
@@ -429,12 +439,13 @@
   if ( !mLayer->isEditable() )
     return false;
 
-  bool res = mLayer->featureAtId( rowToId( index.row() ), mFeat, false, true );
+  bool res = featureAtId( rowToId( index.row() ) );
 
   if ( res )
   {
     mLastRowId = rowToId( index.row() );
-    mLastRow = ( QgsAttributeMap * )( &( mFeat.attributeMap() ) );
+    mLastRow = ( QgsAttributeMap * ) & mFeat.attributeMap();
+
     mLayer->beginEditCommand( tr( "Attribute changed" ) );
     mLayer->changeAttributeValue( rowToId( index.row() ), mAttributes[ index.column()], value, true );
     mLayer->endEditCommand();

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2009-10-06 20:53:22 UTC (rev 11760)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2009-10-06 21:43:33 UTC (rev 11761)
@@ -22,9 +22,8 @@
 #include <QObject>
 #include <QHash>
 
-//QGIS Includes
-#include "qgsfeature.h" //QgsAttributeMap
-#include "qgsvectorlayer.h" //QgsAttributeList
+#include "qgsfeature.h" // QgsAttributeMap
+#include "qgsvectorlayer.h" // QgsAttributeList
 #include "qgsattributetableidcolumnpair.h"
 
 class QgsAttributeTableModel: public QAbstractTableModel
@@ -203,6 +202,14 @@
      */
     virtual void loadLayer();
 
+    /**
+     * load feature fid into mFeat
+     * @param fid feature id
+     * @return feature exists
+     */
+    virtual bool featureAtId( int fid );
+
+    QVariant data( const QModelIndex &index, int role );
 };
 
 



More information about the QGIS-commit mailing list