Added classes to manage simple tabular data of known structure using a

popup containing a wxGrid object.

BasePicker : Abstract class adding a popup to wxPickerBase  styled with
a wxTextCtrl.
BaseGridPicker : Abstract class adding a wxGrid in the popup.

JsonGridPickerCtrl : UI control storing the tabular data in a JSON
array.
LBoundJsonGridPicker : connect JsonGridPicker to database.
LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects.
LGridJsonCellRenderer : render cell JSON data.

XmlGridPickerCtrl : UI control storing the tabular data in as XML
document.
LBoundXmlGridPicker : connect XmlGridPicker to database.
LGridXmlCellEditor : grid editor for LBoundXmlGridPicker.
LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker.

JsonHelper and XmlHelper : for applications to quickly get intent value
from database data..

The structure of managed tabular data :

Column 1 : Intent - this is what we want to store/edit. This can be
telephone numbers, email addresses, instant messaging addresses...
any single line piece of information that can exist many times for one
entity (person, company...).
Column 2 : Type - A short description of the intent : 'Home, Work,
Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox.
Column 3 : Preferred - One line of data can be selected as the preferred
one. It is not mandatory, but it must be a single choice.
Column 4 : Notes - single line notes.

Adjust sql scripts and L7.dox.
Applied ANSI formatting style to all files.

Other changes :

Work around a nasty misbehavior.
Grid columns edited by a translated combobox expect full string
data as cell values. LResultSet::BEData() will report these mapped strings,
instead of database real data. LBoundComboBox::IsDirty() will always be
true even if the editor is unchanged once created.
Simplest workaround : disconnect m_BoundComboBox if unchanged.

LGridTextEditor::ProvideFormEditor() : set the form editor's value
explicitely.; wxTextCtrl does not interpret data it receives

LBoundControl::SetNull must be void.

LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind::

LConnection::GetReturnedKeys should return NULL.
LConnection::SetData should return void.

Notes : wxJSON must be configured with the same prefix as wxWidgets,
here /usr/local/{wxWidgets,wxWidgets-Release}.
This commit is contained in:
SET
2019-12-22 16:35:16 +01:00
parent 1ec23950c0
commit aaacf88071
82 changed files with 3368 additions and 595 deletions

View File

