Skip to content

Commit 1b3b114

Browse files
committed
Several changes:
- Adding some missing documentation to WButtonGroup, 0 -> nullptr It was not specified that WButtonGroup::button(int) returns null if the button is not found Wt 4 uses C++11, so let's refer to a null pointer as nullptr. - Eliminated dubious std::unique_ptr<...>(this) in ColumnWidget constructor clang-analyzer was warning about a possible memory leak after calls to new ColumnWidget(...). It shouldn't normally leak, since the newly created ColumnWidget* is actually put into a unique_ptr and then moved into either table_ or headerColumnsTable_, but std::unique_ptr<WWidget> self(this) is a rather dubious hack. We can do this in a nicer (safer, more guaranteed to be defined behaviour) way.
1 parent 28a126b commit 1b3b114

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

src/Wt/WButtonGroup.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class WT_API WButtonGroup : public WObject
101101
void removeButton(WRadioButton *button);
102102

103103
/*! \brief Returns the button for the given id.
104+
*
105+
* Returns \c nullptr if no button exists for the given id.
104106
*
105107
* \sa id(), addButton()
106108
*/
@@ -143,7 +145,7 @@ class WT_API WButtonGroup : public WObject
143145
/*! \brief Returns the checked radiobutton.
144146
*
145147
* If there is no radiobutton currently checked this function
146-
* returns \c 0.
148+
* returns \c nullptr.
147149
*
148150
* \sa setCheckedButton(), selectedButtonIndex()
149151
*/

src/Wt/WTableView.C

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void WTableView::addSection(const Side side)
490490
setSpannerCount(side, spannerCount(side) - 1);
491491
break;
492492
case Side::Left: {
493-
ColumnWidget *w = new ColumnWidget(this, firstColumn() - 1);
493+
ColumnWidget *w = createColumnWidget(firstColumn() - 1);
494494

495495
if (!columnInfo(w->column()).hidden)
496496
table_->setOffsets(table_->offset(Side::Left).toPixels()
@@ -502,7 +502,7 @@ void WTableView::addSection(const Side side)
502502
break;
503503
}
504504
case Side::Right: {
505-
ColumnWidget *w = new ColumnWidget(this, lastColumn() + 1);
505+
ColumnWidget *w = createColumnWidget(lastColumn() + 1);
506506

507507
if (columnInfo(w->column()).hidden)
508508
w->hide();
@@ -782,7 +782,7 @@ void WTableView::reset()
782782
headerColumnsTable_->clear();
783783

784784
for (int i = 0; i < rowHeaderCount(); ++i)
785-
new ColumnWidget(this, i);
785+
createColumnWidget(i);
786786
}
787787

788788
void WTableView::defineJavaScript()
@@ -1144,30 +1144,36 @@ bool WTableView::isColumnRendered(const int column) const
11441144
return column >= firstColumn() && column <= lastColumn();
11451145
}
11461146

1147-
WTableView::ColumnWidget::ColumnWidget(WTableView *view, int column)
1148-
: column_(column)
1147+
WTableView::ColumnWidget *WTableView::createColumnWidget(int column)
11491148
{
1150-
assert(view->ajaxMode());
1149+
assert(ajaxMode());
11511150

1152-
WTableView::ColumnInfo& ci = view->columnInfo(column);
1153-
setStyleClass(ci.styleClass());
1154-
setPositionScheme(PositionScheme::Absolute);
1155-
setOffsets(0, Side::Top | Side::Left);
1156-
setOverflow(Overflow::Hidden);
1157-
setHeight(view->table_->height());
1151+
ColumnWidget *result = new ColumnWidget(column);
1152+
std::unique_ptr<ColumnWidget> columnWidget(result);
11581153

1159-
std::unique_ptr<WWidget> self(this);
1154+
WTableView::ColumnInfo& ci = columnInfo(column);
1155+
columnWidget->setStyleClass(ci.styleClass());
1156+
columnWidget->setPositionScheme(PositionScheme::Absolute);
1157+
columnWidget->setOffsets(0, Side::Top | Side::Left);
1158+
columnWidget->setOverflow(Overflow::Hidden);
1159+
columnWidget->setHeight(table_->height());
11601160

1161-
if (column >= view->rowHeaderCount()) {
1162-
if (view->table_->count() == 0
1163-
|| column > view->columnContainer(-1)->column())
1164-
view->table_->addWidget(std::move(self));
1161+
if (column >= rowHeaderCount()) {
1162+
if (table_->count() == 0
1163+
|| column > columnContainer(-1)->column())
1164+
table_->addWidget(std::move(columnWidget));
11651165
else
1166-
view->table_->insertWidget(0, std::move(self));
1166+
table_->insertWidget(0, std::move(columnWidget));
11671167
} else
1168-
view->headerColumnsTable_->insertWidget(column, std::move(self));
1168+
headerColumnsTable_->insertWidget(column, std::move(columnWidget));
1169+
1170+
return result;
11691171
}
11701172

1173+
WTableView::ColumnWidget::ColumnWidget(int column)
1174+
: column_(column)
1175+
{ }
1176+
11711177
WTableView::ColumnWidget *WTableView::columnContainer(int renderedColumn) const
11721178
{
11731179
assert(ajaxMode());

src/Wt/WTableView.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,21 @@ class WT_API WTableView : public WAbstractItemView
174174
virtual void enableAjax() override;
175175

176176
private:
177+
class ColumnWidget;
178+
179+
ColumnWidget *createColumnWidget(int column);
180+
177181
class ColumnWidget : public WContainerWidget
178182
{
179183
public:
180-
ColumnWidget(WTableView *view, int column);
181184
int column() const { return column_; }
182185

183186
private:
187+
ColumnWidget(int column);
188+
184189
int column_;
190+
191+
friend ColumnWidget *WTableView::createColumnWidget(int column);
185192
};
186193

187194
/* For Ajax implementation */

0 commit comments

Comments
 (0)