Explorar el Código

Factor the date selection to ctkDateRangeWidget

Since the selection of a start and end date seems like a generic
operation with a bit of logic, factor it out of the dicom widgets
and put it into the general purpose ctk widgets
Steve Pieper hace 14 años
padre
commit
890a951f35

+ 43 - 121
Libs/DICOM/Widgets/Resources/UI/ctkDICOMQueryWidget.ui

@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>566</width>
-    <height>339</height>
+    <height>294</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -19,7 +19,7 @@
      <item>
       <widget class="QTabWidget" name="queryoptions">
        <property name="sizePolicy">
-        <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
+        <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
@@ -27,53 +27,64 @@
        <property name="maximumSize">
         <size>
          <width>16777215</width>
-         <height>25</height>
+         <height>16777215</height>
         </size>
        </property>
        <property name="currentIndex">
-        <number>2</number>
+        <number>0</number>
        </property>
+       <widget class="QWidget" name="Any">
+        <attribute name="title">
+         <string>Any</string>
+        </attribute>
+        <layout class="QVBoxLayout" name="verticalLayout_6">
+         <item>
+          <widget class="QLineEdit" name="AnySearch"/>
+         </item>
+        </layout>
+       </widget>
        <widget class="QWidget" name="Name">
         <attribute name="title">
          <string>Name</string>
         </attribute>
+        <layout class="QVBoxLayout" name="verticalLayout_7">
+         <item>
+          <widget class="QLineEdit" name="NameSearch"/>
+         </item>
+        </layout>
        </widget>
        <widget class="QWidget" name="Tag">
         <attribute name="title">
          <string>Tag</string>
         </attribute>
+        <layout class="QVBoxLayout" name="verticalLayout_8">
+         <item>
+          <widget class="QLineEdit" name="TagSearch"/>
+         </item>
+        </layout>
        </widget>
        <widget class="QWidget" name="ID">
         <attribute name="title">
          <string>ID</string>
         </attribute>
+        <layout class="QVBoxLayout" name="verticalLayout_9">
+         <item>
+          <widget class="QLineEdit" name="IDSearch"/>
+         </item>
+        </layout>
        </widget>
        <widget class="QWidget" name="Number">
         <attribute name="title">
          <string>Number</string>
         </attribute>
-       </widget>
-       <widget class="QWidget" name="Any">
-        <attribute name="title">
-         <string>Any</string>
-        </attribute>
+        <layout class="QVBoxLayout" name="verticalLayout_10">
+         <item>
+          <widget class="QLineEdit" name="NumberSearch"/>
+         </item>
+        </layout>
        </widget>
       </widget>
      </item>
-     <item>
-      <layout class="QHBoxLayout" name="horizontalLayout">
-       <item>
-        <widget class="QLineEdit" name="lineEdit"/>
-       </item>
-       <item>
-        <widget class="QPushButton" name="pushButton">
-         <property name="text">
-          <string>Search</string>
-         </property>
-        </widget>
-       </item>
-      </layout>
-     </item>
     </layout>
    </item>
    <item>
@@ -95,104 +106,7 @@
         </property>
         <layout class="QHBoxLayout" name="horizontalLayout_3">
          <item>
-          <widget class="QFrame" name="frame_4">
-           <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="QRadioButton" name="radioButton">
-              <property name="text">
-               <string>Any Date</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QRadioButton" name="radioButton_3">
-              <property name="text">
-               <string>Today</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QRadioButton" name="radioButton_2">
-              <property name="text">
-               <string>Yesterday</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QRadioButton" name="radioButton_6">
-              <property name="text">
-               <string>Last Week</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QRadioButton" name="radioButton_7">
-              <property name="text">
-               <string>Last Month</string>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </widget>
-         </item>
-         <item>
-          <widget class="QFrame" name="frame_5">
-           <property name="frameShape">
-            <enum>QFrame::StyledPanel</enum>
-           </property>
-           <property name="frameShadow">
-            <enum>QFrame::Raised</enum>
-           </property>
-           <layout class="QVBoxLayout" name="verticalLayout_4">
-            <item>
-             <widget class="QRadioButton" name="radioButton_5">
-              <property name="text">
-               <string>Between</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <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">
-              <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>
+          <widget class="ctkDateRangeWidget" name="widget" native="true"/>
          </item>
         </layout>
        </widget>
@@ -241,6 +155,14 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkDateRangeWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkdaterangewidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>

+ 4 - 0
Libs/Widgets/CMakeLists.txt

@@ -95,6 +95,8 @@ SET(KIT_SRCS
   ctkWorkflowWidget.h
   ctkWorkflowWidgetStep.cpp
   ctkWorkflowWidgetStep.h
+  ctkDateRangeWidget.cpp
+  ctkDateRangeWidget.h
   )
 
 # Headers that should run through moc
