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] QSqlTableModel::insertRow() from QSortFilterProxyModel
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QSqlTableModel::insertRow() from QSortFilterProxyModel

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.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.
  • I Offline
    I Offline
    i92guboj
    wrote on last edited by
    #1

    Hello.

    I am trying to get a new row inserted into a QSqlTableModel from a proxy model.

    I am aware of the map{To,From}Source methods, but I am not having much luck. Probably because I don't get the logic behind this.

    Right now I am trying this:

    [code]
    QModelIndex index_this;
    QModelIndex index_source;

    // get row count from the source model
    int row = myBudget->models.cases_and_accesories->sourceModel()->rowCount();
    
    // this, unfortunately, does nothing in the proxy model, which is what I'd like
    myBudget->models.cases_and_accesories->sourceModel()->insertRow(row);
    index_source = myBudget->models.cases_and_accesories->sourceModel()->index(row, 4);
    index_this = myBudget->models.cases_and_accesories->mapFromSource(index_source);
    ui->tableView_cascosYAccesorios->setCurrentIndex(index_this);
    qDebug() << Q_FUNC_INFO << QString("index_this: %1, %2; index_source: %3,%4")
                .arg(index_this.row()).arg(index_this.column())
                .arg(index_source.row()).arg(index_source.column());
    ui->tableView_cascosYAccesorios->edit(index_this);
    

    [/code]

    qDebug() reports that index_source has sane and adequate values, but index_this is -1,-1, so, unsurprisingly, I can't edit anything in the proxy model (there's no new row either, so no surprise there).

    I am sure there must be something simple I am missing...

    Can anyone help me on this one? I have looked at the examples, the addressbook particularly, and they seem to pick the row from the source model, just as I do. But surely there's some other bit that I am not getting.

    Thank you for any help.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      i92guboj
      wrote on last edited by
      #2

      I'll answer myself.

      The problem has, in fact, nothing to do with the proxy (well, it has, but not in the direct way that I thought).

      After losing a few valuable hours of work, I thought of commenting out the filters, and it started working. I just had to add to the setFilterRegExp() expression the empty string.

      [code]
      models.cases_and_accesories->setFilterRegExp(QRegExp(".AL..|.BA..|.BT..|.COL.|.SEN.|.SEB.|^$"));
      [/code]

      The '|^$' did the trick. The rest of the code remains similar to the one I was using above,

      [code]
      QModelIndex index;
      QModelIndex sourceIndex;
      int row = myBudget->models.presupuestoCompleto->rowCount();
      myBudget->models.presupuestoCompleto->insertRow(row);
      sourceIndex = myBudget->models.presupuestoCompleto->index(row, 4);
      index = myBudget->models.doors_and_drawers->mapFromSource(sourceIndex);
      ui->tableView_PuertasYCajones->edit(index);
      [/code]

      Just need to do the index mapping, and it works!

      Thank you for reading and sorry for the noise ;)

      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