ctkDICOMModelTest2.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <QFileInfo>
  18. #include <QHBoxLayout>
  19. #include <QTimer>
  20. #include <QTreeView>
  21. // ctkDICOMCore includes
  22. #include "ctkDICOMDatabase.h"
  23. #include "ctkDICOMModel.h"
  24. #include "ctkModelTester.h"
  25. // CTK includes
  26. #include "ctkCheckableHeaderView.h"
  27. #include <ctkCheckableModelHelper.h>
  28. // STD includes
  29. #include <iostream>
  30. /* Test from build directory:
  31. ./CTK-build/bin/CTKDICOMCoreCxxTests ctkDICOMModelTest1 test.db ../CTK/Libs/DICOM/Core/Resources/dicom-sample.sql
  32. */
  33. int ctkDICOMModelTest2( int argc, char * argv [] )
  34. {
  35. QApplication app(argc, argv);
  36. if (argc <= 2)
  37. {
  38. std::cerr << "Warning, no sql file given. Test stops" << std::endl;
  39. std::cerr << "Usage: qctkDICOMModelTest1 <scratch.db> <dumpfile.sql>" << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. try
  43. {
  44. ctkDICOMDatabase myCTK( argv[1] );
  45. if (!myCTK.initializeDatabase(argv[2]))
  46. {
  47. std::cerr << "Error when initializing the data base: " << argv[2]
  48. << " error: " << myCTK.lastError().toStdString();
  49. }
  50. ctkDICOMModel model;
  51. model.setDatabase(myCTK.database());
  52. QWidget topLevel;
  53. QTreeView viewer;
  54. QHBoxLayout* layout = new QHBoxLayout;
  55. layout->addWidget(&viewer);
  56. topLevel.setLayout(layout);
  57. viewer.setModel(&model);
  58. QHeaderView* previousHeaderView = viewer.header();
  59. qDebug() << "previous: " << previousHeaderView->isHidden();
  60. ctkCheckableHeaderView* headerView = new ctkCheckableHeaderView(Qt::Horizontal, &viewer);
  61. #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
  62. headerView->setClickable(previousHeaderView->isClickable());
  63. headerView->setMovable(previousHeaderView->isMovable());
  64. #else
  65. headerView->setSectionsClickable(previousHeaderView->sectionsClickable());
  66. headerView->setSectionsMovable(previousHeaderView->sectionsMovable());
  67. #endif
  68. headerView->setHighlightSections(previousHeaderView->highlightSections());
  69. headerView->checkableModelHelper()->setPropagateDepth(-1);
  70. headerView->checkableModelHelper()->setForceCheckability(true);
  71. viewer.setHeader(headerView);
  72. model.setHeaderData(0, Qt::Horizontal, Qt::Checked, Qt::CheckStateRole);
  73. qDebug() << "new: " << headerView->isHidden();
  74. topLevel.show();
  75. if (argc <= 3 || QString(argv[3]) != "-I")
  76. {
  77. QTimer::singleShot(200, &app, SLOT(quit()));
  78. }
  79. return app.exec();
  80. }
  81. catch (std::exception e)
  82. {
  83. std::cerr << "Error when opening the data base file: " << argv[1]
  84. << " error: " << e.what();
  85. return EXIT_FAILURE;
  86. }
  87. }