Results 1 to 2 of 2

Thread: What actually calls QAbstractionTableModel::insertRows() ?

  1. #1
    Join Date
    Jun 2014
    Posts
    30
    Thanks
    4
    Qt products
    Qt5

    Default What actually calls QAbstractionTableModel::insertRows() ?

    I implemented QAbstractTableModel with the usual:

    Qt Code:
    1. class PrintIntervalTableModel : public QAbstractTableModel
    2. {
    3. private:
    4. virtual int rowCount (const QModelIndex & parent = QModelIndex()) const;
    5. virtual int columnCount (const QModelIndex & parent = QModelIndex()) const;
    6. virtual QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const;
    7. virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    8. virtual bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
    9. virtual Qt::ItemFlags flags (const QModelIndex & index) const;
    10.  
    11. virtual bool insertRows (int position, int rows, const QModelIndex & parent = QModelIndex());
    12. virtual bool removeRows (int position, int rows, const QModelIndex & parent = QModelIndex());
    To copy to clipboard, switch view to plain text mode 

    Here is my insert rows, which is pretty simple:

    Qt Code:
    1. bool PrintIntervalTableModel::insertRows(int position, int rows, const QModelIndex & parent)
    2. {
    3. beginInsertRows(QModelIndex(), position, position + rows - 1);
    4.  
    5. for (int row = 0; row < rows; ++row)
    6. {
    7. std::deque<moment_value_pair_type>::iterator it = printIntervalPairs.begin() + position;
    8. printIntervalPairs.insert(it, moment_value_pair_type());
    9. }
    10.  
    11. endInsertRows();
    12.  
    13. return true;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Now I wonder why I actually did this? Do views (or other components) call this method?

    I would like to have a button on the form that, once clicked, inserts a row underneath the user's current selection. Do I basically create a slot in the table (connected to button clicked()) that figures out where to insert the row, and then manually calls table->insertRows()?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: What actually calls QAbstractionTableModel::insertRows() ?

    Anything that needs to add a row into a model will use insertRows() directly or indirectly. Your code might do that in response to a direct user command (as in the case of your Add Row button). It might happen less directly as the result a paste or drag and drop operation. Your code may use this function while you are loading the initial data into a model (like inserting an entry into a combo box does with the underlying model). If you use the model interface in any sort of internal computation you might insert a result row using this function ( no human or view required)

Similar Threads

  1. Replies: 6
    Last Post: 12th September 2012, 08:43
  2. QSortFilterProxyModel::insertRows always adds rows to the end
    By Agnostic Pope in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2012, 23:23
  3. Rowcount and insertrows differences
    By tonnot in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2011, 08:56
  4. Replies: 0
    Last Post: 13th April 2011, 08:47
  5. QTable insertRows issue
    By PrimeCP in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 09:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.