@@ -0,0 +1,211 @@
/*
* File: BaseGridPicker.cpp
* Author: SET - nmset@netcourrier.com
* License : LGPL version 2.1
* Copyright SET, M. D. - © 2014
*
* Created on December 7, 2019, 9:40 PM
*/
#include "BaseGridPicker.h"
IMPLEMENT_CLASS(BaseGridPicker, BasePicker)
BaseGridPicker::BaseGridPicker(wxWindow *parent,
wxWindowID id,
const wxArrayString& types,
wxSize popupSize,
const wxString& text,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator& validator,
const wxString& name)
: BasePicker(parent, id, popupSize, text, pos, size, style, validator, name)
{
m_grid = NULL;
m_stringTable = NULL;
m_editable = true;
m_intentLabel = _T("Intent");
m_nbInsertRows = 3;
m_colTypeChoices = types;
m_PrefEditor = NULL;
wxButton * btn = static_cast<wxButton*> (GetPickerCtrl());
btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &BaseGridPicker::ShowPopup, this);
}
BaseGridPicker::~BaseGridPicker()
{
delete m_grid;
}
void BaseGridPicker::UpdatePickerFromTextCtrl()
{
// Gets called when TextCtrl is changed
}
void BaseGridPicker::UpdateTextCtrlFromPicker()
{
// Gets called when TextCtrl loses focus
}
void BaseGridPicker::CreateGrid()
{
wxDELETE(m_grid);
BasePicker::CreatePopup();
m_grid = new wxGrid(m_popup, wxID_ANY);
m_popup->GetSizer()->Add(m_grid, 1, wxGROW | wxALL, 0);
m_grid->SetSize(m_popup->GetSize());
m_grid->SetDefaultCellAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
m_stringTable = new wxGridStringTable();
m_stringTable->CanHaveAttributes();
m_grid->HideRowLabels();
m_grid->SetUseNativeColLabels();
m_grid->SetTable(m_stringTable);
m_grid->SetSelectionMode(wxGrid::wxGridSelectionModes::wxGridSelectRows);
PrepareGrid();
FillGrid();
}
void BaseGridPicker::SetIntentLabel(const wxString& intent)
{
m_intentLabel = intent;
wxASSERT_MSG(m_stringTable != NULL, _("m_stringTable IS NULL"));
m_stringTable->SetColLabelValue(0, m_intentLabel);
}
wxString BaseGridPicker::GetIntent() const
{
wxASSERT_MSG(m_stringTable != NULL, _("m_stringTable IS NULL"));
for (uint row = 0; row < m_stringTable->GetRowsCount(); row++)
{
if (m_stringTable->GetValue(row, 2) != _T("0")
&& !m_stringTable->GetValue(row, 2).IsEmpty()
&& !m_stringTable->GetValue(row, 0).IsEmpty())
{
return m_stringTable->GetValue(row, 0);
}
}
return wxEmptyString;
}
void BaseGridPicker::EnableEditing(bool editable)
{
m_editable = editable;
m_nbInsertRows = editable ? 3 : 0;
}
void BaseGridPicker::OnPopupHidden(wxShowEvent& evt)
{
if (evt.IsShown())
{
evt.Skip();
return;
}
m_grid->SaveEditControlValue();
/*
* Workaround an unexpected behavior :
* If cell is edited to empty, SaveEditControlValue() above does not
* save the empty string in the string table.
* It still contains the old non-empty value.
* GoToCell() below effectively ends editing.
* But this does not happen if cell is edited from empty to any non-empty
* value.
*/
m_grid->GoToCell(m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol());
DumpGrid();
for (uint row = 0; row < m_stringTable->GetRowsCount(); row++)
{
if (m_stringTable->GetValue(row, 2) != _T("0")
&& !m_stringTable->GetValue(row, 2).IsEmpty())
{
const wxString intent = m_stringTable->GetValue(row, 0);
if (!intent.IsEmpty())
{
GetTextCtrl()->SetValue(intent);
}
else
{
GetTextCtrl()->SetValue(INVALID_INTENT);
}
evt.Skip();
return;
}
}
GetTextCtrl()->SetValue(INVALID_INTENT);
evt.Skip();
}
void BaseGridPicker::PreparePreferredCol()
{
wxASSERT_MSG(m_stringTable != NULL, _("m_stringTable IS NULL"));
wxGridCellAttr * colAtt = m_stringTable->GetAttr(m_grid->GetGridCursorRow(), 2, wxGridCellAttr::Col);
if (colAtt == NULL) colAtt = new wxGridCellAttr();
wxGridCellBoolEditor * ed = new wxGridCellBoolEditor();
colAtt->SetEditor(ed);
wxGridCellBoolRenderer * rn = new wxGridCellBoolRenderer();
colAtt->SetRenderer(rn);
colAtt->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTRE);
m_stringTable->SetColAttr(colAtt, 2);
}
void BaseGridPicker::PrepareTypeCol()
{
wxASSERT_MSG(m_stringTable != NULL, _("m_stringTable IS NULL"));
wxGridCellAttr * colAtt = m_stringTable->GetAttr(m_grid->GetGridCursorRow(), 1, wxGridCellAttr::Col);
if (colAtt == NULL) colAtt = new wxGridCellAttr();
wxGridCellChoiceEditor* ed = new wxGridCellChoiceEditor(m_colTypeChoices);
colAtt->SetEditor(ed);
m_stringTable->SetColAttr(colAtt, 1);
}
void BaseGridPicker::PrepareGrid()
{
wxASSERT_MSG(m_grid != NULL, _("m_grid IS NULL"));
wxASSERT_MSG(m_stringTable != NULL, _("m_stringTable IS NULL"));
m_grid->AppendCols(4);
m_grid->AppendRows(m_nbInsertRows);
PreparePreferredCol();
PrepareTypeCol();
m_grid->SetColSize(0, 170);
m_grid->SetColSize(1, 100);
m_grid->SetColSize(3, 200);
m_stringTable->SetColLabelValue(0, m_intentLabel);
m_stringTable->SetColLabelValue(1, _T("Type"));
m_stringTable->SetColLabelValue(2, _T("Preferred"));
m_stringTable->SetColLabelValue(3, _T("Notes"));
m_grid->Bind(wxEVT_GRID_EDITOR_CREATED, &BaseGridPicker::OnEditorCreated, this);
m_grid->Bind(wxEVT_GRID_EDITOR_HIDDEN, &BaseGridPicker::OnEditorHidden, this);
}
void BaseGridPicker::OnEditorCreated(wxGridEditorCreatedEvent& evt)
{
if (evt.GetCol() == 2)
{
m_PrefEditor = static_cast<wxCheckBox*> (evt.GetControl());
}
evt.Skip();
}
void BaseGridPicker::OnEditorHidden(wxGridEvent& evt)
{
if (evt.GetCol() == 2 && m_PrefEditor && m_PrefEditor->IsChecked())
{
for (uint row = 0; row < m_stringTable->GetRowsCount(); row++)
{
if (row != evt.GetRow())
{
m_stringTable->SetValue(row, evt.GetCol(), _T("0"));
}
}
m_grid->ForceRefresh();
}
evt.Skip();
}
void BaseGridPicker::ShowPopup(wxCommandEvent& evt)
{
BasePicker::DoShowPopup();
evt.Skip();
}