[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d39ff1d 07/46: Use wxGridCellAttrPtr instead
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d39ff1d 07/46: Use wxGridCellAttrPtr instead of manual reference counting |
Date: |
Wed, 22 Jul 2020 11:05:09 -0400 (EDT) |
branch: master
commit d39ff1d5491c8f31b59df825c80dec5e2ca9069b
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Vadim Zeitlin <vadim@tt-solutions.com>
Use wxGridCellAttrPtr instead of manual reference counting
Update CensusViewGridCellAttrProvider::GetAttr() to use smart pointer
class instead of manual IncRef() and DecRef() calls, this is shorter and
less error-prone.
Also add a comment explaining why do we need to clone the attribute
returned by the base class in the first place.
---
census_view.cpp | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/census_view.cpp b/census_view.cpp
index a6cdf04..fbbd2ed 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -1566,22 +1566,23 @@ class CensusViewGridCellAttrProvider
,wxGridCellAttr::wxAttrKind kind
) const override
{
- wxGridCellAttr* attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
+ wxGridCellAttrPtr attr{wxGridCellAttrProvider::GetAttr(row, col,
kind)};
if(row % 2)
{
- if(attr == nullptr)
+ if(!attr)
{
- attr = attrForOddRows_.get();
- attr->IncRef();
+ attr = attrForOddRows_;
}
else
{
if(!attr->HasBackgroundColour())
{
- wxGridCellAttr* attrNew = attr->Clone();
- attr->DecRef();
- attr = attrNew;
+ // Note that we can't modify attr itself, as it can be used
+ // for other cells and changing its background would change
+ // their appearance, so allocate a new attribute for this
+ // cell only.
+ attr = attr->Clone();
attr->SetBackgroundColour
(attrForOddRows_->GetBackgroundColour()
);
@@ -1589,11 +1590,11 @@ class CensusViewGridCellAttrProvider
}
}
- return attr;
+ return attr.release();
}
private:
- wxObjectDataPtr<wxGridCellAttr> attrForOddRows_;
+ wxGridCellAttrPtr attrForOddRows_;
};
/// Interface to the data for wxGrid.
- [lmi-commits] [lmi] master 2922db9 44/46: Disallow single cell operations when non-current row is selected, (continued)
- [lmi-commits] [lmi] master 2922db9 44/46: Disallow single cell operations when non-current row is selected, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master d337a22 45/46: Upgrade wx, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master c679655 19/46: Replace table_type_converter::get_all() with register_all(), Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 7dc508e 35/46: Don't select the first row initially in the grid census view, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 810de0a 26/46: Remove unnecessary wxGrid::IsCellEditControlEnabled() calls, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master adc4089 28/46: Optimize changing grid dimensions when pasting into the census, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master be4c2a4 32/46: Add a comment explaining why the first column is read-only, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b7944ba 38/46: Resize only columns, not rows, in update_visible_columns(), Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b399a7d 40/46: Remove automatic column auto-sizing in wxGrid-based census view, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master d4ad57b 42/46: Disallow "Edit/Run" cell when multiple grid rows are selected, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master d39ff1d 07/46: Use wxGridCellAttrPtr instead of manual reference counting,
Greg Chicares <=