[Kstars-devel] kdeedu/libkdeedu/extdate
Jason Harris
kstars at 30doradus.org
Tue Jun 1 03:33:19 CEST 2004
CVS commit by harris:
Fixing crash condition in ExtDateWidget. If initialized without a date
argument, it was initialized to an invalid date, which caused a crash in the
function ExtDate::daysInMonth(). Two fixes make the widget much more robust:
+ ExtDate::daysInMonth() and ExtDate::leapYear() now check the validity of the
date first, and return sensible default values if the date is invalid.
+ the default ctor ExtDateWidget() now initializes to the current date, rather
than an invalid date.
This fixes the crash in the ScriptBuilder tool.
CCMAIL: kstars-devel at kde.org
M +9 -2 extdatetime.cpp 1.7
M +1 -1 extdatewidget.cpp 1.4
M +2 -2 extdatewidget.h 1.3
M +7 -0 testwidget.cpp 1.3
M +4 -0 testwidget.h 1.2
--- kdeedu/libkdeedu/extdate/extdatetime.cpp #1.6:1.7
@@ -291,10 +291,17 @@ int ExtDate::dayOfYear() const
int ExtDate::daysInMonth() const
{
- int a_month = month();
- return (a_month == 2) ? (leapYear(year()) ? 29 : 28) : m_monthLength[a_month-1] ;
+ if ( isValid() ) {
+ int m = month();
+ int d = m_monthLength[m-1];
+ if (m==2 && leapYear(year())) d++;
+ return d;
+ } else {
+ return 31;
+ }
}
int ExtDate::daysInYear() const
{
+ if ( ! isValid() ) return 365;
return (leapYear(year()) ? 366 : 365);
}
--- kdeedu/libkdeedu/extdate/extdatewidget.cpp #1.3:1.4
@@ -57,5 +57,5 @@ ExtDateWidget::ExtDateWidget( QWidget *p
: QWidget( parent, name )
{
- init(ExtDate());
+ init(ExtDate::currentDate());
setDate(ExtDate());
}
--- kdeedu/libkdeedu/extdate/extdatewidget.h #1.2:1.3
@@ -40,5 +40,5 @@ class ExtDateWidget : public QWidget
public:
/**
- * Constructs a date selection widget.
+ * Constructs a date selection widget, initialized to the current CPU date.
*/
ExtDateWidget( QWidget *parent=0, const char *name=0 );
--- kdeedu/libkdeedu/extdate/testwidget.cpp #1.2:1.3
@@ -1,3 +1,4 @@
#include <kdatepicker.h>
+#include <kdatewidget.h>
#include <klineedit.h>
#include <qlayout.h>
@@ -5,4 +6,5 @@
#include "extdatepicker.h"
+#include "extdatewidget.h"
#include "testwidget.h"
@@ -21,4 +23,7 @@ TestWidget::TestWidget( QWidget *p=0, co
edpEdit->setReadOnly( TRUE );
+ kdw = new KDateWidget( QDate::currentDate(), w );
+ edw = new ExtDateWidget( ExtDate::currentDate(), w );
+
glay->addWidget( kdpLabel, 0, 0 );
glay->addWidget( edpLabel, 0, 1 );
@@ -27,4 +32,6 @@ TestWidget::TestWidget( QWidget *p=0, co
glay->addWidget( kdpEdit, 2, 0 );
glay->addWidget( edpEdit, 2, 1 );
+ glay->addWidget( kdw, 3, 0 );
+ glay->addWidget( edw, 3, 1 );
setCentralWidget(w);
--- kdeedu/libkdeedu/extdate/testwidget.h #1.1:1.2
@@ -6,5 +6,7 @@
class KDatePicker;
class KLineEdit;
+class KDateWidget;
class ExtDatePicker;
+class ExtDateWidget;
class QGridLayout;
class QDate;
@@ -25,4 +27,6 @@ class TestWidget : public KMainWindow {
KDatePicker *kdp;
ExtDatePicker *edp;
+ ExtDateWidget *edw;
+ KDateWidget *kdw;
KLineEdit *kdpEdit, *edpEdit;
};
More information about the Kstars-devel
mailing list