Przeglądaj źródła

improvements to the dicom widgets and application

- save server nodes to settings for persistance between runs of the
  program
- change the date widgets (remove time and add calendar)
Steve Pieper 14 lat temu
rodzic
commit
84e1ab5879

+ 4 - 0
Applications/ctkDICOM/ctkDICOMMain.cpp

@@ -40,6 +40,10 @@ int main(int argc, char** argv)
   ctkLogger::configure();
   QApplication app(argc, argv);
 
+  app.setOrganizationName("commontk");
+  app.setOrganizationDomain("commontk.org");
+  app.setApplicationName("ctkDICOM");
+
   // 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";

+ 30 - 2
Libs/DICOM/Widgets/Resources/UI/ctkDICOMQueryWidget.ui

@@ -158,10 +158,38 @@
              </widget>
             </item>
             <item>
-             <widget class="QDateTimeEdit" name="dateTimeEdit"/>
+             <widget class="QDateTimeEdit" name="dateTimeEdit">
+              <property name="date">
+               <date>
+                <year>2010</year>
+                <month>1</month>
+                <day>1</day>
+               </date>
+              </property>
+              <property name="displayFormat">
+               <string>MMM/dd/yyyy</string>
+              </property>
+              <property name="calendarPopup">
+               <bool>true</bool>
+              </property>
+             </widget>
             </item>
             <item>
-             <widget class="QDateTimeEdit" name="dateTimeEdit_2"/>
+             <widget class="QDateTimeEdit" name="dateTimeEdit_2">
+              <property name="date">
+               <date>
+                <year>2010</year>
+                <month>12</month>
+                <day>31</day>
+               </date>
+              </property>
+              <property name="displayFormat">
+               <string>MMM/dd/yyyy</string>
+              </property>
+              <property name="calendarPopup">
+               <bool>true</bool>
+              </property>
+             </widget>
             </item>
            </layout>
           </widget>

+ 18 - 9
Libs/DICOM/Widgets/Resources/UI/ctkDICOMServerNodeWidget.ui

@@ -38,11 +38,18 @@
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <widget class="QTableWidget" name="nodeTable">
-         <row>
-          <property name="text">
-           <string>Localhost</string>
-          </property>
-         </row>
+         <attribute name="horizontalHeaderStretchLastSection">
+          <bool>true</bool>
+         </attribute>
+         <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>
@@ -58,11 +65,13 @@
            <string>Address</string>
           </property>
          </column>
+         <column>
+          <property name="text">
+           <string>Port</string>
+          </property>
+         </column>
         </widget>
        </item>
-       <item>
-        <widget class="QListView" name="listView"/>
-       </item>
       </layout>
      </widget>
     </widget>
@@ -79,7 +88,7 @@
       <item>
        <widget class="QPushButton" name="addButton">
         <property name="text">
-         <string>Add</string>
+         <string>Add...</string>
         </property>
        </widget>
       </item>

+ 108 - 13
Libs/DICOM/Widgets/ctkDICOMServerNodeWidget.cpp

@@ -1,7 +1,7 @@
 /*=========================================================================
 
   Library:   CTK
- 
+
   Copyright (c) 2010  Kitware Inc.
 
   Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,7 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
- 
+
 =========================================================================*/
 
 /// CTK includes
@@ -28,6 +28,13 @@
 // STD includes
 #include <iostream>
 
