ctkDateRangeWidget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Isomics 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. #ifndef __ctkDateRangeWidget_h
  15. #define __ctkDateRangeWidget_h
  16. // Qt includes
  17. #include <QDateTimeEdit>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "ctkWidgetsExport.h"
  21. class ctkDateRangeWidgetPrivate;
  22. class QDateTime;
  23. ///
  24. /// ctkDateRangeWidget allows the user to select a time range between two
  25. /// dates
  26. class CTK_WIDGETS_EXPORT ctkDateRangeWidget : public QWidget
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY(QDateTime startDateTime READ startDateTime WRITE setStartDateTime NOTIFY startDateTimeChanged)
  30. Q_PROPERTY(QDateTime endDateTime READ endDateTime WRITE setEndDateTime NOTIFY endDateTimeChanged)
  31. Q_PROPERTY(bool displayTime READ displayTime WRITE setDisplayTime)
  32. public:
  33. /// Superclass typedef
  34. typedef QWidget Superclass;
  35. /// Constructor
  36. /// If \li parent is null, ctkDateRangeWidget will be a top-level widget
  37. /// \note The \li parent can be set later using QWidget::setParent()
  38. /// By default, the range is "Any Date"
  39. explicit ctkDateRangeWidget(QWidget* parent = 0);
  40. /// Destructor
  41. virtual ~ctkDateRangeWidget();
  42. ///
  43. /// This property holds whether the date range includes time
  44. /// If includeTime is disabled (the default), the widget only shows dates
  45. /// If includeTime is enabled the date widgets display time as well as date
  46. void setDisplayTime(bool includeTime);
  47. bool displayTime()const;
  48. /// Access the start date/times
  49. /// The returned date is never NULL/empty, but set to
  50. /// QDateTimeEdit::minimumDateTime
  51. QDateTime startDateTime() const;
  52. /// Access the start date/times
  53. /// The returned date is never NULL/empty, but set to
  54. /// QDateTimeEdit::maximumDateTime
  55. QDateTime endDateTime() const;
  56. /// Utility function that returns true if the range correspond to any date
  57. /// It can be useful if the time must be handled specially in that case.
  58. /// Returns true if any of the start or end date is invalid.
  59. bool isAnyDate()const;
  60. public slots:
  61. /// Set the start date.
  62. /// If the date is null or invalid, it will be automatically converted into
  63. /// a valid date (14 September 1752)
  64. void setStartDateTime(QDateTime start);
  65. /// Set the end date.
  66. /// If the date is null or invalid, it will be automatically converted into
  67. /// a valid date (31 December, 7999 and a time of 23:59:59 and 999 milliseconds)
  68. void setEndDateTime(QDateTime end);
  69. ///
  70. /// Utility function that set the start and end values at once
  71. void setDateTimeRange(QDateTime start, QDateTime end);
  72. void setDateRange(QDate start, QDate end);
  73. ///
  74. /// handle clicks on radio buttons
  75. void setAnyDate();
  76. void setToday();
  77. void setYesterday();
  78. void setLastWeek();
  79. void setLastMonth();
  80. void setSelectRange();
  81. signals:
  82. /// Fired when the start date is changed
  83. void startDateTimeChanged(const QDateTime& value);
  84. /// Fired when the end date is changed
  85. void endDateTimeChanged(const QDateTime& value);
  86. protected slots:
  87. void onDateTimeChanged();
  88. protected:
  89. QScopedPointer<ctkDateRangeWidgetPrivate> d_ptr;
  90. private:
  91. Q_DECLARE_PRIVATE(ctkDateRangeWidget);
  92. Q_DISABLE_COPY(ctkDateRangeWidget);
  93. };
  94. #endif