@@ -139,12 +141,14 @@ SET(KIT_MOC_SRCS
   ctkWorkflowTabWidget.h
   ctkWorkflowWidget.h
   ctkWorkflowWidgetStep.h
+  ctkDateRangeWidget.h
   )
 
 # UI files
 SET(KIT_UI_FORMS
   Resources/UI/ctkAddRemoveComboBox.ui
   Resources/UI/ctkRangeWidget.ui
+  Resources/UI/ctkDateRangeWidget.ui
   Resources/UI/ctkSliderWidget.ui
   Resources/UI/ctkWorkflowGroupBox.ui
   )

+ 124 - 0
Libs/Widgets/Resources/UI/ctkDateRangeWidget.ui

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkDateRangeWidget</class>
+ <widget class="QWidget" name="ctkDateRangeWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>207</width>
+    <height>233</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>ctkSliderSpinBoxWidget</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QFrame" name="frame_4">
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Raised</enum>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <widget class="QRadioButton" name="AnyDate">
+        <property name="text">
+         <string>Any Date</string>
+        </property>
+        <property name="checked">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="Today">
+        <property name="text">
+         <string>Today</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="Yesterday">
+        <property name="text">
+         <string>Yesterday</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="LastWeek">
+        <property name="text">
+         <string>Last Week</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="LastMonth">
+        <property name="text">
+         <string>Last Month</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="SelectRange">
+        <property name="text">
+         <string>Select Range</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QDateTimeEdit" name="StartDate">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+        <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="EndDate">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+        <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>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 179 - 0
Libs/Widgets/ctkDateRangeWidget.cpp

