]> Git trees. - libqmvoc.git/commitdiff
API changes on ExtDateWidget:
authorPino Toscano <pino@kde.org>
Sun, 18 Feb 2007 01:33:00 +0000 (01:33 +0000)
committerPino Toscano <pino@kde.org>
Sun, 18 Feb 2007 01:33:00 +0000 (01:33 +0000)
- 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
extdate/extdatewidget.h

index da7fa9fcb4d98ad13c64a9db79d9ca0fd337c7a1..465c847c8d831c3074ca5c1979e1316142e66f9e 100644 (file)
@@ -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"
index 485a361400787ac2bf4a230d45701aa3b23c7000..80803017b44146de35dd5d17d122db931106f8c5 100644 (file)
@@ -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