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 Offline
    M Offline
    milan
    wrote on last edited by
    #1

    Hello, I have currently C++ model holding list of names and associated data for those names. The list items can be checked by user. And the checked list items will be displayed in the mainwindow by circular gauge (if possible, ability to change the the view component on run time to another maybe gauge, etc).

    I have confusion on how can I feed the circular gauges with a single C++ model or should I create separate C++ model for separate gauges? Please help

    E 1 Reply Last reply
    0
    • M milan

      Hello, I have currently C++ model holding list of names and associated data for those names. The list items can be checked by user. And the checked list items will be displayed in the mainwindow by circular gauge (if possible, ability to change the the view component on run time to another maybe gauge, etc).

      I have confusion on how can I feed the circular gauges with a single C++ model or should I create separate C++ model for separate gauges? Please help

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

      I have confusion on how can I feed the circular gauges with a single C++ model

      I have got doubts that it can usually make sense to display the same data by more instances of the same view.

      or should I create separate C++ model for separate gauges?

      I would find it more useful to show different input data on similar output views.
      How do you think about to indicate the desired connections by labels or specific colours?

      M 1 Reply Last reply
      0
      • E elfring

        I have confusion on how can I feed the circular gauges with a single C++ model

        I have got doubts that it can usually make sense to display the same data by more instances of the same view.

        or should I create separate C++ model for separate gauges?

        I would find it more useful to show different input data on similar output views.
        How do you think about to indicate the desired connections by labels or specific colours?

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

        @elfring. What i meant to say is each gauge will have different data, because it is fed by different data in the list. Of course, I do know that same model can be used in multiple views. I do not know understand what you try to explain "How do you think about to indicate the desired connections by labels or specific colours?".

        E VRoninV 2 Replies Last reply
        0
        • M milan

          @elfring. What i meant to say is each gauge will have different data, because it is fed by different data in the list. Of course, I do know that same model can be used in multiple views. I do not know understand what you try to explain "How do you think about to indicate the desired connections by labels or specific colours?".

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

          I do not know understand what you try to explain "How do you think about to indicate the desired connections by labels or specific colours?".

          • You can display data also in a redundant way (if it is really desired).
          • How do you distinguish if the used views should present different data from separate input sources?
          M 1 Reply Last reply
          0
          • E elfring

            I do not know understand what you try to explain "How do you think about to indicate the desired connections by labels or specific colours?".

            • You can display data also in a redundant way (if it is really desired).
            • How do you distinguish if the used views should present different data from separate input sources?
            M Offline
            M Offline
            milan
            wrote on last edited by
            #5

            @elfring. Yes I have these problems. I do not also know which data structure could be suitable for this.
            I am thinking of QList<QVariant>. The QList item of QVariant will again hold QList of QVariants. I do not know if this is appropriate solution.

            E 1 Reply Last reply
            0
            • M milan

              @elfring. What i meant to say is each gauge will have different data, because it is fed by different data in the list. Of course, I do know that same model can be used in multiple views. I do not know understand what you try to explain "How do you think about to indicate the desired connections by labels or specific colours?".

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

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

              What i meant to say is each gauge will have different data, because it is fed by different data in the list.

              So basically each element in the list should be represented by a circular gauge. I that correct? if so, how are the gauges arranged on the view (one under the other, in a grid, etc.)

              "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
              • VRoninV VRonin

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

                What i meant to say is each gauge will have different data, because it is fed by different data in the list.

                So basically each element in the list should be represented by a circular gauge. I that correct? if so, how are the gauges arranged on the view (one under the other, in a grid, etc.)

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

                @VRonin . Yes, for testing, I am using horizontal layout now. Grid layout can be good option.

                1 Reply Last reply
                0
                • M milan

                  @elfring. Yes I have these problems. I do not also know which data structure could be suitable for this.
                  I am thinking of QList<QVariant>. The QList item of QVariant will again hold QList of QVariants. I do not know if this is appropriate solution.

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

                  I am thinking of QList<QVariant>.

                  Are you using customised data models for your software application already?

                  I do not know if this is appropriate solution.

                  Which objects will you pass to the member function “setModel” of your views?

                  M 1 Reply Last reply
                  0
                  • E elfring

                    I am thinking of QList<QVariant>.

                    Are you using customised data models for your software application already?

                    I do not know if this is appropriate solution.

                    Which objects will you pass to the member function “setModel” of your views?

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

                    @elfring. Yes, I am using QAbstractListModel now. But I do not know if QAbstractItemModel or QAbstractTableModel would be better choice?

                    I am not yet able to have working application yet. I think I need to pass Qvariantlist for each gauge because gauge will have name, value and unit. And all those parameters will come from the model.

                    E 1 Reply Last reply
                    0
                    • M milan

                      @elfring. Yes, I am using QAbstractListModel now. But I do not know if QAbstractItemModel or QAbstractTableModel would be better choice?

                      I am not yet able to have working application yet. I think I need to pass Qvariantlist for each gauge because gauge will have name, value and unit. And all those parameters will come from the model.

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

                      I am using QAbstractListModel now.

                      Would you like to fiddle with any “tables” after the current list approach?

                      M 1 Reply Last reply
                      0
                      • E elfring

                        I am using QAbstractListModel now.

                        Would you like to fiddle with any “tables” after the current list approach?

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

                        @elfring. I got confused now with list based approach or table based approach as gauge should have few parameters coming from model namely, name, unit, and value.

                        E 1 Reply Last reply
                        0
                        • M milan

                          @elfring. I got confused now with list based approach or table based approach as gauge should have few parameters coming from model namely, name, unit, and value.

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

                          few parameters coming from model namely, name, unit, and value.

                          Did you put these items into a specific class together?

                          M 1 Reply Last reply
                          0
                          • VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by
                            #13

                            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

                            "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

                              few parameters coming from model namely, name, unit, and value.

                              Did you put these items into a specific class together?

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

                              @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 1 Reply Last reply
                              0
                              • 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

                                          • Login

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