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. Design problem between choice of single or multiple C++ models
Forum Updated to NodeBB v4.3 + New Features

Design problem between choice of single or multiple C++ models

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 4 Posters 4.5k 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.
  • M milan

    @elfring . No, not yet. I thought of QList<QVariantList>. The QVariantList would contain QVariants of QString(Name), QString(Unit), double/int (Value). Just an idea now.

    E Offline
    E Offline
    elfring
    wrote on last edited by
    #15

    Just an idea now.

    I suggest to reconsider the data structure design. The software dependencies might become clearer also for your use case.

    M 1 Reply Last reply
    0
    • VRoninV VRonin

      Ok, let's split the problem in the 3 components:

      The model

      You can subclass QAbstractListModel and build your own but I suggest to use QStandardItemModel through the QAbstractItemModel interface only (the easier way is to have something like QAbstractItemModel* model = new QStandardItemModel.
      Now you can use insertRows/insertColumns to add gauges and setData to store in different roles all the data you need for the gauge (e.g. min, max, current value, tick distance, colour, etc.)

      The delegate

      This is a QStyledItemDelegate subclass that will take care of painting a single gauge. The method you want to reimplement is QStyledItemDelegate::paint. From there you can use index.data(role) to retrieve the data stored in the various roles of the model before

      The View

      This decides how the gauges are laid out you can use QListView/QTableView in the beginning and then subclass your own of you feel the need


      An Alternative

      Instead of the delegate+view approach you can use QDataWidgetMapper http://doc.qt.io/qt-5/qdatawidgetmapper.html to map data in a model directly in a widget. This is not the most efficient solution however as it duplicates the data and it's really designed to show a specific item (or a subset of items) from the model

      M Offline
      M Offline
      milan
      wrote on last edited by
      #16

      @VRonin. In C++, we are not sure how many gauges will be in the window. The gauges will be added depending upon the parameters chosen by user in the UI. For example, if the user choses 5 parameters, there will be 5 gauges.

      VRoninV 1 Reply Last reply
      0
      • M milan

        @VRonin. In C++, we are not sure how many gauges will be in the window. The gauges will be added depending upon the parameters chosen by user in the UI. For example, if the user choses 5 parameters, there will be 5 gauges.

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #17

        @milan said in Design problem between choice of single or multiple C++ models:

        For example, if the user choses 5 parameters, there will be 5 gauges.

        You are free to call insertRow or removeRow on the model at runtime to change the number of gauges

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        M 1 Reply Last reply
        1
        • E elfring

          Just an idea now.

          I suggest to reconsider the data structure design. The software dependencies might become clearer also for your use case.

          M Offline
          M Offline
          milan
          wrote on last edited by
          #18

          @elfring . Yes, I may need to rethink the datastructure. But it is the best I can think of right now.

          E 1 Reply Last reply
          0
          • VRoninV VRonin

            @milan said in Design problem between choice of single or multiple C++ models:

            For example, if the user choses 5 parameters, there will be 5 gauges.

            You are free to call insertRow or removeRow on the model at runtime to change the number of gauges

            M Offline
            M Offline
            milan
            wrote on last edited by
            #19

            @VRonin. Okay, I can also give your idea a try. But what about the gauge parameters like Name, value, unit that is coming from the model. I also forget to add that gauge is Circular gauge from QtQuick2 extras used as quickwidget in QtWidget application.

            VRoninV 1 Reply Last reply
            0
            • M milan

              @elfring . Yes, I may need to rethink the datastructure. But it is the best I can think of right now.

              E Offline
              E Offline
              elfring
              wrote on last edited by
              #20

              But it is the best I can think of right now.

              Would you like to combine any more elements into specific classes?

              M 1 Reply Last reply
              0
              • E elfring

                But it is the best I can think of right now.

                Would you like to combine any more elements into specific classes?

                M Offline
                M Offline
                milan
                wrote on last edited by
                #21

                @elfring . No, each gauge would only have specific name, its unit and value. And the value would be updating each second.

                E 1 Reply Last reply
                0
                • M milan

                  @VRonin. Okay, I can also give your idea a try. But what about the gauge parameters like Name, value, unit that is coming from the model. I also forget to add that gauge is Circular gauge from QtQuick2 extras used as quickwidget in QtWidget application.

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #22

                  @milan said in Design problem between choice of single or multiple C++ models:

                  But what about the gauge parameters like Name, value, unit that is coming from the model

                  @VRonin said in Design problem between choice of single or multiple C++ models:

                  setData to store in different roles all the data you need for the gauge (e.g. min, max, current value, tick distance, colour, etc.)

                  @VRonin said in Design problem between choice of single or multiple C++ models:

                  The method you want to reimplement is QStyledItemDelegate::paint. From there you can use index.data(role) to retrieve the data stored in the various roles of the model before


                  @milan said in Design problem between choice of single or multiple C++ models:

                  I also forget to add that gauge is Circular gauge from QtQuick2 extras used as quickwidget in QtWidget application

                  Ok, so performance is already out of the window, so you can use this template delegate to make the delegate part a lot easier. You just need to reimplement setSubEditorData to pass the relevant parameters to the widget

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  M 1 Reply Last reply
                  0
                  • M milan

                    @elfring . No, each gauge would only have specific name, its unit and value. And the value would be updating each second.

                    E Offline
                    E Offline
                    elfring
                    wrote on last edited by
                    #23

                    @milan said in Design problem between choice of single or multiple C++ models:

                    No, each gauge …

                    It seems then that you are using a widget with well-known properties.
                    Will you eventually pass the name to a label?

                    M 1 Reply Last reply
                    0
                    • E elfring

                      @milan said in Design problem between choice of single or multiple C++ models:

                      No, each gauge …

                      It seems then that you are using a widget with well-known properties.
                      Will you eventually pass the name to a label?

                      M Offline
                      M Offline
                      milan
                      wrote on last edited by
                      #24

                      @elfring. Yes, each gauge has to be identified. So the label text will be updated by the model.

                      1 Reply Last reply
                      0
                      • VRoninV VRonin

                        @milan said in Design problem between choice of single or multiple C++ models:

                        But what about the gauge parameters like Name, value, unit that is coming from the model

                        @VRonin said in Design problem between choice of single or multiple C++ models:

                        setData to store in different roles all the data you need for the gauge (e.g. min, max, current value, tick distance, colour, etc.)

                        @VRonin said in Design problem between choice of single or multiple C++ models:

                        The method you want to reimplement is QStyledItemDelegate::paint. From there you can use index.data(role) to retrieve the data stored in the various roles of the model before


                        @milan said in Design problem between choice of single or multiple C++ models:

                        I also forget to add that gauge is Circular gauge from QtQuick2 extras used as quickwidget in QtWidget application

                        Ok, so performance is already out of the window, so you can use this template delegate to make the delegate part a lot easier. You just need to reimplement setSubEditorData to pass the relevant parameters to the widget

                        M Offline
                        M Offline
                        milan
                        wrote on last edited by
                        #25

                        @VRonin . Could you please explain why the performance will be problem. What could cause that.

                        kshegunovK VRoninV 2 Replies Last reply
                        0
                        • M milan

                          @VRonin . Could you please explain why the performance will be problem. What could cause that.

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

                          @milan said in Design problem between choice of single or multiple C++ models:

                          Could you please explain why the performance will be problem. What could cause that.

                          It's due to the way widgets are painter. Whatever the reason though you should ignore the performance issue, as it's (highly) unlikely you'd have tens of gauges, much less thousands of them.

                          Read and abide by the Qt Code of Conduct

                          M 1 Reply Last reply
                          1
                          • M milan

                            @VRonin . Could you please explain why the performance will be problem. What could cause that.

                            VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by
                            #27

                            @milan said in Design problem between choice of single or multiple C++ models:

                            Could you please explain why the performance will be problem

                            I'm not saying it will be a problem but it's certainly not optimised. You are mixing 2 UI frameworks one painted inside the other so it's only natural it won't be as performing as manual painting on a QStyledItemDelegate subclass

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            M 1 Reply Last reply
                            0
                            • kshegunovK kshegunov

                              @milan said in Design problem between choice of single or multiple C++ models:

                              Could you please explain why the performance will be problem. What could cause that.

                              It's due to the way widgets are painter. Whatever the reason though you should ignore the performance issue, as it's (highly) unlikely you'd have tens of gauges, much less thousands of them.

                              M Offline
                              M Offline
                              milan
                              wrote on last edited by
                              #28

                              @kshegunov . There will be around 10-20 gauges i think in a tab, another tab will use same model's data and name to display in Qt Charts.

                              1 Reply Last reply
                              0
                              • VRoninV VRonin

                                @milan said in Design problem between choice of single or multiple C++ models:

                                Could you please explain why the performance will be problem

                                I'm not saying it will be a problem but it's certainly not optimised. You are mixing 2 UI frameworks one painted inside the other so it's only natural it won't be as performing as manual painting on a QStyledItemDelegate subclass

                                M Offline
                                M Offline
                                milan
                                wrote on last edited by
                                #29

                                @VRonin. I did not like to use two UI frameworks, but I did not find nice gauge in Qt Widgets. But using QML for a desktop application, I find it not easy.

                                VRoninV 1 Reply Last reply
                                0
                                • M milan

                                  @VRonin. I did not like to use two UI frameworks, but I did not find nice gauge in Qt Widgets. But using QML for a desktop application, I find it not easy.

                                  VRoninV Offline
                                  VRoninV Offline
                                  VRonin
                                  wrote on last edited by
                                  #30

                                  @milan said in Design problem between choice of single or multiple C++ models:

                                  but I did not find nice gauge in Qt Widgets

                                  At the end of the day it's an arch, 2 triangles, some tick lines and some text. It's not hard to paint manually and a "gauge" allows so much personalisation that it's hard to ship a generic pre-made widget that satisfies everyone

                                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                  ~Napoleon Bonaparte

                                  On a crusade to banish setIndexWidget() from the holy land of Qt

                                  1 Reply Last reply
                                  1

                                  • Login

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