Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8409

QDataWidgetMapper ignores the flags of a QAbstractTableModel

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • Some future release
    • 4.6.1, 5.0.0, 5.3.0
    • Widgets: Itemviews
    • None
    • Mac Os X, Linux
    • macOS

    Description

      I have derived my own model from QAbstractTableModel, including the implementation of Qt::ItemFlags flags ( const QModelIndex & index ).

      When I display the model using a QTableView, the columns handle the flags appropriate.

      If I use a QDataWidgetMapper instead, the flags are ignored.

      class myModel : public QAbstractTableModel
      {
          Q_OBJECT
      
      public:
          myModel();
          int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
          int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
          QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
          bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
          QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
          Qt::ItemFlags flags ( const QModelIndex & index ) const;
      protected:
          QList<QString> c1;
          QList<QString> c2;
      };
      
      int myModel::rowCount ( const QModelIndex & parent ) const
      {
          return c1.count();
      }
      
      
      
      int myModel::columnCount ( const QModelIndex & parent ) const
      {
          return 2;
      }
      
      
      
      QVariant myModel::data ( const QModelIndex & index, int role ) const
      {
          if ( (role != Qt::DisplayRole) && (role != Qt::EditRole) )
              return QVariant();
          return (index.column() == 0) ? QVariant(c1.at(index.row())) : QVariant(c2.at(index.row()));
      }
      
      
      
      bool myModel::setData ( const QModelIndex & index, const QVariant & value, int role )
      {
          if (index.column() == 0)
              c1[index.row()]= value.toString();
          else
              c2[index.row()]= value.toString();
          emit dataChanged( this->index(0,0), this->index(c1.count(),1));
          return true;
      }
      
      QVariant myModel::headerData ( int section, Qt::Orientation orientation, int role ) const
      {
          return QVariant(QString(""));
      }
      
      Qt::ItemFlags myModel::flags( const QModelIndex & index ) const
      {
          return Qt::ItemIsSelectable;
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              marc Marc
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes