Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal flag changes for QAbstractItemModel
Forum Updated to NodeBB v4.3 + New Features

Signal flag changes for QAbstractItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
itemmodel
18 Posts 4 Posters 4.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS SGaist

    Hi,

    AFAIK, the flags are check "on use" so if you double click on an item which you just changed flags for not editable it should already take it into account.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #5

    @SGaist
    I come from looking at topic https://forum.qt.io/topic/144826/problem-using-an-integer-in-a-const-function-after-changing-its-value.

    I think your answer was "not good enough" :) , and @kshegunov's question is a good one. Let's say you do not "click an item", which doubtless would have caused that item to be re-evaluated/redrawn, but instead happen to do something in code which will cause flags() on some item to now return a different value. What is going to cause that item/flags to be re-evaluated? Nothing, I think.

    Since there is no "flags changed" signal I can only guess you would have to use dataChanged(), perhaps for DisplayRole or all roles, just to get e.g. a table view to update from the model's new flags.

    SGaistS 1 Reply Last reply
    0
    • JonBJ JonB

      @SGaist
      I come from looking at topic https://forum.qt.io/topic/144826/problem-using-an-integer-in-a-const-function-after-changing-its-value.

      I think your answer was "not good enough" :) , and @kshegunov's question is a good one. Let's say you do not "click an item", which doubtless would have caused that item to be re-evaluated/redrawn, but instead happen to do something in code which will cause flags() on some item to now return a different value. What is going to cause that item/flags to be re-evaluated? Nothing, I think.

      Since there is no "flags changed" signal I can only guess you would have to use dataChanged(), perhaps for DisplayRole or all roles, just to get e.g. a table view to update from the model's new flags.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @JonB indeed, there's nothing to notify that specific change.
      I am wondering whether dataChanged conveys that idea at all since it's there was in fact nothing changed data wise.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      0
      • SGaistS SGaist

        @JonB indeed, there's nothing to notify that specific change.
        I am wondering whether dataChanged conveys that idea at all since it's there was in fact nothing changed data wise.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #7

        @SGaist
        dataChanged() does not really convey that. But as @kshegunov said there isn't a role for "flags". I imagine DisplayRole will have the desired effect of forcing it to re-evaluate the flag()s and see e.g. item enablement change, so you would get the desired behaviour for the wrong reason.

        SGaistS 1 Reply Last reply
        0
        • JonBJ JonB

          @SGaist
          dataChanged() does not really convey that. But as @kshegunov said there isn't a role for "flags". I imagine DisplayRole will have the desired effect of forcing it to re-evaluate the flag()s and see e.g. item enablement change, so you would get the desired behaviour for the wrong reason.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @JonB maybe coupled with EditRole since the flag change might also influence that part.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          JonBJ 1 Reply Last reply
          0
          • SGaistS SGaist

            @JonB maybe coupled with EditRole since the flag change might also influence that part.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #9

            @SGaist Do a dataChanged() for "all roles" and then you have done the best you can :)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #10

              I am sure there are some corner cases that will be fun

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #11

                Well, I'd long forgotten about this topic, but I would think we actually need a flagsChanged(QModelIndex, QModelIndex) signal, which would be "the right way"™. I didn't open a feature request at the time, but maybe one of you might feel strongly enough about it to do so.

                Read and abide by the Qt Code of Conduct

                JonBJ 1 Reply Last reply
                1
                • kshegunovK kshegunov

                  Well, I'd long forgotten about this topic, but I would think we actually need a flagsChanged(QModelIndex, QModelIndex) signal, which would be "the right way"™. I didn't open a feature request at the time, but maybe one of you might feel strongly enough about it to do so.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #12

                  @kshegunov
                  It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response? And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

                  kshegunovK 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @kshegunov
                    It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response? And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #13

                    @JonB said in Signal flag changes for QAbstractItemModel:

                    It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response?

                    It should be painless in the sense that it's a new signal, so nobody needs to actually do anything to keep old code working.

                    And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

                    Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

                    Read and abide by the Qt Code of Conduct

                    JonBJ 1 Reply Last reply
                    0
                    • kshegunovK kshegunov

                      @JonB said in Signal flag changes for QAbstractItemModel:

                      It would indeed! But then the issue is: who wants to go through all the code finding every occurrence where flags() has changed to decide what needs to be done in response?

                      It should be painless in the sense that it's a new signal, so nobody needs to actually do anything to keep old code working.

                      And in practice would it be any more or less than dataChanged(index, index, {}) does? :)

                      Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #14

                      @kshegunov said in Signal flag changes for QAbstractItemModel:

                      Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

                      Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                      kshegunovK 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @kshegunov said in Signal flag changes for QAbstractItemModel:

                        Possibly, as you don't go around querying the data from the model, albeit I'm not sure if that's really relevant, as in the end you may need to.

                        Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #15

                        @JonB said in Signal flag changes for QAbstractItemModel:

                        Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                        It may, which was my original argument - it (the signal) could simply do nothing significant in the end.

                        Read and abide by the Qt Code of Conduct

                        SGaistS 1 Reply Last reply
                        0
                        • kshegunovK kshegunov

                          @JonB said in Signal flag changes for QAbstractItemModel:

                          Because of, say, Qt::ItemIsEnabled flag, which shows item differently, won't it end up having to access item's DisplayRole which has to query the model to get the text again to show it dimmed?

                          It may, which was my original argument - it (the signal) could simply do nothing significant in the end.

                          SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #16

                          I wonder how often this use case happens.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          kshegunovK 1 Reply Last reply
                          1
                          • SGaistS SGaist

                            I wonder how often this use case happens.

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #17

                            @SGaist said in Signal flag changes for QAbstractItemModel:

                            I wonder how often this use case happens.

                            I'd imagine for any nontrivial use of the item model, this will happen. In the case of widgets it probably won't matter anyway, as you'd want to immediately redraw whatever it is you're showing; but with Qt quick it may actually be a malice on performance, since it would invalidate the scene graph node (which may or may not be a problem, I haven't actually looked at the implementation).

                            Read and abide by the Qt Code of Conduct

                            JonBJ 1 Reply Last reply
                            0
                            • kshegunovK kshegunov

                              @SGaist said in Signal flag changes for QAbstractItemModel:

                              I wonder how often this use case happens.

                              I'd imagine for any nontrivial use of the item model, this will happen. In the case of widgets it probably won't matter anyway, as you'd want to immediately redraw whatever it is you're showing; but with Qt quick it may actually be a malice on performance, since it would invalidate the scene graph node (which may or may not be a problem, I haven't actually looked at the implementation).

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #18

                              @kshegunov
                              One might actually need the signal to tell us which flags have changed. Only certain flag changes affect anything we are interested in, several seem not relevant.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved