[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] indicate read-only cells in CensusView [patch]
From: |
Vaclav Slavik |
Subject: |
[lmi] indicate read-only cells in CensusView [patch] |
Date: |
Sun, 15 Jan 2012 14:14:38 +0100 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 |
Hi,
below is a patch that significantly improves inline editing in
CensusView. Similarly to how the edit dialog disables controls for
fields that are not applicable, this patch grays out disabled cells and
makes them uneditable.
You can see a screenshot here: http://review.bakefile.org/r/380/s/35/
The wxDVC part of the patch is straightforward and simple:
--
diff --git a/census_view.cpp b/census_view.cpp
index 07f99b5..e98ac6c 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -52,6 +52,7 @@
#include <wx/icon.h>
#include <wx/menu.h>
#include <wx/msgdlg.h>
+#include <wx/settings.h>
#include <wx/spinctrl.h>
#include <wx/valnum.h>
#include <wx/wupdlock.h>
@@ -708,6 +709,8 @@ class CensusViewDataViewModel : public
wxDataViewIndexListModel
virtual void GetValueByRow(wxVariant& variant, unsigned int row, unsigned
int col) const;
virtual bool SetValueByRow(wxVariant const&, unsigned int, unsigned int);
+ virtual bool IsEnabledByRow(unsigned int row, unsigned int col) const;
+ virtual bool GetAttrByRow(unsigned row, unsigned col, wxDataViewItemAttr&
attr) const;
virtual unsigned int GetColumnCount() const;
@@ -762,6 +765,34 @@ bool CensusViewDataViewModel::SetValueByRow(wxVariant
const& variant, unsigned r
return true;
}
+bool CensusViewDataViewModel::IsEnabledByRow(unsigned int row, unsigned int
col) const
+{
+ if(col == Col_CellNum)
+ {
+ return false;
+ }
+ else
+ {
+ any_member<Input> const& value = cell_at(row, col);
+ return member_cast<datum_base>(value)->is_enabled();
+ }
+}
+
+bool CensusViewDataViewModel::GetAttrByRow(unsigned row, unsigned col,
wxDataViewItemAttr& attr) const
+{
+ if(!IsEnabledByRow(row, col))
+ {
+ // Indicate non-editable items with grayed out text.
+ static wxColour s_gray =
wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
+ attr.SetColour(s_gray);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
unsigned int CensusViewDataViewModel::GetColumnCount() const
{
return all_headers().size() + 1;
--
But this alone was not enough -- datum_base::is_enabled() kept returning
wrong values (allowing editing of fields that were disabled in the edit
dialog). I'm still mostly lost in the model code, so I'm far from sure
that I'm doing the correct thing here. But the way it looked to me, an
explicit harmonization step was needed after initially loading the
census or modifying it in any way (editing, adding or removing cells).
The only public method that I could call on cell_parms() was
Reconcile(), but that didn't sound right to me -- it could modify the
data, couldn't it? So I decided to make Harmonize() public and call it
from CensusView::Update():
--
diff --git a/census_view.cpp b/census_view.cpp
index 07f99b5..e98ac6c 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -1403,6 +1434,15 @@ void CensusView::Update()
update_class_names();
update_visible_columns();
+ for
+ (std::vector<Input>::iterator i = cell_parms().begin()
+ ;i != cell_parms().end()
+ ;++i
+ )
+ {
+ i->Harmonize();
+ }
+
// All displayed data is valid when this function ends.
all_changes_have_been_validated_ = true;
}
diff --git a/mvc_model.hpp b/mvc_model.hpp
index 837e6ee..b074a3d 100644
--- a/mvc_model.hpp
+++ b/mvc_model.hpp
@@ -135,13 +135,13 @@ class LMI_SO MvcModel
void Reconcile();
void TestInitialConsistency();
+ void Harmonize();
private:
void AdaptExternalities();
void CustomizeInitialValues();
void EnforceCircumscription(std::string const&);
void EnforceProscription (std::string const&);
- void Harmonize();
void Transmogrify();
virtual datum_base const* DoBaseDatumPointer(std::string const&) const = 0;
--
Once again, I'm not familiar with this code and this was the best I
could figure out. I have this nagging feeling that this could be done in
a better way and that I am missing something. That's why I present this
part of the patch separately -- as far as the upper part is concerned,
all that matters is that is_enabled() always returns correct value for
all cells visible on the screen.
Regards,
Vaclav
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi] indicate read-only cells in CensusView [patch],
Vaclav Slavik <=