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. [SOLVED] QTableView reset View
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTableView reset View

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 7.1k Views 1 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.
  • T Offline
    T Offline
    Tecnova
    wrote on 25 Nov 2013, 14:43 last edited by
    #1

    Hi,
    I read in some data from some log-files and save them in a QAbstractTableModel.
    I have put a QSortFilterProxyModel between the model and the QTableView.

    My Question now is that when I set the filter options for the proxy-model and want to show the new view with the filter. What is than the best way to reset the filter?

    currently I use the reset() function from the QTableView.

    And when I try to look if the row is hidden with isRowHidden() it always returns false, but the rows are not shown in the view.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 25 Nov 2013, 14:54 last edited by
      #2

      If possible, use
      @
      void QAbstractItemModel::beginResetModel () [protected]
      @
      in your model. This will safely signal all connected View to "reload" data from the model. Because the models are loaded, they will be re read!
      Do not use reset() directly, it is a possible cause for undefined behavior!
      Read docs of QAbstractItemModel!

      Greetz, Jeroen

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 25 Nov 2013, 15:00 last edited by
        #3

        [quote author="Tecnova" date="1385390599"]
        My Question now is that when I set the filter options for the proxy-model and want to show the new view with the filter. What is than the best way to reset the filter?
        [/quote]
        I assume you use QSortFilterProxyModel?
        If so just use one of these methods:
        @
        void setFilterRegExp(const QString &pattern);
        void setFilterWildcard(const QString &pattern);
        void setFilterFixedString(const QString &pattern);
        void invalidate();
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tecnova
          wrote on 26 Nov 2013, 07:36 last edited by
          #4

          thx for the fast reply.

          yes I'm using a QSortFilterProxyModel.

          When I use invalidate() the view gets updated.
          But I still get false from
          @bool QTableView::isRowHidden(int row) const@

          I do that because, I only show 500 rows in one view and when I use a filter on that view sometimes only 10 or less rows are shown. Now I want to get so much new shown rows until I have 500 rows in the current view

          @
          MyTableView widget = (MyTableView) ui->tabWidget->widget(ui->tabWidget->currentIndex()); //get the Table from the current tab

          Filter *filter = filtervec.at(ui->tabWidget->currentIndex()); // get the QSortFilterProxyModel from the current tab

          filter->invalidate(); //reset the view

          for(int r = filter->getMinrow(); r < filter->getMaxrow(); r++)
          {
          qDebug() << "row :" << r << " is " << widget->isRowHidden(r) << "\n";
          if(!widget->isRowHidden(r)) //when row is not hidden inc rowCounter
          this->rowCounter++;
          }
          if(this->rowCounter < 500) //when less than 500 rows are shown
          {
          //update the shown row range by +500
          if(filter->getMaxrow() >= filter->sourceModel()->rowCount())
          return;
          else filter->setMaxrow(filter->getMaxrow()+500);
          showFilter(); //update view again
          }@

          1 Reply Last reply
          0
          • R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 26 Nov 2013, 07:46 last edited by
            #5

            isRowHidden() just checks if you have set the row hidden in the vertical headerview. This requires to call setRowHidden() first.
            In your filter method just filter accept the filtered rows until you have reached the max row count instead the way you are currently doing it.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tecnova
              wrote on 26 Nov 2013, 08:08 last edited by
              #6

              I tried that too, but
              @bool QSortFilterProxyModel::filterAcceptsRow(int sourcerow, const QModelIndex &sourceparent) const@

              is const so I can't change attributes in the function.

              My filter currently looks like:

              @bool Filter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
              {
              int today = QDate::currentDate().year()0;
              if(sourceRow >= minrow && sourceRow <= maxrow)
              {
              QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent), //Date
              index1 = sourceModel()->index(sourceRow, 1, sourceParent), //Time
              index2 = sourceModel()->index(sourceRow, 2, sourceParent), //Source
              index3 = sourceModel()->index(sourceRow, 4, sourceParent), //Data0
              index4 = sourceModel()->index(sourceRow, 8, sourceParent); //Event/Error

                  QStringList timevalues = sourceModel()->data(index1).toString().split(':');   //split the time string from the filter to houres, minutes and seconds
              
                  QString  h = timevalues.at(0),
                           m = timevalues.at(1),
                           s = timevalues.at(2);
                  //make the time string to a time      
                  QTime timer(h.toInt(), m.toInt(), s.toInt()); 
              

              //split the time string from the filter to year, month and day
              timevalues = sourceModel()->data(index0).toString().split('/');
              h = timevalues.at(2), //year
              m = timevalues.at(1), //month
              s = timevalues.at(0); //day

                  if(h.toInt() <= today && h.size() == 2)
                      h.insert(0, "20");
                  else h.insert(0, "19");
              

              //make the time string to a time
              QDate dater(h.toInt(), m.toInt(), s.toInt());

              //now check if the rows data fit with the filter
              return timeInRange(timer)
              && dateInRange(dater)
              && sourcecheck(index2)
              && data0check(index3)
              && sourceModel()->data(index4).toString().contains(this->rxtype);
              }
              else return false;
              }@

              and I can't call a not const function in it that counts the hidden rows

              1 Reply Last reply
              0
              • R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 26 Nov 2013, 08:14 last edited by
                #7

                why do you need to change attributes?!
                You are just reading the max count. When you set the max count from externally do also an invalidate of the filter.
                And if you really have to change the attribute from the inside of a const method declare it as "mutable".

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Tecnova
                  wrote on 26 Nov 2013, 09:05 last edited by
                  #8

                  ah OK didn't know that.
                  thanks a lot.
                  it works now :)

                  1 Reply Last reply
                  0

                  1/8

                  25 Nov 2013, 14:43

                  • Login

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