Преглед изворни кода

rework ctkDICOM for use as a widget or application

Change the infrastructure so you can set a database directory
to store a ctkDICOM.sql file with the index along with any files that
are imported to the application.
Steve Pieper пре 14 година
родитељ
комит
cf09e00d16

+ 30 - 15
Applications/ctkDICOM/ctkDICOMMain.cpp

@@ -21,6 +21,8 @@
 // Qt includes
 #include <QApplication>
 #include <QTreeView>
+#include <QSettings>
+#include <QDir>
 
 // CTK widget includes
 #include <ctkDICOMQueryRetrieveWidget.h>
@@ -44,35 +46,48 @@ int main(int argc, char** argv)
   app.setOrganizationDomain("commontk.org");
   app.setApplicationName("ctkDICOM");
 
+  QSettings settings;
+  QString databaseDirectory;
+
   // set up the database 
-  const char *datbaseFileName = "/tmp/test.db";
-  const char *datbaseScriptFileName = "/Users/pieper/ctk/latest/CTK/Libs/DICOM/Core/Resources/dicom-sample.sql";
   if (argc > 1)
     {
-    datbaseFileName = argv[1];
+    QString directory(argv[1]);
+    settings.setValue("DatabaseDirectory", directory);
+    settings.sync();
     }
-  if (argc > 2)
+
+  if ( settings.value("DatabaseDirectory", "") == "" )
+  {
+    databaseDirectory = QString("./ctkDICOM-Database");
+    std::cerr << "No DatabaseDirectory on command line or in settings.  Using \"" << databaseDirectory.toLatin1().data() << "\".\n";
+  } else
+  {
+    databaseDirectory = settings.value("DatabaseDirectory", "").toString();
+  }
+
+  QDir qdir(databaseDirectory);
+  if ( !qdir.exists(databaseDirectory) ) 
+  {
+    if ( !qdir.mkpath(databaseDirectory) )
     {
-    datbaseScriptFileName = argv[2];
+      std::cerr << "Could not create database directory \"" << databaseDirectory.toLatin1().data() << "\".\n";
+      return EXIT_FAILURE;
     }
+  }
+
+
+  QString databaseFileName = databaseDirectory + QString("/ctkDICOM.sql");
 
   ctkDICOM myCTK;
-  try { myCTK.openDatabase( datbaseFileName ); }
+  try { myCTK.openDatabase( databaseFileName ); }
   catch (std::exception e)
   {
-    std::cerr << "Database error:" << qPrintable(myCTK.GetLastError());
+    std::cerr << "Database error:" << qPrintable(myCTK.GetLastError()) << "\n";
     myCTK.closeDatabase();
     return EXIT_FAILURE;
   }
 
-  try { myCTK.initializeDatabase(datbaseScriptFileName); }
-  catch (std::exception e)
-  {
-    std::cerr << "Error when initializing the data base: " << datbaseScriptFileName
-              << " error: " << myCTK.GetLastError().toStdString();
-    return EXIT_FAILURE;
-  }
-
   ctkDICOMModel model;
   model.setDatabase(myCTK.database());
   

+ 0 - 0
Libs/DICOM/Core/ctkDICOMQuery.cpp


+ 0 - 0
Libs/DICOM/Core/ctkDICOMRetrieve.cpp


+ 87 - 25
Libs/DICOM/Widgets/Resources/UI/ctkDICOMQueryRetrieveWidget.ui

@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>762</width>
+    <width>977</width>
     <height>769</height>
    </rect>
   </property>
@@ -24,17 +24,96 @@
      </property>
      <layout class="QHBoxLayout" name="horizontalLayout">
       <item>
-       <widget class="ctkDICOMServerNodeWidget" name="serverNodeWidget" native="true">
-        <property name="minimumSize">
-         <size>
-          <width>300</width>
-          <height>200</height>
-         </size>
+       <widget class="QGroupBox" name="groupBox">
+        <property name="title">
+         <string>Data Sources</string>
         </property>
+        <layout class="QVBoxLayout" name="verticalLayout_2">
+         <item>
+          <widget class="QFrame" name="frame_2">
+           <property name="frameShape">
+            <enum>QFrame::StyledPanel</enum>
+           </property>
+           <property name="frameShadow">
+            <enum>QFrame::Raised</enum>
+           </property>
+           <layout class="QHBoxLayout" name="horizontalLayout_3">
+            <item>
+             <widget class="QLabel" name="label">
+              <property name="text">
+               <string>Local Database</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="ctkDirectoryButton" name="sqlDirectory" native="true">
+              <property name="minimumSize">
+               <size>
+                <width>30</width>
+                <height>0</height>
+               </size>
+              </property>
+              <property name="toolTip">
+               <string>Local directory where cached files and database index file are stored.</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QPushButton" name="addToDatabase">
+              <property name="toolTip">
+               <string>Add more files to the local database by browsing the filesystem</string>
+              </property>
+              <property name="text">
+               <string>Add...</string>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </widget>
+         </item>
+         <item>
+          <widget class="QFrame" name="frame_3">
+           <property name="frameShape">
+            <enum>QFrame::StyledPanel</enum>
+           </property>
+           <property name="frameShadow">
+            <enum>QFrame::Raised</enum>
+           </property>
+           <layout class="QVBoxLayout" name="verticalLayout_3">
+            <item>
+             <widget class="QLabel" name="label_2">
+              <property name="text">
+               <string>Query Targets</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="ctkDICOMServerNodeWidget" name="serverNodeWidget" native="true">
+              <property name="minimumSize">
+               <size>
+                <width>300</width>
+                <height>200</height>
+               </size>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </widget>
+         </item>
+        </layout>
        </widget>
       </item>
       <item>
