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

QDataWidgetMapper ImmediateSubmit policy

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.10.1
    • Widgets: Itemviews
    • None

    Description

      It would be nice if QDataWidgetMapper had an ImmediateSubmit mode that would submit its data as soon as a widgets value changes. This would be extremely easy to add to the existing QDataWidgetMapper and allow the view and the model to be constantly in-sync with each other.

      This can be implemented simply by using the mappedPropertyName of QDataWidgetMapper and using the widget's metaObject to get the notifySignalIndex to know when the property changes. As I've done here:

      void ImmediateDataWidgetMapper::addMapping(QWidget *widget, int section, QByteArray propertyName) {
        // since QDataWidgetMapper makes its widget map private we have no way of
        // getting all of the widgets registered with this mapper
        // we also do not want to hook up a widget that's already mapped
        if (widgetList.contains(widget)) return;
        widgetList.append(widget);
        QDataWidgetMapper::addMapping(widget, section, propertyName);
        // we use the QDataWidgetMapper to tell us what property we should listen to for changes
        // all widgets have several properties, but most have a "primary" property with which
        // the user interacts, i.e. "checked" for QCheckBox
        propertyName = this->mappedPropertyName(widget);
        // we use the widget's meta object in order to get us a signal that we can listen to
        // so we know when this property changes
        auto widgetMetaObject = widget->metaObject();
        auto property = widgetMetaObject->property(widgetMetaObject->indexOfProperty(propertyName));
        auto metaObject = this->metaObject();
        QMetaObject::connect(widget, property.notifySignalIndex(), this, metaObject->indexOfSlot("widgetChanged()"));
      }
      

       
      I think this would clear up a lot of general confusion on the internet:

      https://stackoverflow.com/questions/5077513/qdatawidgetmapper-autosubmit-doesnt-work
      https://stackoverflow.com/questions/40532050/how-to-update-qdatawidgetmapper-items-without-focus
      https://stackoverflow.com/questions/16084658/qdatawidgetmapper-only-updates-first-index-to-qsqlrelationaltablemodel
      https://stackoverflow.com/questions/7651516/accept-edited-wigets-with-qdatawidgetmapper
      http://lists.qt-project.org/pipermail/interest/2012-June/002760.html

      Attachments

        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
            RobertBColton Robert B. Colton
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes