Results 1 to 10 of 10

Thread: QTableView and a row validation

  1. #1
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableView and a row validation

    Hi!
    I have usual MVC-setup (QTableModel descendant paired with QTableView descendant) and trying to do a row-based validation (field-based validation does not cut it in this case - validation is based on a combination of field values). So, the view calls model.submit(), the model validates the edited record, says 'no way' and returns False. But how do I tell the table view to return into editing state? The model does not know which view called it's submit() slot, if I understand correctly. Any thoughts?

  2. #2
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView and a row validation

    Allmost got it. I created a signal model.rowNotValidated(QModelIndex), which is emitted when model.submit() failes. Then I connected it to QTableView.edit() slot. It works well when a user presses Enter to submit edits, but does not work if a user ends editing by clicking on another row or elsewhere.

  3. #3
    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: QTableView and a row validation

    Isn't submit() a little bit too late to do validation? How about having a proxy model that accepts all crazy entries and does validation upon some signal from the view that the user changed the current row? Then you can decide whether to submit the data to the base model or not. And you have complete information about which row caused the failure.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView and a row validation

    The validation per se is not a problem - how to deal with an usuccessful validation is. I know what row coused the failure (had to setup a simple tracking), so what I need is to signal TableView() - "Hey, it was all wrong, go back to editing state, row is not accepted."

    I fail to see how a proxy model would be of any help in this case. After all, that proxy model would still be connected to TableView and I would still need to catch the moment editing is finished(with submit()), validate the input and return QTableView back into editing state upon usuccessful validation.

  5. #5
    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: QTableView and a row validation

    submit() does not mean that editing is finished. There can be cases when editing is finished but submit() is not called. I'm telling you to monitor QAbstractItemView::currentIndex() and when its row changes, start the validation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView and a row validation

    Actually, I've managed to ensure that submit() is called using QTableView.closeEditor(hint) - when user clicks away from the edited record, the hint == QAbstractItemDelegate.NoHint, in that case I call QTableView.closeEditor() with hint= QAbstractItemDelegate.SubmitModelCache. The problem is in the view - I need to reliably return it back to editing state

  7. #7
    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: QTableView and a row validation

    Doesn't calling edit() do what you want?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView and a row validation

    For some strange reason - no. Actually, it does set the view into an editing state, but... it starts editing another row that user clicked to.

  9. #9
    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: QTableView and a row validation

    Are you passing a proper index to edit()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView and a row validation

    Yes, I am. Also, view's edit triggers are EditKeyPressed|DoubleClicked, so a single click should not trigger editing, so the editing is defenitely a result of a call view.edit(). But why does it start editing in a wrong place? Mistery.


    Added after 30 minutes:


    Oh, I was connecting my signal to another object, which happend to have a method called edit - imagine that. So no errors visible. A shame. But still - maybe it's time for me to give up trying to do it through Q..View.closeEditor() and go with something more reliable, as was recommended above. Are there eny examples of implementing record-based editing with record validation?
    Last edited by AlexVhr; 28th November 2012 at 21:30.

Similar Threads

  1. set the validation for checkboxes
    By sangee in forum Qt Programming
    Replies: 10
    Last Post: 24th August 2012, 09:45
  2. XML Validation
    By NoRulez in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2010, 13:07
  3. QTableView QItemDelegate validation
    By pippo42 in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2010, 09:23
  4. Validation
    By Tavit in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2009, 07:03
  5. XML DTC validation problem
    By shailesh in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2006, 13:12

Tags for this Thread

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.