Results 1 to 2 of 2

Thread: QAbstractListModel searching.

  1. #1
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default QAbstractListModel searching.

    I'm currently having trouble with writing my IRC client. When changing a user's channel status, and doing it my own self it updates fine. But when testing it with another client in a channel. Removing and adding statuses, the QListView model will not update the User's icons unless I move my mouse over the QListView. Currently I'm thinking the way I have it right now is just slow as hell and what not. Is there a better way of optimising the searching of a user?

    Qt Code:
    1. void
    2. ChannelTab::slotOnMode(const QString &from, const QString &channel, const QString &mode, const QString &nick)
    3. {
    4. if (name() != channel) {
    5. return;
    6. }
    7.  
    8. enum {
    9. None,
    10. Give,
    11. Take
    12. };
    13. int state = None;
    14.  
    15. QModelIndex index;
    16. Aki::Irc::User *user = 0;
    17.  
    18. //Aki::Irc::User *user = d->userList->model()->data(d->userList->currentIndex(), NickListModel::IrcUserRole)
    19. // .value<Aki::Irc::User*>();
    20.  
    21. for (int i = 0; i < d->userList->count(); ++i) {
    22. index = d->userList->model()->index(i, 0);
    23. user = d->userList->model()->data(index, NickListModel::IrcUserRole).value<Aki::Irc::User*>();
    24. if (user->nick() == nick) {
    25. kDebug() << "found";
    26. break;
    27. }
    28. }
    29.  
    30. if (!user) {
    31. return;
    32. }
    33.  
    34. QString modes = user->modes();
    35. bool fromYou = from == d->socket->currentNick();
    36. bool toYou = nick == d->socket->currentNick();
    37.  
    38. foreach (QChar c, mode) {
    39. if (c == QChar('+')) {
    40. state = Give;
    41. kDebug() << "Give";
    42. } else if (c == QChar('-')) {
    43. state = Take;
    44. kDebug() << "Take";
    45. } else if (c == QChar('o')) {
    46. if (state == Give) {
    47. user->setModes(modes + c);
    48. d->userList->model()->setData(d->userList->currentIndex(),
    49. QVariant::fromValue<Aki::Irc::User*>(user),
    50. NickListModel::IrcUserRole);
    51. d->channelOutput->addMode(from, nick, c, toYou, fromYou);
    52. } else if (state == Take) {
    53. user->removeModes(c);
    54. d->userList->model()->setData(d->userList->currentIndex(),
    55. QVariant::fromValue<Aki::Irc::User*>(user),
    56. NickListModel::IrcUserRole);
    57. d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
    58. }
    59. } else if (c == QChar('v')) {
    60. if (state == Give) {
    61. user->setModes(modes + c);
    62. d->userList->model()->setData(d->userList->currentIndex(),
    63. QVariant::fromValue<Aki::Irc::User*>(user),
    64. NickListModel::IrcUserRole);
    65. d->channelOutput->addMode(from, nick, c, toYou, fromYou);
    66. } else if (state == Take) {
    67. user->removeModes(c);
    68. d->userList->model()->setData(d->userList->currentIndex(),
    69. QVariant::fromValue<Aki::Irc::User*>(user),
    70. NickListModel::IrcUserRole);
    71. d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
    72. }
    73. } else if (c == QChar('h')) {
    74. if (state == Give) {
    75. user->setModes(modes + c);
    76. d->userList->model()->setData(d->userList->currentIndex(),
    77. QVariant::fromValue<Aki::Irc::User*>(user),
    78. NickListModel::IrcUserRole);
    79. d->channelOutput->addMode(from, nick, c, toYou, fromYou);
    80. } else if (state == Take) {
    81. user->removeModes(c);
    82. d->userList->model()->setData(d->userList->currentIndex(),
    83. QVariant::fromValue<Aki::Irc::User*>(user),
    84. NickListModel::IrcUserRole);
    85. d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
    86. }
    87. }
    88. }
    89. }
    To copy to clipboard, switch view to plain text mode 
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  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: QAbstractListModel searching.

    I can't make much from the code above but you are probably not emitting proper signals from your model (like dataChanged() from setData()).
    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.


Similar Threads

  1. Searching files from directories & its subdirectories
    By ashukla in forum Qt Programming
    Replies: 4
    Last Post: 12th April 2014, 13:57
  2. Replies: 6
    Last Post: 30th December 2010, 12:19
  3. QAbstractListModel problem
    By UltimatePace in forum Qt Programming
    Replies: 5
    Last Post: 27th September 2009, 11:51
  4. QAbstractListModel and icon problem
    By mchrk in forum Qt Programming
    Replies: 2
    Last Post: 11th March 2009, 12:21

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.