-       <widget class="ctkDICOMQueryWidget" name="queryWidget" native="true"/>
+       <widget class="QGroupBox" name="groupBox_2">
+        <property name="title">
+         <string>Search Options</string>
+        </property>
+        <layout class="QVBoxLayout" name="verticalLayout_4">
+         <item>
+          <widget class="ctkDICOMQueryWidget" name="queryWidget" native="true"/>
+         </item>
+        </layout>
+       </widget>
       </item>
      </layout>
     </widget>
@@ -43,23 +122,6 @@
     <widget class="QWidget" name="commandFrame" native="true">
      <layout class="QHBoxLayout" name="horizontalLayout_4">
       <item>
-       <widget class="QLabel" name="label">
-        <property name="text">
-         <string>Local Database</string>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="ctkDirectoryButton" name="sqlDirectory" native="true">
-        <property name="minimumSize">
-         <size>
-          <width>30</width>
-          <height>0</height>
-         </size>
-        </property>
-       </widget>
-      </item>
-      <item>
        <spacer name="horizontalSpacer">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>

+ 4 - 10
Libs/DICOM/Widgets/Resources/UI/ctkDICOMServerNodeWidget.ui

@@ -31,8 +31,8 @@
        <rect>
         <x>0</x>
         <y>0</y>
-        <width>572</width>
-        <height>394</height>
+        <width>580</width>
+        <height>414</height>
        </rect>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout_2">
@@ -44,12 +44,6 @@
          <attribute name="verticalHeaderStretchLastSection">
           <bool>false</bool>
          </attribute>
-         <attribute name="horizontalHeaderStretchLastSection">
-          <bool>true</bool>
-         </attribute>
-         <attribute name="verticalHeaderStretchLastSection">
-          <bool>false</bool>
-         </attribute>
          <column>
           <property name="text">
            <string>Name</string>
@@ -88,14 +82,14 @@
       <item>
        <widget class="QPushButton" name="addButton">
         <property name="text">
-         <string>Add...</string>
+         <string>Add Server</string>
         </property>
        </widget>
       </item>
       <item>
        <widget class="QPushButton" name="removeButton">
         <property name="text">
-         <string>Remove</string>
+         <string>Remove Server</string>
         </property>
        </widget>
       </item>

+ 9 - 0
Libs/DICOM/Widgets/ctkDICOMQueryRetrieveWidget.cpp

@@ -37,12 +37,14 @@ ctkDICOMQueryRetrieveWidget::ctkDICOMQueryRetrieveWidget(QWidget* _parent):Super
   connect(d->queryButton, SIGNAL(clicked()), this, SLOT(processQuery()));
   connect(d->results, SIGNAL(tabCloseRequested(int)), this, SLOT(onTabCloseRequested(int)));
   connect(d->sqlDirectory, SIGNAL(directoryChanged(const QString&)), this, SLOT(onDatabaseDirectoryChanged(const QString&)));
+  connect(d->addToDatabase, SIGNAL(clicked()), this, SLOT(onAddToDatabase()));
 
   QSettings settings;
   if ( settings.value("DatabaseDirectory", "") != "" )
   {
     d->sqlDirectory->setDirectory(settings.value("DatabaseDirectory").toString());
   }
+
 }
 
 //----------------------------------------------------------------------------
@@ -71,6 +73,13 @@ void ctkDICOMQueryRetrieveWidget::onTabCloseRequested(int index)
   d->results->removeTab(index);
 }
 
+void ctkDICOMQueryRetrieveWidget::onAddToDatabase()
+{
+  Q_D(ctkDICOMQueryRetrieveWidget);
+
+  //d->
+}
+
 //----------------------------------------------------------------------------
 void ctkDICOMQueryRetrieveWidget::processQuery()
 {

+ 1 - 0
Libs/DICOM/Widgets/ctkDICOMQueryRetrieveWidget.h

@@ -40,6 +40,7 @@ public slots:
     void onDatabaseDirectoryChanged(const QString& directory);
     void processQuery();
     void onTabCloseRequested(int index);
+    void onAddToDatabase();
 
 protected:
   QScopedPointer<ctkDICOMQueryRetrieveWidgetPrivate> d_ptr;

+ 9 - 3
Libs/DICOM/Widgets/ctkDICOMServerNodeWidget.cpp

@@ -75,13 +75,19 @@ ctkDICOMServerNodeWidget::ctkDICOMServerNodeWidget(QWidget* _parent):Superclass(
   QMap<QString, QVariant> node;
   if ( settings.value("ServerNodeCount").toInt() == 0 )
   {
-    node["Name"] = "localhost";
+    node["Name"] = "Local Database";
     node["CheckState"] = Qt::Checked;
+    node["AETitle"] = "N/A";
+    node["Address"] = "N/A";
+    node["Port"] = "N/A";
+    settings.setValue("ServerNodeCount", 2);
+    settings.setValue("ServerNodes/0", QVariant(node));
+    node["Name"] = "ExampleHost";
+    node["CheckState"] = Qt::Unchecked;
     node["AETitle"] = "CTK_AE";
     node["Address"] = "localhost";
     node["Port"] = "11112";
-    settings.setValue("ServerNodeCount", 3);
-    settings.setValue("ServerNodes/0", QVariant(node));
+    settings.setValue("ServerNodes/1", QVariant(node));
     settings.sync();
   }