From 48376d9bc74e9a0213fd0af6925702da7e11c74b Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 18 Feb 2007 01:33:00 +0000 Subject: [PATCH] API changes on ExtDateWidget: - move the private slot to the private class - remove virtual_hook, not needed in QObject-derived classes - signals -> Q_SIGNALS in public API - const-ify the d-pointer - remove old code svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=634706 --- extdate/extdatewidget.cpp | 80 +++++++++++++++------------------------ extdate/extdatewidget.h | 18 ++++----- 2 files changed, 38 insertions(+), 60 deletions(-) diff --git a/extdate/extdatewidget.cpp b/extdate/extdatewidget.cpp index da7fa9f..465c847 100644 --- a/extdate/extdatewidget.cpp +++ b/extdate/extdatewidget.cpp @@ -48,8 +48,20 @@ public: class ExtDateWidget::ExtDateWidgetPrivate { public: - ExtDateWidgetPrivate() { calendar = new ExtCalendarSystemGregorian(); } - ~ExtDateWidgetPrivate() { delete calendar; } + ExtDateWidgetPrivate(ExtDateWidget *qq) + : q( qq ), calendar( new ExtCalendarSystemGregorian() ) + { + } + + ~ExtDateWidgetPrivate() + { + delete calendar; + } + + // slots + void dateChanged(); + + ExtDateWidget *q; ExtDateWidgetSpinBox *m_day; QComboBox *m_month; ExtDateWidgetSpinBox *m_year; @@ -59,48 +71,21 @@ public: ExtDateWidget::ExtDateWidget( QWidget *parent ) - : QWidget( parent ) + : QWidget( parent ), d(new ExtDateWidgetPrivate(this)) { init(ExtDate::currentDate()); setDate(ExtDate()); } ExtDateWidget::ExtDateWidget( const ExtDate &date, QWidget *parent ) - : QWidget( parent ) + : QWidget( parent ), d(new ExtDateWidgetPrivate(this)) { init(date); setDate(date); } -// // ### CFM Repaced by init(const ExtDate&). Can be safely removed -// // when no risk of BIC -// void ExtDateWidget::init() -// { -// d = new ExtDateWidgetPrivate; -// KLocale *locale = KGlobal::locale(); -// QHBoxLayout *layout = new QHBoxLayout(this, 0, KDialog::spacingHint()); -// layout->setAutoAdd(true); -// d->m_day = new ExtDateWidgetSpinBox(1, 1, this); -// d->m_month = new QComboBox(false, this); -// for (int i = 1; ; ++i) -// { -// QString str = d->calendar->monthName(i, -// d->calendar->year(ExtDate())); -// if (str.isNull()) break; -// d->m_month->insertItem(str); -// } -// -// d->m_year = new ExtDateWidgetSpinBox(d->calendar->minValidYear(), -// d->calendar->maxValidYear(), this); -// -// connect(d->m_day, SIGNAL(valueChanged(int)), this, SLOT(slotDateChanged())); -// connect(d->m_month, SIGNAL(activated(int)), this, SLOT(slotDateChanged())); -// connect(d->m_year, SIGNAL(valueChanged(int)), this, SLOT(slotDateChanged())); -// } - void ExtDateWidget::init(const ExtDate& date) { - d = new ExtDateWidgetPrivate; //KLocale *locale = KGlobal::locale(); QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(0); @@ -122,14 +107,14 @@ void ExtDateWidget::init(const ExtDate& date) d->calendar->maxValidYear(), this); layout->addWidget(d->m_year); - connect(d->m_day, SIGNAL(valueChanged(int)), this, SLOT(slotDateChanged())); - connect(d->m_month, SIGNAL(activated(int)), this, SLOT(slotDateChanged())); - connect(d->m_year, SIGNAL(valueChanged(int)), this, SLOT(slotDateChanged())); + connect(d->m_day, SIGNAL(valueChanged(int)), this, SLOT(dateChanged())); + connect(d->m_month, SIGNAL(activated(int)), this, SLOT(dateChanged())); + connect(d->m_year, SIGNAL(valueChanged(int)), this, SLOT(dateChanged())); } ExtDateWidget::~ExtDateWidget() { - delete d; + delete d; } void ExtDateWidget::setDate( const ExtDate &date ) @@ -158,29 +143,26 @@ ExtDate ExtDateWidget::date() const return d->m_dat; } -void ExtDateWidget::slotDateChanged( ) +void ExtDateWidget::ExtDateWidgetPrivate::dateChanged() { // const KCalendarSystem * calendar = KGlobal::locale()->calendar(); ExtDate date; int y,m,day; - y = d->m_year->value(); - y = qMin(qMax(y, d->calendar->minValidYear()), d->calendar->maxValidYear()); + y = m_year->value(); + y = qMin(qMax(y, calendar->minValidYear()), calendar->maxValidYear()); - d->calendar->setYMD(date, y, 1, 1); - m = d->m_month->currentIndex()+1; - m = qMin(qMax(m,1), d->calendar->monthsInYear(date)); + calendar->setYMD(date, y, 1, 1); + m = m_month->currentIndex()+1; + m = qMin(qMax(m,1), calendar->monthsInYear(date)); - d->calendar->setYMD(date, y, m, 1); - day = d->m_day->value(); - day = qMin(qMax(day,1), d->calendar->daysInMonth(date)); + calendar->setYMD(date, y, m, 1); + day = m_day->value(); + day = qMin(qMax(day,1), calendar->daysInMonth(date)); - d->calendar->setYMD(date, y, m, day); - setDate(date); + calendar->setYMD(date, y, m, day); + q->setDate(date); } -void ExtDateWidget::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - #include "extdatewidget.moc" diff --git a/extdate/extdatewidget.h b/extdate/extdatewidget.h index 485a361..8080301 100644 --- a/extdate/extdatewidget.h +++ b/extdate/extdatewidget.h @@ -43,12 +43,12 @@ public: /** * Constructs a date selection widget, initialized to the current CPU date. */ - ExtDateWidget( QWidget *parent=0 ); + explicit ExtDateWidget( QWidget *parent=0 ); /** * Constructs a date selection widget with the initial date set to @p date. */ - ExtDateWidget( const ExtDate &date, QWidget *parent=0 ); + explicit ExtDateWidget( const ExtDate &date, QWidget *parent=0 ); /** * Destructs the date selection widget. @@ -66,25 +66,21 @@ public: void setDate(const ExtDate &date); -signals: +Q_SIGNALS: /** * Emitted whenever the date of the widget * is changed, either with setDate() or via user selection. */ - void changed(ExtDate); + void changed(const ExtDate&); protected: - void init(); void init(const ExtDate&); -protected slots: - void slotDateChanged(); - -protected: - virtual void virtual_hook( int id, void* data ); private: class ExtDateWidgetPrivate; - ExtDateWidgetPrivate *d; + ExtDateWidgetPrivate * const d; + + Q_PRIVATE_SLOT(d, void dateChanged()) }; #endif -- 2.47.3