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. Transforming and filtering a model

Transforming and filtering a model

Scheduled Pinned Locked Moved Solved General and Desktop
model-view
6 Posts 2 Posters 2.0k Views
  • 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.
  • KlimichKartorGnusovK Offline
    KlimichKartorGnusovK Offline
    KlimichKartorGnusov
    wrote on last edited by KlimichKartorGnusov
    #1

    Hello!
    I have a table model with the following structure:

    • first name
    • second name
    • location
    • street
    • telephone.

    Necessary represent this structure differently. Need combine first name, second name to the full name and also, location, street to the full address, but need save the source structure model for filtering by each column.

    I went to the following path and did:

    • Source model (inherits from QAbstractTableModel)
    • Filter model (inherits from QSortFilterProxyModel)
    • Converter model (inherits from QIdentyProxyModel)

    It turns out that the converter model refers to the filter model, filter model refers to the source model.
    To set up model need make: tableView->setModel(converterModel)...
    After that, all works, but it seems to me that the decision is not correct.
    Help advice. Is there a better way?

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

      Hi and welcome to devnet,

      Taking from what your wrote, from top to bottom:

      1. QTableView
      2. Converter Model
      3. Filter Model
      4. Source Model

      That's the correct way.

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

      KlimichKartorGnusovK 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Taking from what your wrote, from top to bottom:

        1. QTableView
        2. Converter Model
        3. Filter Model
        4. Source Model

        That's the correct way.

        KlimichKartorGnusovK Offline
        KlimichKartorGnusovK Offline
        KlimichKartorGnusov
        wrote on last edited by KlimichKartorGnusov
        #3

        @SGaist Hi! Thank you! I've got one more question...
        There is universal method to get source index via converter Model?

        At the moment I'm doing:

        • Get a index of filter model via a converter model
        QModelIndex filterIndex = converterModel_->mapToSource(converterIndex);
        
        • Get source index through the index of filter model
        QModelIndex sourceIndex = filterModel_->mapToSource(filterIndex);
        

        This method is not universal and designed for current situation.

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

          What is your use case for that ?

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

          KlimichKartorGnusovK 1 Reply Last reply
          1
          • SGaistS SGaist

            What is your use case for that ?

            KlimichKartorGnusovK Offline
            KlimichKartorGnusovK Offline
            KlimichKartorGnusov
            wrote on last edited by
            #5

            @SGaist 3 models that described above are a set of my custom view. It may contain 2 models(source+filter) or 3 models(source+filter+converter). I'm want make an abstract interface for it. For example i'm want a shared slot double click in table. Need universal method to get source index via the converter model or the filter model. At the moment, i'm checking pointers to models and depending situation, I'm making a necessary actions.

            void AbstractTableView::doubleClick(const QModelIndex &index) 
            {
            	int row;
            	QModelIndex filterIndex;
            	QModelIndex sourceIndex;
            	
            	//if a converterModel and filterModel was set
            	if(converterModel_) {
            		filterIndex = converterModel_->mapToSource(index);
            		sourceIndex = filterModel_->mapToSource(filterIndex);
            	//if only filterModel was set
            	} else {
            		sourceIndex = filterModel_->mapToSource(index);
            	}
            	
            	//to make something with the resulting row
            	row = sourceIndex.row();
            	editorWidget->editing(row, domainModel_->object(row));
            }
            

            I would like to know whether it is possible to do otherwise?

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

              You don't need all of this. Just use the top-most index. Modifying its content will propagate it back to the bottom index.

              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
              1

              • Login

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