1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // User Interface //
9 // //
10 // Program: SAGA //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // dlg_table_control.cpp //
15 // //
16 // Copyright (C) 2015 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. SAGA is free software; you //
22 // can redistribute it and/or modify it under the terms //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the //
25 // License, or (at your option) any later version. //
26 // //
27 // SAGA is distributed in the hope that it will be //
28 // useful, but WITHOUT ANY WARRANTY; without even the //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
30 // PARTICULAR PURPOSE. See the GNU General Public //
31 // License for more details. //
32 // //
33 // You should have received a copy of the GNU General //
34 // Public License along with this program; if not, see //
35 // <http://www.gnu.org/licenses/>. //
36 // //
37 //-------------------------------------------------------//
38 // //
39 // contact: Olaf Conrad //
40 // Institute of Geography //
41 // University of Hamburg //
42 // Germany //
43 // //
44 // e-mail: oconrad@saga-gis.org //
45 // //
46 ///////////////////////////////////////////////////////////
47
48 //---------------------------------------------------------
49 #include <wx/window.h>
50
51 #include <saga_api/saga_api.h>
52
53 #include "res_commands.h"
54 #include "res_dialogs.h"
55
56 #include "helper.h"
57
58 #include "wksp_data_manager.h"
59
60 #include "view_table_data.h"
61 #include "dlg_table_control.h"
62
63
64 ///////////////////////////////////////////////////////////
65 // //
66 // //
67 // //
68 ///////////////////////////////////////////////////////////
69
70 //---------------------------------------------------------
IMPLEMENT_CLASS(CDLG_Table_Control,wxGrid)71 IMPLEMENT_CLASS(CDLG_Table_Control, wxGrid)
72
73 //---------------------------------------------------------
74 BEGIN_EVENT_TABLE(CDLG_Table_Control, wxGrid)
75 #if (wxMAJOR_VERSION == 3 && wxMINOR_VERSION <= 1)
76 EVT_GRID_RANGE_SELECT (CDLG_Table_Control::On_Selected ) // RANGE_SELECT was split in RANGE_SELECTING and SELECTED in 3.2
77 #else
78 EVT_GRID_RANGE_SELECTED (CDLG_Table_Control::On_Selected )
79 #endif
80 EVT_GRID_CELL_CHANGED (CDLG_Table_Control::On_Changed )
81
82 EVT_GRID_CELL_LEFT_CLICK (CDLG_Table_Control::On_LClick )
83 EVT_GRID_CELL_LEFT_DCLICK (CDLG_Table_Control::On_LDClick )
84 EVT_GRID_LABEL_LEFT_CLICK (CDLG_Table_Control::On_LClick_Label )
85 EVT_GRID_LABEL_LEFT_DCLICK(CDLG_Table_Control::On_LDClick_Label)
86
87 EVT_GRID_CELL_RIGHT_CLICK (CDLG_Table_Control::On_RClick )
88 EVT_GRID_LABEL_RIGHT_CLICK(CDLG_Table_Control::On_RClick_Label )
89
90 EVT_MENU (ID_CMD_TABLE_AUTOSIZE_COLS , CDLG_Table_Control::On_Autosize_Cols)
91 EVT_MENU (ID_CMD_TABLE_AUTOSIZE_ROWS , CDLG_Table_Control::On_Autosize_Rows)
92
93 EVT_MENU (ID_CMD_TABLE_FIELD_OPEN_APP , CDLG_Table_Control::On_Cell_Open )
94 EVT_MENU (ID_CMD_TABLE_FIELD_OPEN_DATA, CDLG_Table_Control::On_Cell_Open )
95
96 EVT_MENU (ID_CMD_TABLE_RECORD_ADD , CDLG_Table_Control::On_Record_Add )
97 EVT_UPDATE_UI(ID_CMD_TABLE_RECORD_ADD , CDLG_Table_Control::On_Record_Add_UI)
98 EVT_MENU (ID_CMD_TABLE_RECORD_INS , CDLG_Table_Control::On_Record_Ins )
99 EVT_UPDATE_UI(ID_CMD_TABLE_RECORD_INS , CDLG_Table_Control::On_Record_Ins_UI)
100 EVT_MENU (ID_CMD_TABLE_RECORD_DEL , CDLG_Table_Control::On_Record_Del )
101 EVT_UPDATE_UI(ID_CMD_TABLE_RECORD_DEL , CDLG_Table_Control::On_Record_Del_UI)
102 EVT_MENU (ID_CMD_TABLE_RECORD_DEL_ALL , CDLG_Table_Control::On_Record_Clr )
103 EVT_UPDATE_UI(ID_CMD_TABLE_RECORD_DEL_ALL , CDLG_Table_Control::On_Record_Clr_UI)
104
105 EVT_MENU (ID_CMD_TABLE_FIELD_SORT , CDLG_Table_Control::On_Field_Sort )
106 EVT_UPDATE_UI(ID_CMD_TABLE_FIELD_SORT , CDLG_Table_Control::On_Field_Sort_UI)
107 END_EVENT_TABLE()
108
109
110 ///////////////////////////////////////////////////////////
111 // //
112 ///////////////////////////////////////////////////////////
113
114 //---------------------------------------------------------
115 CDLG_Table_Control::CDLG_Table_Control(wxWindow *pParent, CSG_Table *pTable)
116 : wxGrid(pParent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxSUNKEN_BORDER)
117 {
118 m_Table.Create(*pTable);
119 m_pData = new CVIEW_Table_Data(&m_Table);
120
121 if( pTable->Get_MetaData()("SAGA_GUI_LUT_TYPE")
122 && pTable->Get_Field_Count() == 5
123 && pTable->Get_Field_Type(0) == SG_DATATYPE_Color
124 && pTable->Get_Field_Type(1) == SG_DATATYPE_String
125 && pTable->Get_Field_Type(2) == SG_DATATYPE_String )
126 {
127 m_LUT_Type = pTable->Get_MetaData()["SAGA_GUI_LUT_TYPE"].Get_Content().asInt();
128 }
129 else
130 {
131 m_LUT_Type = SG_DATAOBJECT_TYPE_Undefined;
132 }
133
134 EnableDragGridSize(false);
135 DisableDragRowSize();
136 SetRowLabelAlignment(wxALIGN_RIGHT, wxALIGN_CENTRE);
137 SetCellHighlightColour(SYS_Get_Color(wxSYS_COLOUR_HIGHLIGHT));
138
139 wxGridCellRenderer *pRenderer;
140
141 pRenderer = GetDefaultRendererForType(wxGRID_VALUE_FLOAT);
142 pRenderer->DecRef();
143 pRenderer->SetParameters("-1,-1,g"); // Use the shorter of e or f (g)
144
145 #if !(wxMAJOR_VERSION == 3 && wxMINOR_VERSION <= 1)
146 pRenderer = GetDefaultRendererForType(wxGRID_VALUE_DATE );
147 pRenderer->DecRef();
148 pRenderer->SetParameters("%Y-%m-%d");
149 #endif
150
151 SetTable(m_pData, true, wxGrid::wxGridSelectRows);
152
153 Update_Table();
154 }
155
156 //---------------------------------------------------------
~CDLG_Table_Control(void)157 CDLG_Table_Control::~CDLG_Table_Control(void)
158 {}
159
160
161 ///////////////////////////////////////////////////////////
162 // //
163 ///////////////////////////////////////////////////////////
164
165 //---------------------------------------------------------
Update_Table(void)166 bool CDLG_Table_Control::Update_Table(void)
167 {
168 return( GetBatchCount() == 0 && _Update_Records() );
169 }
170
171 //---------------------------------------------------------
Update_Selection(void)172 bool CDLG_Table_Control::Update_Selection(void)
173 {
174 return( _Update_Selection() );
175 }
176
177 //---------------------------------------------------------
_Update_Records(void)178 bool CDLG_Table_Control::_Update_Records(void)
179 {
180 //-----------------------------------------------------
181 int dCols = m_pData->GetNumberCols() - GetNumberCols();
182
183 if( dCols > 0 )
184 {
185 AppendCols(dCols);
186 }
187 else if( dCols < 0 )
188 {
189 DeleteCols(0, -dCols);
190 }
191
192 //-----------------------------------------------------
193 int dRows = m_pData->GetNumberRows() - GetNumberRows();
194
195 if( dRows > 0 )
196 {
197 AppendRows(dRows);
198 }
199 else if( dRows < 0 )
200 {
201 DeleteRows(0, -dRows);
202 }
203
204 //-----------------------------------------------------
205 for(int iField=0; iField<m_Table.Get_Field_Count(); iField++)
206 {
207 if( m_Table.Get_Field_Type(iField) == SG_DATATYPE_Color )
208 {
209 BeginBatch();
210
211 for(int i=0; i<m_pData->GetNumberRows(); i++)
212 {
213 wxColour Colour(Get_Color_asWX(m_pData->Get_Record(i)->asInt(iField)));
214
215 SetCellBackgroundColour(i, iField, Colour);
216 SetCellTextColour (i, iField, Colour);
217 }
218
219 EndBatch();
220 }
221 }
222
223 //-----------------------------------------------------
224 _Update_Selection();
225
226 return( true );
227 }
228
229 //---------------------------------------------------------
_Update_Selection(void)230 bool CDLG_Table_Control::_Update_Selection(void)
231 {
232 if( GetBatchCount() > 0 )
233 {
234 return( false );
235 }
236
237 //-----------------------------------------------------
238 BeginBatch();
239
240 ClearSelection();
241
242 if( m_Table.Get_Selection_Count() > 0 )
243 {
244 for(int i=0; i<m_pData->GetRowsCount(); i++)
245 {
246 if( m_pData->Get_Record(i)->is_Selected() )
247 {
248 SelectRow(i, true);
249 }
250 }
251 }
252
253 EndBatch();
254
255 return( true );
256 }
257
258
259 ///////////////////////////////////////////////////////////
260 // //
261 ///////////////////////////////////////////////////////////
262
263 //---------------------------------------------------------
On_Selected(wxGridRangeSelectEvent & event)264 void CDLG_Table_Control::On_Selected(wxGridRangeSelectEvent &event)
265 {
266 if( event.Selecting() )
267 {
268 m_Table.Select(); // clear current selection
269
270 for(int i=0; i<m_Table.Get_Count(); i++)
271 {
272 if( IsInSelection(i, 0) )
273 {
274 m_Table.Select(i, true);
275 }
276 }
277 }
278 }
279
280
281 ///////////////////////////////////////////////////////////
282 // //
283 ///////////////////////////////////////////////////////////
284
285 //---------------------------------------------------------
On_Changed(wxGridEvent & event)286 void CDLG_Table_Control::On_Changed(wxGridEvent &event)
287 {
288 m_pData->On_Changed(event.GetRow(), event.GetCol());
289 }
290
291
292 ///////////////////////////////////////////////////////////
293 // //
294 ///////////////////////////////////////////////////////////
295
296 //---------------------------------------------------------
On_LClick(wxGridEvent & event)297 void CDLG_Table_Control::On_LClick(wxGridEvent &event)
298 {
299 SetGridCursor(event.GetRow(), event.GetCol());
300
301 //-----------------------------------------------------
302 if( event.AltDown () && m_Table.Get_Field_Type(event.GetCol()) == SG_DATATYPE_String )
303 {
304 Open_Application(GetCellValue(event.GetRow(), event.GetCol()));
305 }
306
307 //-----------------------------------------------------
308 if( event.ControlDown() && m_Table.Get_Field_Type(event.GetCol()) == SG_DATATYPE_String )
309 {
310 g_pData->Open (GetCellValue(event.GetRow(), event.GetCol()));
311 }
312 }
313
314 //---------------------------------------------------------
On_LDClick(wxGridEvent & event)315 void CDLG_Table_Control::On_LDClick(wxGridEvent &event)
316 {
317 if( m_pData->Get_Field_Type(event.GetCol()) == SG_DATATYPE_Color )
318 {
319 CSG_Table_Record *pRecord = m_pData->Get_Record(event.GetRow());
320
321 if( pRecord )
322 {
323 long Value = pRecord->asInt(event.GetCol());
324
325 if( DLG_Color_From_Text(Value) )
326 {
327 pRecord->Set_Value(event.GetCol(), Value);
328
329 wxColour Colour(Get_Color_asWX(Value));
330
331 SetCellBackgroundColour(event.GetRow(), event.GetCol(), Colour);
332 SetCellTextColour (event.GetRow(), event.GetCol(), Colour);
333
334 ForceRefresh();
335 }
336 }
337 }
338 else
339 {
340 event.Skip();
341 }
342 }
343
344 //---------------------------------------------------------
On_LClick_Label(wxGridEvent & event)345 void CDLG_Table_Control::On_LClick_Label(wxGridEvent &event)
346 {
347 if( event.GetRow() != -1 ) // select records
348 {
349 if( event.ControlDown() )
350 {
351 m_Table.Select(m_Table.Get_Record_byIndex(event.GetRow()), true);
352
353 Update_Selection();
354 }
355 else if( event.ShiftDown() )
356 {
357 SelectBlock(event.GetRow(), 0, GetGridCursorRow(), GetNumberCols(), false);
358 }
359 else
360 {
361 SelectRow(event.GetRow(), false);
362 }
363
364 SetGridCursor(event.GetRow(), GetGridCursorCol());
365 }
366 else if( event.GetCol() < 0 )
367 {
368 ClearSelection();
369 }
370 }
371
372 //---------------------------------------------------------
On_LDClick_Label(wxGridEvent & event)373 void CDLG_Table_Control::On_LDClick_Label(wxGridEvent &event)
374 {
375 if( m_pData->Sort(event.GetCol(), -1) )
376 {
377 _Update_Records();
378 }
379 }
380
381
382 ///////////////////////////////////////////////////////////
383 // //
384 ///////////////////////////////////////////////////////////
385
386 //---------------------------------------------------------
On_RClick(wxGridEvent & event)387 void CDLG_Table_Control::On_RClick(wxGridEvent &event)
388 {
389 SetGridCursor(event.GetRow(), event.GetCol());
390
391 //-----------------------------------------------------
392 switch( m_Table.Get_Field_Type(event.GetCol()) )
393 {
394 default:
395 {
396 // nop
397 }
398 break;
399
400 case SG_DATATYPE_String:
401 {
402 wxMenu Menu;
403
404 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_OPEN_APP);
405
406 wxString Value = GetCellValue(event.GetRow(), event.GetCol());
407
408 if( m_pData->is_DataSource(Value) )
409 {
410 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_OPEN_DATA);
411 }
412
413 PopupMenu(&Menu, event.GetPosition());
414 }
415 break;
416
417 case SG_DATATYPE_Color:
418 {
419 CSG_Table_Record *pRecord = m_pData->Get_Record(event.GetRow()); long lValue;
420
421 if( pRecord && DLG_Color(lValue = pRecord->asInt(event.GetCol())) )
422 {
423 pRecord->Set_Value(event.GetCol(), lValue);
424
425 wxColour Colour(Get_Color_asWX(pRecord->asInt(event.GetCol())));
426
427 SetCellBackgroundColour(event.GetRow(), event.GetCol(), Colour);
428 SetCellTextColour (event.GetRow(), event.GetCol(), Colour);
429
430 ForceRefresh();
431 }
432 }
433 break;
434 }
435 }
436
437 //---------------------------------------------------------
On_RClick_Label(wxGridEvent & event)438 void CDLG_Table_Control::On_RClick_Label(wxGridEvent &event)
439 {
440 //-----------------------------------------------------
441 if( event.GetCol() != -1 )
442 {
443 wxMenu Menu(_TL("Columns"));
444
445 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_COLS);
446 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_SORT);
447 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_RENAME);
448
449 PopupMenu(&Menu, event.GetPosition().x, event.GetPosition().y - GetColLabelSize());
450 }
451
452 //-----------------------------------------------------
453 else if( event.GetRow() != -1 )
454 {
455 wxMenu Menu(_TL("Rows"));
456
457 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_ADD);
458 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_INS);
459 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_DEL);
460 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_DEL_ALL);
461
462 Menu.AppendSeparator();
463 CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_ROWS);
464
465 PopupMenu(&Menu, event.GetPosition().x - GetRowLabelSize(), event.GetPosition().y);
466 }
467
468 //-----------------------------------------------------
469 else
470 {
471 ClearSelection();
472 }
473 }
474
475
476 ///////////////////////////////////////////////////////////
477 // //
478 ///////////////////////////////////////////////////////////
479
480 //---------------------------------------------------------
On_Autosize_Cols(wxCommandEvent & event)481 void CDLG_Table_Control::On_Autosize_Cols(wxCommandEvent &event)
482 {
483 AutoSizeColumns(false);
484 }
485
486 //---------------------------------------------------------
On_Autosize_Rows(wxCommandEvent & event)487 void CDLG_Table_Control::On_Autosize_Rows(wxCommandEvent &event)
488 {
489 AutoSizeRows(false);
490 }
491
492
493 ///////////////////////////////////////////////////////////
494 // //
495 ///////////////////////////////////////////////////////////
496
497 //---------------------------------------------------------
On_Cell_Open(wxCommandEvent & event)498 void CDLG_Table_Control::On_Cell_Open(wxCommandEvent &event)
499 {
500 wxString Value = GetCellValue(GetGridCursorRow(), GetGridCursorCol());
501
502 if( event.GetId() == ID_CMD_TABLE_FIELD_OPEN_APP )
503 {
504 if( !Open_Application(Value) )
505 {
506 DLG_Message_Show_Error(_TL("failed"), CMD_Get_Name(ID_CMD_TABLE_FIELD_OPEN_APP));
507 }
508 }
509
510 if( event.GetId() == ID_CMD_TABLE_FIELD_OPEN_DATA )
511 {
512 if( !m_pData->is_DataSource(Value) || !g_pData->Open(Value) )
513 {
514 DLG_Message_Show_Error(_TL("failed"), CMD_Get_Name(ID_CMD_TABLE_FIELD_OPEN_DATA));
515 }
516 }
517 }
518
519
520 ///////////////////////////////////////////////////////////
521 // //
522 ///////////////////////////////////////////////////////////
523
524 //---------------------------------------------------------
Add_Record(void)525 bool CDLG_Table_Control::Add_Record(void)
526 {
527 return( m_Table.Add_Record()
528 && _Update_Records()
529 );
530 }
531
532 //---------------------------------------------------------
Ins_Record(void)533 bool CDLG_Table_Control::Ins_Record(void)
534 {
535 return( m_Table.Ins_Record(GetGridCursorRow())
536 && _Update_Records()
537 );
538 }
539
540 //---------------------------------------------------------
Del_Record(void)541 bool CDLG_Table_Control::Del_Record(void)
542 {
543 return( (m_Table.Get_Selection_Count() ? m_Table.Del_Selection() > 0 : m_Table.Del_Record(GetGridCursorRow()))
544 && _Update_Records()
545 );
546 }
547
548 //---------------------------------------------------------
Del_Records(void)549 bool CDLG_Table_Control::Del_Records(void)
550 {
551 return( m_Table.Del_Records()
552 && _Update_Records()
553 );
554 }
555
556
557 ///////////////////////////////////////////////////////////
558 // //
559 ///////////////////////////////////////////////////////////
560
561 //---------------------------------------------------------
On_Record_Add(wxCommandEvent & event)562 void CDLG_Table_Control::On_Record_Add(wxCommandEvent &event)
563 {
564 if( m_Table.Add_Record() )
565 {
566 _Update_Records();
567 }
568 }
569
On_Record_Add_UI(wxUpdateUIEvent & event)570 void CDLG_Table_Control::On_Record_Add_UI(wxUpdateUIEvent &event)
571 {
572 event.Enable(!m_Table.is_Indexed());
573 }
574
575 //---------------------------------------------------------
On_Record_Ins(wxCommandEvent & event)576 void CDLG_Table_Control::On_Record_Ins(wxCommandEvent &event)
577 {
578 if( m_Table.Ins_Record(GetGridCursorRow()) )
579 {
580 _Update_Records();
581 }
582 }
583
On_Record_Ins_UI(wxUpdateUIEvent & event)584 void CDLG_Table_Control::On_Record_Ins_UI(wxUpdateUIEvent &event)
585 {
586 event.Enable(!m_Table.is_Indexed());
587 }
588
589 //---------------------------------------------------------
On_Record_Del(wxCommandEvent & event)590 void CDLG_Table_Control::On_Record_Del(wxCommandEvent &event)
591 {
592 if( m_Table.Del_Selection() )
593 {
594 _Update_Records();
595 }
596 }
597
On_Record_Del_UI(wxUpdateUIEvent & event)598 void CDLG_Table_Control::On_Record_Del_UI(wxUpdateUIEvent &event)
599 {
600 event.Enable(!m_Table.is_Indexed() && m_Table.Get_Selection_Count() > 0);
601 }
602
603 //---------------------------------------------------------
On_Record_Clr(wxCommandEvent & event)604 void CDLG_Table_Control::On_Record_Clr(wxCommandEvent &event)
605 {
606 if( m_Table.Del_Records() )
607 {
608 _Update_Records();
609 }
610 }
611
On_Record_Clr_UI(wxUpdateUIEvent & event)612 void CDLG_Table_Control::On_Record_Clr_UI(wxUpdateUIEvent &event)
613 {
614 event.Enable(m_Table.Get_Selection_Count() > 0);
615 }
616
617
618 ///////////////////////////////////////////////////////////
619 // //
620 ///////////////////////////////////////////////////////////
621
622 //---------------------------------------------------------
On_Field_Sort(wxCommandEvent & event)623 void CDLG_Table_Control::On_Field_Sort(wxCommandEvent &event)
624 {
625 if( m_pData->On_Sort() )
626 {
627 _Update_Records();
628 }
629 }
630
On_Field_Sort_UI(wxUpdateUIEvent & event)631 void CDLG_Table_Control::On_Field_Sort_UI(wxUpdateUIEvent &event)
632 {
633 event.Enable(m_Table.Get_Field_Count() > 0 && m_Table.Get_Record_Count() > 1);
634 }
635
636
637 ///////////////////////////////////////////////////////////
638 // //
639 ///////////////////////////////////////////////////////////
640
641 //---------------------------------------------------------
Load(void)642 bool CDLG_Table_Control::Load(void)
643 {
644 bool bResult = false;
645
646 //-----------------------------------------------------
647 wxString File, Filter;
648
649 Filter += wxString::Format("%s (*.txt, *.csv, *.dbf)|*.txt;*.csv;*.dbf|", _TL("Tables"));
650
651 if( m_LUT_Type != SG_DATAOBJECT_TYPE_Undefined )
652 {
653 Filter += wxString::Format("%s (*.qml)|*.qml|", _TL("QGIS Layer Style File"));
654 }
655
656 Filter += wxString::Format("%s|*.*", _TL("All Files"));
657
658 //-----------------------------------------------------
659 if( DLG_Open(File, _TL("Load Table"), Filter) )
660 {
661 CSG_Table Table;
662
663 if( m_LUT_Type != SG_DATAOBJECT_TYPE_Undefined && SG_File_Cmp_Extension(&File, "qml") )
664 {
665 QGIS_Styles_Import(&File, Table);
666 }
667 else
668 {
669 Table.Create(&File);
670 }
671
672 bResult = Table.Get_Count() > 0 && Table.Get_Field_Count() == m_Table.Get_Field_Count()
673 && m_Table.Assign_Values(&Table) && Update_Table();
674
675 PROCESS_Set_Okay();
676 }
677
678 return( bResult );
679 }
680
681 //---------------------------------------------------------
Save(void)682 bool CDLG_Table_Control::Save(void)
683 {
684 bool bResult = false;
685
686 //-----------------------------------------------------
687 wxString File, Filter;
688
689 Filter += wxString::Format("%s (*.txt, *.csv, *.dbf)|*.txt;*.csv;*.dbf|", _TL("Tables"));
690
691 if( m_LUT_Type == SG_DATAOBJECT_TYPE_Grid )
692 {
693 Filter += wxString::Format("%s (*.qml)|*.qml|", _TL("QGIS Layer Style File"));
694 }
695
696 Filter += wxString::Format("%s|*.*", _TL("All Files"));
697
698 //-----------------------------------------------------
699 if( DLG_Save(File, _TL("Save Table"), Filter) )
700 {
701 if( m_LUT_Type == SG_DATAOBJECT_TYPE_Grid && SG_File_Cmp_Extension(&File, "qml") )
702 {
703 bResult = QGIS_Styles_Export(&File, m_Table);
704 }
705 else
706 {
707 bResult = m_Table.Save(&File);
708 }
709
710 PROCESS_Set_Okay();
711 }
712
713 return( bResult );
714 }
715
716
717 ///////////////////////////////////////////////////////////
718 // //
719 // //
720 // //
721 ///////////////////////////////////////////////////////////
722
723 //---------------------------------------------------------
724