Skip to content

Commit

Permalink
Several changes:
Browse files Browse the repository at this point in the history
 - Fix issue #5846: keep and return created editor
 - Issue #5845: use std::chrono::milliseconds for WTimer
   WTimer is based on JavaScript's setTimeout functionality, and not on
   std::chrono::steady_clock, so std::chrono::milliseconds is the
   appropriate resolution.
  • Loading branch information
RockinRoel committed Aug 1, 2017
1 parent 4d55398 commit dd2aeba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/Wt/WItemDelegate.C
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ std::unique_ptr<WWidget> WItemDelegate::update(WWidget *widget, const WModelInde
{
bool editing = widget && widget->find("t") == nullptr;

WidgetRef widgetRef(widget);

if (flags.test(ViewItemRenderFlag::Editing)) {
if (!editing) {
widget = createEditor(index, flags).release();
widgetRef.created = createEditor(index, flags);
widgetRef.w = widgetRef.created.get();
WInteractWidget *iw = dynamic_cast<WInteractWidget *>(widget);
if (iw) {
// Disable drag & drop and selection behaviour
Expand All @@ -115,11 +118,9 @@ std::unique_ptr<WWidget> WItemDelegate::update(WWidget *widget, const WModelInde
}
} else {
if (editing)
widget = nullptr;
widgetRef.w = nullptr;
}

WidgetRef widgetRef(widget);

bool isNew = false;

bool haveCheckBox = index.isValid() ? !index.data(ItemDataRole::Checked).empty() : false;
Expand Down
14 changes: 7 additions & 7 deletions src/Wt/WTimer
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public:

/*! \brief Returns the interval
*/
std::chrono::steady_clock::duration interval() const { return interval_; }
std::chrono::milliseconds interval() const { return interval_; }

/*! \brief Sets the interval
*/
void setInterval(std::chrono::steady_clock::duration interval);
void setInterval(std::chrono::milliseconds interval);

/*! \brief Returns if the timer is running.
*/
Expand Down Expand Up @@ -114,15 +114,15 @@ public:
* \endcode
*/
template <class T, class V>
static void singleShot(std::chrono::steady_clock::duration interval, T *receiver, void (V::*method)());
static void singleShot(std::chrono::milliseconds interval, T *receiver, void (V::*method)());

/*! \brief This static function calls a function after a given time interval.
*
* This variant of the overloaded singleShot() method supports a
* template function object (which supports operator ()).
*/
template <class F>
static void singleShot(std::chrono::steady_clock::duration interval, const F& f);
static void singleShot(std::chrono::milliseconds interval, const F& f);
#endif // WT_TARGET_JAVA

/*! \brief Starts the timer.
Expand Down Expand Up @@ -153,7 +153,7 @@ private:
WTimerWidget *timerWidget_;

bool singleShot_;
std::chrono::steady_clock::duration interval_;
std::chrono::milliseconds interval_;
bool active_;
bool timeoutConnected_;

Expand All @@ -167,13 +167,13 @@ private:

#ifndef WT_TARGET_JAVA
template <class T, class V>
void WTimer::singleShot(std::chrono::steady_clock::duration interval, T *receiver, void (V::*method)())
void WTimer::singleShot(std::chrono::milliseconds interval, T *receiver, void (V::*method)())
{
singleShot(interval, std::bind(method, receiver));
}

template <class F>
void WTimer::singleShot(std::chrono::steady_clock::duration interval, const F& f)
void WTimer::singleShot(std::chrono::milliseconds interval, const F& f)
{
WTimer *timer = new WTimer();
timer->setSingleShot(true);
Expand Down
2 changes: 1 addition & 1 deletion src/Wt/WTimer.C
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ WTimer::~WTimer()
delete timerWidget_;
}

void WTimer::setInterval(std::chrono::steady_clock::duration msec)
void WTimer::setInterval(std::chrono::milliseconds msec)
{
interval_ = msec;
}
Expand Down

0 comments on commit dd2aeba

Please sign in to comment.