+// Qt includes
+#include <QList>
+#include <QMap>
+#include <QVariant>
+#include <QSettings>
+#include <QTableWidgetItem>
+
 //----------------------------------------------------------------------------
 class ctkDICOMServerNodeWidgetPrivate: public Ui_ctkDICOMServerNodeWidget
 {
@@ -43,11 +50,11 @@ public:
 // ctkDICOMServerNodeWidget methods
 
 //----------------------------------------------------------------------------
-ctkDICOMServerNodeWidget::ctkDICOMServerNodeWidget(QWidget* _parent):Superclass(_parent), 
+ctkDICOMServerNodeWidget::ctkDICOMServerNodeWidget(QWidget* _parent):Superclass(_parent),
   d_ptr(new ctkDICOMServerNodeWidgetPrivate)
 {
   Q_D(ctkDICOMServerNodeWidget);
-  
+ 
   d->setupUi(this);
 
   // checkable headers.
@@ -57,17 +64,58 @@ ctkDICOMServerNodeWidget::ctkDICOMServerNodeWidget(QWidget* _parent):Superclass(
   headerView->setClickable(previousHeaderView->isClickable());
   headerView->setMovable(previousHeaderView->isMovable());
   headerView->setHighlightSections(previousHeaderView->highlightSections());
-  //headerView->setModel(previousHeaderView->model());
-  //headerView->setSelectionModel(previousHeaderView->selectionModel());
   headerView->setPropagateToItems(true);
   d->nodeTable->setHorizontalHeader(headerView);
 
   d->removeButton->setEnabled(false);
 
-  connect(d->addButton,SIGNAL(clicked()), this, SLOT(addNode()));
-  connect(d->nodeTable,SIGNAL(cellActivated(int,int)), this, SLOT(updateState(int,int)));
-
 
+  QSettings settings;
+
+  QMap<QString, QVariant> node;
+  if ( settings.value("ServerNodeCount").toInt() == 0 )
+  {
+    node["Name"] = "localhost";
+    node["AETitle"] = "CTK_AE";
+    node["Address"] = "localhost";
+    node["Port"] = "11112";
+    settings.setValue("ServerNodeCount", 3);
+    settings.setValue("ServerNodes/0", QVariant(node));
+    settings.sync();
+  }
+
+  int count = settings.value("ServerNodeCount").toInt();
+  d->nodeTable->setRowCount(count);
+  for (int row = 0; row < count; row++)
+  {
+    node = settings.value(QString("ServerNodes/%1").arg(row)).toMap();
+    QTableWidgetItem *newItem;
+    newItem = new QTableWidgetItem( node["Name"].toString() );
+    d->nodeTable->setItem(row, 0, newItem);
+    newItem = new QTableWidgetItem( node["AETitle"].toString() );
+    d->nodeTable->setItem(row, 1, newItem);
+    newItem = new QTableWidgetItem( node["Address"].toString() );
+    d->nodeTable->setItem(row, 2, newItem);
+    newItem = new QTableWidgetItem( node["Port"].toString() );
+    d->nodeTable->setItem(row, 3, newItem);
+  }
+
+  connect(d->addButton
+    ,SIGNAL(clicked()),
+    this,
+    SLOT(addNode()));
+  connect(d->removeButton
+    ,SIGNAL(clicked()),
+    this,
+    SLOT(removeNode()));
+  connect(d->nodeTable,
+    SIGNAL(cellChanged(int,int)),
+    this,
+    SLOT(onCellChanged(int,int)));
+  connect(d->nodeTable,
+    SIGNAL(currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)),
+    this,
+    SLOT(onCurrentItemChanged(QTableWidgetItem*, QTableWidgetItem*)));
 }
 
 //----------------------------------------------------------------------------
@@ -79,19 +127,66 @@ ctkDICOMServerNodeWidget::~ctkDICOMServerNodeWidget()
 //----------------------------------------------------------------------------
 void ctkDICOMServerNodeWidget::addNode()
 {
-  //Q_D(ctkDICOMServerNodeWidget);
+  Q_D(ctkDICOMServerNodeWidget);
 
-  std::cerr << "add server node\n";
+  d->nodeTable->setRowCount( d->nodeTable->rowCount() + 1 );
 }
 
 //----------------------------------------------------------------------------
-void ctkDICOMServerNodeWidget::updateState(int row, int column)
+void ctkDICOMServerNodeWidget::removeNode()
+{
+  Q_D(ctkDICOMServerNodeWidget);
+
+  d->nodeTable->removeRow( d->nodeTable->currentRow() );
+  d->removeButton->setEnabled(false);
+  this->saveSettings();
+}
+
+//----------------------------------------------------------------------------
+void ctkDICOMServerNodeWidget::onCellChanged(int row, int column)
 {
   Q_UNUSED(row);
   Q_UNUSED(column);
+
+  this->saveSettings();
+}
+
+//----------------------------------------------------------------------------
+void ctkDICOMServerNodeWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem *previous)
+{
+  Q_UNUSED(current);
+  Q_UNUSED(previous);
+
+  Q_D(ctkDICOMServerNodeWidget);
+  if (d->nodeTable->rowCount() > 1)
+  {
+    d->removeButton->setEnabled(true);
+  }
+}
+
+//----------------------------------------------------------------------------
+void ctkDICOMServerNodeWidget::saveSettings()
+{
   Q_D(ctkDICOMServerNodeWidget);
 
-  d->removeButton->setEnabled(true);
+  QSettings settings;
+  QMap<QString, QVariant> node;
+  int count = d->nodeTable->rowCount();
+  QStringList keys;
+  keys << "Name" << "AETitle" << "Address" << "Port";
+  for (int row = 0; row < count; row++)
+  {
+    for (int k = 0; k < keys.size(); ++k)
+    {
+      if ( d->nodeTable->item(row,k) )
+      {
+        node[keys.at(k)] = d->nodeTable->item(row,k)->text();
+      }
+      settings.setValue(QString("ServerNodes/%1").arg(row), QVariant(node));
+    }
+  }
+  settings.setValue("ServerNodeCount", count);
+  settings.sync();
 }
 
 //----------------------------------------------------------------------------

+ 5 - 1
Libs/DICOM/Widgets/ctkDICOMServerNodeWidget.h

@@ -26,6 +26,7 @@
 
 #include "CTKDICOMWidgetsExport.h"
 
+class QTableWidgetItem;
 class ctkDICOMServerNodeWidgetPrivate;
 
 class CTK_DICOM_WIDGETS_EXPORT ctkDICOMServerNodeWidget : public QWidget
@@ -42,7 +43,10 @@ public:
 
 public slots:
   void addNode ();
-  void updateState (int row, int column);
+  void removeNode ();
+  void onCellChanged (int row, int column);
+  void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem *previous);
+  void saveSettings ();
 
 protected:
   QScopedPointer<ctkDICOMServerNodeWidgetPrivate> d_ptr;