ctkDateRangeWidget.h 3.8 KB

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