Results 1 to 4 of 4

Thread: deleting selected headers

  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default deleting selected headers

    Hello everybody,
    Have a trouble:

    I have to delete selected headers in the tableView model. To get this I create two slots:

    slotHeadersToBeDeleted slot checks whether selected Item was selected before. If yes (was selected and clicked again then it should be deleted from the vector for deleted headers) other way it should be added to the vector for deleted headers. When the necessary headers have been selected the user should push the button “deleteButton” and the headers are to be deleted.

    Qt Code:
    1. Class1
    2. {
    3. …
    4. QVector<int> m_vHeadersToBeDeleted;
    5. QStandardItemModel m_pDataModel;
    6. …
    7. };
    8. …
    9.  
    10. void Class1:: slotHeadersToBeDeleted(int LogicalIndex)
    11. {
    12. bool headerStatus = false;
    13. QVector<int>::iterator i = m_vHeadersToBedeleted.begin();
    14. while (i < m_vHeadersToBedeleted.end())
    15. {
    16. if (*i == LogicalIndex)
    17. {
    18. m_vHeadersToBedeleted.erase(i);
    19. headerStatus = true;
    20. }
    21.  
    22. i++;
    23. }
    24. if (headerStatus) m_vHeadersToBedeleted.push_back(LogicalIndex);
    25. }
    26.  
    27. void Class1::slotDeleteSelectedItems()
    28. {
    29. QVector<int>::iterator i = m_vHeadersToBedeleted.begin();
    30. while (i < m_vHeadersToBedeleted.end())
    31. {
    32. m_pDataModel->removeRow(*i);
    33. i++;
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 


    and in the constructor of class Class1 I created two connections:

    Qt Code:
    1. connect(m_pTable->verticalHeader(), SIGNAL(sectionClicked(int LogicalIndex)), this, SLOT(slotHeadersToBedeleted(int LogicalIndex)));
    2. connect(m_pDeleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteSelectedItems()));
    To copy to clipboard, switch view to plain text mode 

    where m_pTable is QTableView object
    m_pDeleteButton is a QPushButton

    the headers are not deleted. Where am I mistaken?
    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: deleting selected headers

    First of all I'd use i!=m_vHeadersToBedeleted.end(). Second of all if you start deleting rows then their internal numbers are going to change, so your list of rows to delete won't make sense unless it's sorted and you iterate in descending order (which does not seem to be the case here). Third of all what is the type of m_pDataModel?

  3. #3
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: deleting selected headers

    thank you for the reply.

    m_pDataModel has QStandardItemModel Class. m_pDataModel is set as
    Qt Code:
    1. m_pTable->setModel(m_pDataModel);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: deleting selected headers

    Ok, so correct the remaining problems and then we'll continue.

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.