Files
l7/special/BaseGridPicker.h

173 lines
4.5 KiB
C
Raw Permalink Normal View History

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}.
2019-12-22 16:35:16 +01:00
/*
* File: BaseGridPicker.h
2022-11-19 16:05:44 +01:00
* Author: Saleem Edah-Tally - nmset@yandex.com
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}.
2019-12-22 16:35:16 +01:00
* License : LGPL version 2.1
2022-11-19 16:05:44 +01:00
* Copyright Saleem Edah-Tally, M. D. - © 2014
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}.
2019-12-22 16:35:16 +01:00
*
* Created on December 7, 2019, 9:40 PM
*/
#ifndef BASEGRIDPICKER_H
#define BASEGRIDPICKER_H
#include "BasePicker.h"
#include <wx/grid.h>
#define INVALID_INTENT _("[Invalid]")
/**
* Abstract class adding a wxGrid to BasePicker.
* <br/>The grid is contained in the popup. It has 4 columns :
* <br/><br/> Column 0 : The intent : phone, email..., in single line
* <br/> Column 1 : Type : Home, Work...
* <br/> Column 2 : Preferred : one entry should be preferred
* <br/> Column 3 : Short notes in single line
* <br/><br/>
* The label of the Intent column can be changed by an application. The other
* columns have fixed labels.
* <br/>
* The Type column is edited with a combobox. Its values are set by
* SetColTypeChoices().
* <br/>
* The Preferred column allows selecting one single entry as preferred. If none
* is selected, the dataset persists but considered invalid.
* <br/>
* Selection mode is wxGridSelectRows. Row labels are hidden.
* <br/>
* Three empty rows are available for quick multiple inputs.
* @return
*/
class BaseGridPicker : public BasePicker
{
DECLARE_CLASS(BaseGridPicker)
public:
BaseGridPicker(wxWindow *parent,
wxWindowID id,
const wxArrayString& types,
wxSize popupSize = wxDefaultSize,
const wxString& text = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxPB_USE_TEXTCTRL,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxButtonNameStr);
virtual ~BaseGridPicker();
/**
* Unused, empty implementation.
*/
virtual void UpdatePickerFromTextCtrl();
/**
* Unused, empty implementation.
*/
virtual void UpdateTextCtrlFromPicker();
virtual void SetValue(const wxString& value) = 0;
virtual wxString GetValue() = 0;
/**
* Sets the values of the Type column in a combobox.
* @param choices
*/
void SetColTypeChoices(const wxArrayString& choices)
{
m_colTypeChoices = choices;
}
/**
* Gets the values of the Type column.
* @return
*/
wxArrayString GetColTypeChoices() const
{
return m_colTypeChoices;
}
/**
* Sets the label of the Intent column.
* @param intent
*/
void SetIntentLabel(const wxString& intent);
/**
* Gets the label of the Intent column.
* @return
*/
wxString GetIntentLabel() const
{
return m_intentLabel;
}
/**
* Gets the Intent value, the one that is marked as preferred.
* It may return an empty string if no item is preferred.
* @return
*/
wxString GetIntent() const;
/**
* Can we modify data ?
* @return
*/
bool IsEditable() const
{
return m_editable;
}
/**
* Grid data may be editable or not. In the latter case, no empty rows are
* shown.
* @param editable
*/
void EnableEditing(bool editable);
protected:
/**
* Saves the grid's content internally and updates the wxTextCtrl's value.
* @param evt
*/
virtual void OnPopupHidden(wxShowEvent& evt);
virtual void FillGrid() = 0;
virtual void DumpGrid() = 0;
/**
* Creates, configures and fills the grid by calling FillGrid(). A previous
* grid is deleted.
*/
void CreateGrid();
wxGrid * m_grid;
wxGridStringTable * m_stringTable;
bool m_editable;
private:
wxArrayString m_colTypeChoices;
wxString m_intentLabel;
uint m_nbInsertRows;
/**
* Configures the Preferred column for editing and rendering using a
* checkbox.
*/
void PreparePreferredCol();
/**
* Configures the Type column for editing using a combobox.
*/
void PrepareTypeCol();
/**
* Adds rows and columns, configures the columns, further setting sizes
* and labels.
* <br/>
* Binds the grid to editor creation and hidden events.
*/
void PrepareGrid();
/**
* Concerns the Preferred column only. When the editor is checked, ensures
* the other rows are unchecked.
* @param evt
*/
void OnPrefCellChanged(wxGridEvent& evt);
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}.
2019-12-22 16:35:16 +01:00
/**
* Just calls BasePicker::DoShowPopup().
* @param evt
*/
virtual void ShowPopup(wxCommandEvent& evt);
};
#endif /* BASEGRIDPICKER_H */