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. Model/View programming conventions
Forum Updated to NodeBB v4.3 + New Features

Model/View programming conventions

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.8k 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.
  • VolebabV Offline
    VolebabV Offline
    Volebab
    wrote on last edited by Volebab
    #1

    I'm translating the tutorial about model/view programming to my language in order to understand better, the thing is that in the tutorial I found a few name conventions that I'm not acquainted with.
    For example: "item model classes", "item data" and "item views".
    This conventions are used everywhere in the tutorial but I can't find their definition. "item views" is it the same as saying "view's item", like meaning it's a item within a view? I really don't get it.

    JKSHJ 1 Reply Last reply
    0
    • VolebabV Volebab

      I'm translating the tutorial about model/view programming to my language in order to understand better, the thing is that in the tutorial I found a few name conventions that I'm not acquainted with.
      For example: "item model classes", "item data" and "item views".
      This conventions are used everywhere in the tutorial but I can't find their definition. "item views" is it the same as saying "view's item", like meaning it's a item within a view? I really don't get it.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi @Volebab,

      You can think of Qt's models as lists (1D arrays), tables (2D arrays), or trees (nested arrays-inside-arrays).

      An "Item" is an element of a list, table, or tree. For example, if your model represents a table with 3 rows and 4 columns, that means your table model contains 12 items.

      • "Item model class" == Any class that inherits from QAbstractItemModel, directly or indirectly. (For example, QAbstractTableModel)
      • "Item data" == The data inside an item. (For example, a number or a string)
      • "Item view" == A view that displays a model's "item data". (For example, QTableView)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      VolebabV 1 Reply Last reply
      2
      • JKSHJ JKSH

        Hi @Volebab,

        You can think of Qt's models as lists (1D arrays), tables (2D arrays), or trees (nested arrays-inside-arrays).

        An "Item" is an element of a list, table, or tree. For example, if your model represents a table with 3 rows and 4 columns, that means your table model contains 12 items.

        • "Item model class" == Any class that inherits from QAbstractItemModel, directly or indirectly. (For example, QAbstractTableModel)
        • "Item data" == The data inside an item. (For example, a number or a string)
        • "Item view" == A view that displays a model's "item data". (For example, QTableView)
        VolebabV Offline
        VolebabV Offline
        Volebab
        wrote on last edited by Volebab
        #3

        @JKSH - I understand most of what you explained, the only thing is:

        "Item model class" == Any class that inherits from QAbstractItemModel, directly or indirectly. (For example, QAbstractTableModel)

        Kinda confusing. An item is an element of a model, like a list, table or three, and it has data - "item data" - and can be displayed using, for example, with QTableView, then why "item model class" is classes that inherits from QAbstractItemModel? I mean, "item model" isn't an item inside a model? Why QAbstractTableModel inherits from it?
        When we say that it's inherits something is the same as saying that it's the same, so QAbstractTableModel is an QAbstractItemModel? - What is an "item model"? *mind blown*

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          QAbstractItemView and QAbstractItemModel work in pair.

          If you use Qt based model view approach, any view will be derived from QAbstractItemView , any model will be derived from QAbstractItemModel .
          All QAbstractItemModel defines is API QAbstractItemView will use to communicate with its model.
          Why QAbstractItemModel and not QqAbsrtactViewModel? Probably better name was not found.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @Volebab said:

            I mean, "item model" isn't an item inside a model? Why QAbstractTableModel inherits from it?

            No, "item model" is not an item inside a model.

            • "Item model" == A model that contains items.
            • "Item model class" == A C++ class that implements an item model.

            An item is an element of a model, like a list, table or three, and it has data - "item data" - and can be displayed using, for example, with QTableView

            Yes, this is correct. :)

            why "item model class" is classes that inherits from QAbstractItemModel?
            ...
            When we say that it's inherits something is the same as saying that it's the same, so QAbstractTableModel is an QAbstractItemModel? - What is an "item model"? *mind blown*

            Are you familiar with object-oriented programming and inheritance? These are important concepts in C++. You should learn them before you translate a C++ tutorial.

            I guess I should also rewrite my explanation:

            • "Item model class" == QAbstractItemModel, or any other class that inherits from it (directly or indirectly)

            Here are some abstract examples of model inheritance:

            • QAbstractItemModel represents a tree.
            • QAbstractTableModel inherits QAbstractItemModel, and it represents a table. It removes the ability to have nested data.
            • QAbstractListModel inherits QAbstractItemModel, and it represents a list. It removes the ability to have multiple columns.

            Here are some concrete examples of model inheritance:

            • QFileSystemModel inherits QAbstractItemModel, and it represents a folder hierarchy in your computer. Each item represents a file or folder.
            • QSqlQueryModel inherits QAbstractTableModel, and it represents the result of an SQL query. Each item is an element from an SQL SELECT query.
            • QStringListModel inherits QAbstractListModel, and it represents a list of strings. Each item is a string.

            All of these classes are item models.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            VolebabV 1 Reply Last reply
            1
            • JKSHJ JKSH

              @Volebab said:

              I mean, "item model" isn't an item inside a model? Why QAbstractTableModel inherits from it?

              No, "item model" is not an item inside a model.

              • "Item model" == A model that contains items.
              • "Item model class" == A C++ class that implements an item model.

              An item is an element of a model, like a list, table or three, and it has data - "item data" - and can be displayed using, for example, with QTableView

              Yes, this is correct. :)

              why "item model class" is classes that inherits from QAbstractItemModel?
              ...
              When we say that it's inherits something is the same as saying that it's the same, so QAbstractTableModel is an QAbstractItemModel? - What is an "item model"? *mind blown*

              Are you familiar with object-oriented programming and inheritance? These are important concepts in C++. You should learn them before you translate a C++ tutorial.

              I guess I should also rewrite my explanation:

              • "Item model class" == QAbstractItemModel, or any other class that inherits from it (directly or indirectly)

              Here are some abstract examples of model inheritance:

              • QAbstractItemModel represents a tree.
              • QAbstractTableModel inherits QAbstractItemModel, and it represents a table. It removes the ability to have nested data.
              • QAbstractListModel inherits QAbstractItemModel, and it represents a list. It removes the ability to have multiple columns.

              Here are some concrete examples of model inheritance:

              • QFileSystemModel inherits QAbstractItemModel, and it represents a folder hierarchy in your computer. Each item represents a file or folder.
              • QSqlQueryModel inherits QAbstractTableModel, and it represents the result of an SQL query. Each item is an element from an SQL SELECT query.
              • QStringListModel inherits QAbstractListModel, and it represents a list of strings. Each item is a string.

              All of these classes are item models.

              VolebabV Offline
              VolebabV Offline
              Volebab
              wrote on last edited by
              #6

              @JKSH - Thank you, helped a lot.

              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