ctkDICOMMain.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.commontk.org/LICENSE
  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 <QTreeView>
  17. #include <QSettings>
  18. #include <QDir>
  19. // CTK widget includes
  20. #include <ctkDICOMQueryRetrieveWidget.h>
  21. // ctkDICOMCore includes
  22. #include "ctkDICOM.h"
  23. #include "ctkDICOMModel.h"
  24. // Logger
  25. #include "ctkLogger.h"
  26. // STD includes
  27. #include <iostream>
  28. int main(int argc, char** argv)
  29. {
  30. ctkLogger::configure();
  31. QApplication app(argc, argv);
  32. app.setOrganizationName("commontk");
  33. app.setOrganizationDomain("commontk.org");
  34. app.setApplicationName("ctkDICOM");
  35. QSettings settings;
  36. QString databaseDirectory;
  37. // set up the database
  38. if (argc > 1)
  39. {
  40. QString directory(argv[1]);
  41. settings.setValue("DatabaseDirectory", directory);
  42. settings.sync();
  43. }
  44. if ( settings.value("DatabaseDirectory", "") == "" )
  45. {
  46. databaseDirectory = QString("./ctkDICOM-Database");
  47. std::cerr << "No DatabaseDirectory on command line or in settings. Using \"" << databaseDirectory.toLatin1().data() << "\".\n";
  48. } else
  49. {
  50. databaseDirectory = settings.value("DatabaseDirectory", "").toString();
  51. }
  52. QDir qdir(databaseDirectory);
  53. if ( !qdir.exists(databaseDirectory) )
  54. {
  55. if ( !qdir.mkpath(databaseDirectory) )
  56. {
  57. std::cerr << "Could not create database directory \"" << databaseDirectory.toLatin1().data() << "\".\n";
  58. return EXIT_FAILURE;
  59. }
  60. }
  61. QString databaseFileName = databaseDirectory + QString("/ctkDICOM.sql");
  62. ctkDICOM myCTK;
  63. try { myCTK.openDatabase( databaseFileName ); }
  64. catch (std::exception e)
  65. {
  66. std::cerr << "Database error: " << qPrintable(myCTK.GetLastError()) << "\n";
  67. myCTK.closeDatabase();
  68. return EXIT_FAILURE;
  69. }
  70. ctkDICOMModel model;
  71. model.setDatabase(myCTK.database());
  72. ctkDICOMQueryRetrieveWidget queryRetrieve;
  73. QTreeView *treeView = queryRetrieve.findChild<QTreeView *>("treeView");
  74. if (!treeView)
  75. {
  76. std::cerr << "Could not access tree view from QueryRetrieve widget\n";
  77. return EXIT_FAILURE;
  78. }
  79. treeView->setModel(&model);
  80. queryRetrieve.show();
  81. queryRetrieve.raise();
  82. return app.exec();
  83. }