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