@@ -0,0 +1,179 @@
+/*=========================================================================
+
+  Library:   CTK
+ 
+  Copyright (c) 2010  Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  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.
+ 
+=========================================================================*/
+
+// Qt includes
+#include <QDebug>
+#include <QDate>
+#include <QDateTime>
+#include <QDateTimeEdit>
+
+// CTK includes
+#include "ctkDateRangeWidget.h"
+#include "ui_ctkDateRangeWidget.h"
+#include "ctkLogger.h"
+
+static ctkLogger logger("org.commontk.libs.widgets.ctkDateRangeWidget");
+
+//-----------------------------------------------------------------------------
+class ctkDateRangeWidgetPrivate: public Ui_ctkDateRangeWidget
+{
+  Q_DECLARE_PUBLIC(ctkDateRangeWidget);
+protected:
+  ctkDateRangeWidget* const q_ptr;
+public:
+  ctkDateRangeWidgetPrivate(ctkDateRangeWidget& object);
+
+  bool          includeTime;
+};
+
+
+// --------------------------------------------------------------------------
+ctkDateRangeWidgetPrivate::ctkDateRangeWidgetPrivate(ctkDateRangeWidget& object)
+  :q_ptr(&object)
+{
+  this->includeTime = false;
+}
+
+// --------------------------------------------------------------------------
+ctkDateRangeWidget::ctkDateRangeWidget(QWidget* _parent) : Superclass(_parent)
+  , d_ptr(new ctkDateRangeWidgetPrivate(*this))
+{
+  Q_D(ctkDateRangeWidget);
+  
+  d->setupUi(this);
+
+  QObject::connect(d->AnyDate, SIGNAL(clicked()),this, SLOT(onAnyDate()));
+  QObject::connect(d->Today, SIGNAL(clicked()),this, SLOT(onToday()));
+  QObject::connect(d->Yesterday, SIGNAL(clicked()),this, SLOT(onYesterday()));
+  QObject::connect(d->LastWeek, SIGNAL(clicked()),this, SLOT(onLastWeek()));
+  QObject::connect(d->LastMonth, SIGNAL(clicked()),this, SLOT(onLastMonth()));
+  //QObject::connect(d->SelectRange, SIGNAL(clicked()),this, SLOT(onSelectRange()));
+}
+
+// --------------------------------------------------------------------------
+ctkDateRangeWidget::~ctkDateRangeWidget()
+{
+}
+
+
+// --------------------------------------------------------------------------
+QDateTime ctkDateRangeWidget::startDateTime()const
+{
+  Q_D(const ctkDateRangeWidget);
+  return d->StartDate->dateTime();
+}
+
+// --------------------------------------------------------------------------
+QDateTime ctkDateRangeWidget::endDateTime()const
+{
+  Q_D(const ctkDateRangeWidget);
+  return d->EndDate->dateTime();
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::setStartDateTime(QDateTime dateTime)
+{
+  Q_D(const ctkDateRangeWidget);
+  return d->StartDate->setDateTime(dateTime);
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::setEndDateTime(QDateTime dateTime)
+{
+  Q_D(const ctkDateRangeWidget);
+  return d->EndDate->setDateTime(dateTime);
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::setDateTimeRange(QDateTime startDateTime, QDateTime endDateTime)
+{
+  Q_D(const ctkDateRangeWidget);
+  return d->StartDate->setDateTime(startDateTime);
+  return d->EndDate->setDateTime(endDateTime);
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::onAnyDate()
+{
+  Q_D(const ctkDateRangeWidget);
+  logger.info("selected AnyDate");
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::onToday()
+{
+  Q_D(const ctkDateRangeWidget);
+  logger.info("selected Today");
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::onYesterday()
+{
+  Q_D(const ctkDateRangeWidget);
+  logger.info("selected Yesterday");
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::onLastWeek()
+{
+  Q_D(const ctkDateRangeWidget);
+  logger.info("selected LastWeek");
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::onLastMonth()
+{
+  Q_D(const ctkDateRangeWidget);
+  logger.info("selected LastMonth");
+}
+
+// --------------------------------------------------------------------------
+void ctkDateRangeWidget::onSelectRange()
+{
+  Q_D(const ctkDateRangeWidget);
+  logger.info("selected SelectRange");
+}
+
+
+// -------------------------------------------------------------------------
+void ctkDateRangeWidget::setIncludeTime(bool includeTime)
+{
+  Q_D(ctkDateRangeWidget);
+  d->includeTime = includeTime;
+  if ( includeTime )
+  {
+    // TODO: set time format 
+    d->StartDate->setDisplayFormat( QString( "MMM dd, yyyy") );
+    d->EndDate->setDisplayFormat( QString( "MMM dd, yyyy") );
+  } 
+  else 
+  {
+    d->StartDate->setDisplayFormat( QString( "MMM dd, yyyy") );
+    d->EndDate->setDisplayFormat( QString( "MMM dd, yyyy") );
+  }
+}
+
+// -------------------------------------------------------------------------
+bool ctkDateRangeWidget::includeTime()const
+{
+  Q_D(const ctkDateRangeWidget);
+  return d->includeTime;
+}
+

+ 110 - 0
Libs/Widgets/ctkDateRangeWidget.h

@@ -0,0 +1,110 @@
+/*=========================================================================
+
+  Library:   CTK
+ 
+  Copyright (c) 2010  Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  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.
+ 
+=========================================================================*/
+
+#ifndef __ctkDateRangeWidget_h
+#define __ctkDateRangeWidget_h
+
+// Qt includes
+#include <QDateTimeEdit>
+
+// CTK includes
+#include <ctkPimpl.h>
+
+#include "CTKWidgetsExport.h"
+
+class ctkDateRangeWidgetPrivate;
+class QDateTime;
+
+///
+/// ctkDateRangeWidget is a wrapper around a ctkDoubleRangeSlider and 2 QSpinBoxes
+/// \image html http://www.commontk.org/images/1/14/CtkDateRangeWidget.png
+/// \sa ctkSliderSpinBoxWidget, ctkDoubleRangeSlider, QSpinBox
+class CTK_WIDGETS_EXPORT ctkDateRangeWidget : public QWidget
+{
+  Q_OBJECT
+    // placeholder - not yet used
+  Q_PROPERTY(bool includeTime READ includeTime WRITE setIncludeTime)
+
+public:
+  /// Superclass typedef
+  typedef QWidget Superclass;
+
+  /// Constructor
+  /// If \li parent is null, ctkDateRangeWidget will be a top-leve widget
+  /// \note The \li parent can be set later using QWidget::setParent()
+  explicit ctkDateRangeWidget(QWidget* parent = 0);
+  
+  /// Destructor
+  virtual ~ctkDateRangeWidget();
+
+  ///
+  /// This property holds whether the date range includes time
+  /// If tracking is disabled (the default), the widget only shows dates
+  /// If includeTime is enabled the date widgets display time as well as date
+  void setIncludeTime(bool includeTime);
+  bool includeTime()const;
+
+  ///
+  /// Access the start and end date/times
+  QDateTime startDateTime() const;
+  QDateTime endDateTime() const;
+
+public slots:
+  ///
+  /// Reset the slider and spinbox to zero (value and position)
+  void setStartDateTime(QDateTime start);
+  void setEndDateTime(QDateTime end);
+  ///
+  /// Utility function that set the start and end values at once
+  void setDateTimeRange(QDateTime start, QDateTime end);
+
+  ///
+  /// handle clicks on radio buttons
+  void onAnyDate();
+  void onToday();
+  void onYesterday();
+  void onLastWeek();
+  void onLastMonth();
+  void onSelectRange();
+
+signals:
+  /// 
+  /// signals
+  void startDateTimeChanged(QDateTime value);
+  void endDateTimeChanged(QDateTime value);
+
+protected slots:
+  ///
+  /// None
+
+protected:
+  ///
+  /// None
+
+protected:
+  QScopedPointer<ctkDateRangeWidgetPrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkDateRangeWidget);
+  Q_DISABLE_COPY(ctkDateRangeWidget);
+
+};
+
+#endif