Skip to content

Commit

Permalink
fix issue: editing is limited to 10 digits in a integer field in table
Browse files Browse the repository at this point in the history
fix: editing is limited to 10 digits in a integer field in table

update the logic of resize column width based on content instead of using column lable width;
  • Loading branch information
lixun910 committed Feb 20, 2019
1 parent d7382bf commit 20ec4c5
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
23 changes: 12 additions & 11 deletions DataViewer/OGRColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ OGRColumnInteger::OGRColumnInteger(wxString name, int field_length, int decimals
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = 0;
undef_markers[i] = false;
undef_markers[i] = true;
}
}

Expand All @@ -303,7 +303,7 @@ OGRColumnInteger::OGRColumnInteger(OGRLayerProxy* ogr_layer, wxString name,
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = 0;
undef_markers[i] = false;
undef_markers[i] = true;
}
}

Expand Down Expand Up @@ -467,8 +467,8 @@ void OGRColumnInteger::SetValueAt(int row_idx, const wxString &value,
}

wxInt64 l_val;
if ( GenUtils::validInt(value) ) {
GenUtils::strToInt64(value, &l_val);

if (value.ToLongLong(&l_val)) {
if (is_new) {
new_data[row_idx] = l_val;
} else {
Expand Down Expand Up @@ -741,7 +741,7 @@ OGRColumnString::OGRColumnString(wxString name, int field_length,
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = wxEmptyString;
undef_markers[i] = false;
undef_markers[i] = true;
}
}
OGRColumnString::OGRColumnString(OGRLayerProxy* ogr_layer, wxString name,
Expand All @@ -754,7 +754,7 @@ OGRColumnString::OGRColumnString(OGRLayerProxy* ogr_layer, wxString name,
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = wxEmptyString;
undef_markers[i] = false;
undef_markers[i] = true;
}
}

Expand Down Expand Up @@ -787,9 +787,6 @@ void OGRColumnString::FillData(vector<double>& data)
for (int i=0; i<rows; ++i) {
double val = 0.0;
if ( !new_data[i].ToDouble(&val) ) {
// internal is always local "C"
//wxString error_msg = wxString::Format( "Fill data error: can't convert '%s' to floating-point number.", new_data[i]);
//throw GdaException(error_msg.c_str());
undef_markers[i] = true;
}
data[i] = val;
Expand All @@ -815,6 +812,8 @@ void OGRColumnString::FillData(vector<double>& data)
} else if (tmp.ToDouble(&val)) {
data[i] = val;
} else {
// get name of current locale
char *old_locale = setlocale(LC_NUMERIC, NULL);
// try comma as decimal point
setlocale(LC_NUMERIC, "de_DE");
double _val;
Expand All @@ -824,7 +823,7 @@ void OGRColumnString::FillData(vector<double>& data)
data[i] = 0.0;
undef_markers[i] = true;
}
setlocale(LC_NUMERIC, "C");
setlocale(LC_NUMERIC, old_locale);
}
}
}
Expand Down Expand Up @@ -879,6 +878,8 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
data[i] = val;

} else {
// get name of current locale
char *old_locale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "de_DE");
wxInt64 val_;
double val_d_;
Expand All @@ -893,7 +894,7 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
data[i] = 0;
undef_markers[i] = true;
}
setlocale(LC_NUMERIC, "C");
setlocale(LC_NUMERIC, old_locale);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DataViewer/TableBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void TableBase::update(TableState* o)
BOOST_FOREACH(const TableDeltaEntry& e, o->GetTableDeltaListRef()) {
if (e.insert) {
if (e.type == GdaConst::long64_type) {
GetView()->SetColFormatNumber(e.pos_final);
// leave as a string: for more than 10 digts 64-bit number
} else if (e.type == GdaConst::double_type) {
int dd = e.displayed_decimals;
if (dd == -1) dd = e.decimals;
Expand Down
31 changes: 9 additions & 22 deletions DataViewer/TableFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,30 @@ TableFrame::TableFrame(wxFrame *parent, Project* project,
for (int i=0, iend=table_base->GetNumberCols(); i<iend; i++) {
double cur_col_size = grid->GetColSize(i);
double cur_lbl_len = grid->GetColLabelValue(i).length();
double avg_cell_len = 0;
double max_cell_len = 0;
for (int j=0; j<sample-1; ++j) {
wxString cv = grid->GetCellValue(j, i);
cv.Trim(true);
cv.Trim(false);
avg_cell_len += cv.length();
if (cv.length() > max_cell_len) max_cell_len = cv.length();
}
if (sample >= 1) { // sample last row
wxString txt = grid->GetCellValue(table_base->GetNumberRows()-1, i);
avg_cell_len += txt.length();
}
avg_cell_len /= (double) sample;
if (avg_cell_len > cur_lbl_len &&
avg_cell_len >= 1 && cur_lbl_len >= 1) {
if (max_cell_len > cur_lbl_len &&
max_cell_len >= 1 && cur_lbl_len >= 1) {
// attempt to scale up col width based on cur_col_size
double fac = avg_cell_len / cur_lbl_len;
fac *= 1.2;
double fac = max_cell_len / cur_lbl_len;
if (fac < 1) fac = 1;
if (fac < 1.5 && fac > 1) fac = 1.5;
if (fac > 5) fac = 5;
grid->SetColMinimalWidth(i, cur_col_size*fac);
grid->SetColSize(i, cur_col_size*fac);
fac = fac * 1.2;
grid->SetColMinimalWidth(i, cur_col_size * fac);
grid->SetColSize(i, cur_col_size * fac);
} else {
// add a few pixels of buffer to current label
grid->SetColMinimalWidth(i, cur_col_size+6);
grid->SetColSize(i, cur_col_size+6);
}
}

//if (!project->IsFileDataSource()) {
// grid->DisableDragColMove();
//}

//grid->SetMargins(0 - wxSYS_VSCROLL_X, 0);
grid->ForceRefresh();

wxBoxSizer *box = new wxBoxSizer(wxVERTICAL);
box->Add(grid, 1, wxEXPAND | wxALL, 0);
panel->SetSizerAndFit(box);
Expand Down Expand Up @@ -223,7 +211,6 @@ void TableFrame::OnMenuClose(wxCommandEvent& event)
void TableFrame::MapMenus()
{
// Map Default Options Menus
//wxMenu* optMenu=wxXmlResource::Get()->LoadMenu("ID_DEFAULT_MENU_OPTIONS");
wxMenu* optMenu=wxXmlResource::Get()->LoadMenu("ID_TABLE_VIEW_MENU_CONTEXT");
GeneralWxUtils::ReplaceMenu(GdaFrame::GetGdaFrame()->GetMenuBar(), _("Options"), optMenu);
}
Expand Down
17 changes: 15 additions & 2 deletions DialogTools/CreatingWeightDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ w_man_int(project_s->GetWManInt()),
w_man_state(project_s->GetWManState()),
m_num_obs(project_s->GetNumRecords()),
m_cbx_precision_threshold_first_click(true),
suspend_table_state_updates(false)
suspend_table_state_updates(false),
is_table_only(project_s->IsTableOnlyProject())
{
wxLogMessage("Open CreatingWeightDlg");
Create(parent, id, caption, pos, size, style);
Expand Down Expand Up @@ -219,13 +220,25 @@ void CreatingWeightDlg::CreateControls()
m_power->Enable(false);
m_power_knn->Enable(false);

m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &CreatingWeightDlg::OnDistanceWeightsInputUpdate, this);
m_nb_weights_type->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
&CreatingWeightDlg::OnWeightTypeSelect, this);
m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
&CreatingWeightDlg::OnDistanceWeightsInputUpdate, this);
m_Vars->Bind(wxEVT_LISTBOX, &CreatingWeightDlg::OnDistanceWeightsVarsSel, this);
m_dist_choice_vars->Bind(wxEVT_CHOICE, &CreatingWeightDlg::OnDistanceMetricVarsSel, this);
m_trans_choice_vars->Bind(wxEVT_CHOICE, &CreatingWeightDlg::OnDistanceMetricVarsSel, this);
InitDlg();
}

void CreatingWeightDlg::OnWeightTypeSelect( wxCommandEvent& event )
{
int sel = event.GetSelection();
if (is_table_only && sel == 0) {
// force to "distance weight"
m_nb_weights_type->SetSelection(1);
}
}

void CreatingWeightDlg::OnDistanceMetricVarsSel( wxCommandEvent& event )
{
int metric = m_dist_choice_vars->GetSelection();
Expand Down
3 changes: 2 additions & 1 deletion DialogTools/CreatingWeightDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public TableStateObserver, public WeightsManStateObserver
void OnDistanceWeightsInputUpdate( wxBookCtrlEvent& event );
void OnDistanceWeightsVarsSel( wxCommandEvent& event );
void OnDistanceMetricVarsSel( wxCommandEvent& event );
void OnWeightTypeSelect( wxCommandEvent& event );
/** Implementation of FramesManagerObserver interface */
virtual void update(FramesManager* o);

Expand Down Expand Up @@ -165,7 +166,7 @@ public TableStateObserver, public WeightsManStateObserver
TableState* table_state;
WeightsManState* w_man_state;
WeightsManInterface* w_man_int;

bool is_table_only;
bool user_xy;
// col_id_map[i] is a map from the i'th numeric item in the
// fields drop-down to the actual col_id_map. Items
Expand Down
4 changes: 2 additions & 2 deletions rc/dialogs.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -3482,7 +3482,7 @@
</object>
<object class="sizeritem">
<object class="wxNotebook" name="IDC_NB_WEIGHTS_CREATION">
<object class="notebookpage">
<object class="notebookpage" name="IDC_NBPG_CONTIGUITY_WEIGHT">
<object class="wxPanel">
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
Expand Down Expand Up @@ -3568,7 +3568,7 @@
<label>Contiguity Weight</label>
<flag>wxALL|wxEXPAND</flag>
</object>
<object class="notebookpage">
<object class="notebookpage" name="IDC_NBPG_DISTANCE_WEIGHT">
<object class="wxPanel">
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
Expand Down
4 changes: 1 addition & 3 deletions wxTranslationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ bool wxTranslationHelper::Load()
wxArrayString names;
wxArrayLong identifiers;
GetInstalledLanguages(names, identifiers);

//AskUserForLanguage(names, identifiers);


for(size_t i = 0; i < identifiers.Count(); i++) {
if(identifiers[i] == language) {
if(m_Locale) {
Expand Down

0 comments on commit 20ec4c5

Please sign in to comment.