ctkDICOMBrowserTest1.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <QDir>
  17. #include <QTimer>
  18. // ctk includes
  19. #include "ctkCoreTestingMacros.h"
  20. #include "ctkUtils.h"
  21. // ctkDICOMCore includes
  22. #include "ctkDICOMDatabase.h"
  23. // ctkDICOMWidget includes
  24. #include "ctkDICOMBrowser.h"
  25. // STD includes
  26. #include <iostream>
  27. int ctkDICOMBrowserTest1( int argc, char * argv [] )
  28. {
  29. QApplication app(argc, argv);
  30. qDebug() << "argc = " << argc;
  31. for (int i = 0; i < argc; ++i)
  32. {
  33. qDebug() << "\t" << argv[i];
  34. }
  35. QFileInfo tempFileInfo(QDir::tempPath() + QString("/ctkDICOMBrowserTest1-db"));
  36. QString dbDir = tempFileInfo.absoluteFilePath();
  37. qDebug() << "\n\nUsing directory: " << dbDir;
  38. if (tempFileInfo.exists())
  39. {
  40. qDebug() << "\n\nRemoving directory: " << dbDir;
  41. ctk::removeDirRecursively(dbDir);
  42. }
  43. qDebug() << "\n\nMaking directory: " << dbDir;
  44. QDir dir(dbDir);
  45. dir.mkdir(dbDir);
  46. ctkDICOMBrowser browser;
  47. browser.setDatabaseDirectory(dbDir);
  48. browser.show();
  49. browser.setDisplayImportSummary(false);
  50. qDebug() << "Importing directory " << argv[1];
  51. // [Deprecated]
  52. // make sure copy/link dialog doesn't pop up, always copy on import
  53. QSettings settings;
  54. QString settingsString = settings.value("MainWindow/DontConfirmCopyOnImport").toString();
  55. settings.setValue("MainWindow/DontConfirmCopyOnImport", QString("0")); // QMessageBox::AcceptRole
  56. CHECK_INT(browser.importDirectoryMode(), static_cast<int>(ctkDICOMBrowser::ImportDirectoryCopy));
  57. // [/Deprecated]
  58. browser.importDirectories(QStringList() << argv[1]);
  59. // [Deprecated]
  60. // reset to the original copy/import setting
  61. settings.setValue("MainWindow/DontConfirmCopyOnImport", settingsString);
  62. // [/Deprecated]
  63. CHECK_INT(browser.patientsAddedDuringImport(), 1);
  64. CHECK_INT(browser.studiesAddedDuringImport(), 1);
  65. CHECK_INT(browser.seriesAddedDuringImport(), 1);
  66. CHECK_INT(browser.instancesAddedDuringImport(), 100);
  67. qDebug() << "\n\nAdded to database directory: " << dbDir;
  68. if (argc <= 2 || QString(argv[argc - 1]) != "-I")
  69. {
  70. QTimer::singleShot(200, &app, SLOT(quit()));
  71. }
  72. return app.exec();
  73. }