ctkSearchBoxTest2.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QDebug>
  17. #include <QLabel>
  18. #include <QListView>
  19. #include <QSortFilterProxyModel>
  20. #include <QStringListModel>
  21. #include <QTimer>
  22. #include <QVBoxLayout>
  23. //CTK includes
  24. #include "ctkSearchBox.h"
  25. // STD includes
  26. #include <cstdlib>
  27. #include <iostream>
  28. // ------------------------------------------------------------------------------
  29. int ctkSearchBoxTest2(int argc, char* argv[])
  30. {
  31. QApplication app(argc, argv);
  32. QStringList stringList;
  33. stringList<<"totoa"<<"TOTOaa"<<"tic"<<"tac"<<"nice"<<"slicer"<<"monday"<<"july"<<"phone";
  34. ctkSearchBox search3;
  35. search3.show();
  36. search3.setText("phone");
  37. QRegExp regExp(search3.text(),Qt::CaseInsensitive, QRegExp::Wildcard);
  38. //QStringList testFilter = stringList.filter(search3.text());
  39. QStringList testFilter = stringList.filter(regExp);
  40. qDebug() << "Result of Test Filter : " << testFilter;
  41. if (testFilter.size() >= stringList.size())
  42. {
  43. qDebug() << "Line : " << __LINE__<< " error with the filter : " << search3.text();
  44. }
  45. QStringListModel listModel(stringList);
  46. QSortFilterProxyModel filterModel;
  47. filterModel.setSourceModel(&listModel);
  48. filterModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
  49. filterModel.setFilterWildcard(search3.text());
  50. QObject::connect(&search3, SIGNAL(textChanged(QString)),
  51. &filterModel, SLOT(setFilterWildcard(QString)));
  52. QListView listView;
  53. listView.setModel(&filterModel);
  54. listView.show();
  55. if (argc < 2 || QString(argv[1]) != "-I" )
  56. {
  57. QTimer::singleShot(200, &app, SLOT(quit()));
  58. }
  59. return app.exec();
  60. }