-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainWindow.cpp
More file actions
2961 lines (2759 loc) · 119 KB
/
Copy pathmainWindow.cpp
File metadata and controls
2961 lines (2759 loc) · 119 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* mainWindow.cpp: the beating heart of MecParts (a Meccano parts inventory
* program). You can define parts, sets, prices, currencies, quantities, and
* even pictures. One feature I've found to be really handy is the ability
* to say "if I have this set of parts and want to build this model, what
* parts do I need that I don't have?"
*
* Copyright 2012 Wayne Hortensius <whortens@shaw.ca>
*
* BTW: I'm using #ifndef _region_name to ape .NET's #region directive.
* Geany's (the lightweight IDE I used for development) code folding
* handles it nicely and allows me to concentrate on just the section of
* code that I'm working on.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <iostream>
#include <sstream>
#include <vector>
#include <iomanip>
#include <stdlib.h>
#include <assert.h>
#include <locale.h>
#include <time.h>
#include <boost/regex.hpp>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include "mainWindow.h"
#include "csvReader.h"
using namespace std;
#ifndef _Constructor_Destructor
MainWindow::MainWindow()
{
m_initialized = false;
m_bSetsFiltered = false;
m_localeCurrencyCode = "";
m_baseCurrencyCode = "";
m_baseCurrencyRate = 0;
m_pricelistNumber = 0;
m_pricelistCurrencyRate = 0;
m_pricelistCurrencyCode = "";
m_collectionNumber = "";
m_collectionDescription = "";
m_collectionPartsCount = 0;
m_collectionCost = 0;
m_collectionViewPriceColumnIndex = 0;
m_partsViewPriceColumnIndex = 0;
m_toMakeCost = 0;
m_toMakeViewPriceColumnIndex = 0;
m_baseDir = Glib::build_filename(Glib::get_home_dir(),".mecparts");
// hook up to the database
m_pSql = new Sql(this,Glib::build_filename(m_baseDir,"Database","meccano.db"));
// Load the GtkBuilder file and instantiate its widgets
m_refBuilder = Gtk::Builder::create();
if( !m_refBuilder ) {
throw "null m_refBuilder";
}
try {
// look for the ui first in the directory containing the executable
// (used during debugging) and if it's not found, look in the usual
// base directory
string uiFile = "mecparts.ui";
if( !Glib::file_test(uiFile,Glib::FILE_TEST_EXISTS) ) {
uiFile = Glib::build_filename(m_baseDir,uiFile);
}
m_refBuilder->add_from_file(uiFile);
}
catch( const Glib::FileError &ex ) {
throw "FileError: "+ex.what();
}
catch(const Glib::MarkupError &ex) {
throw "MarkupError: "+ex.what();
}
catch( const Gtk::BuilderError &ex ) {
throw "BuilderError: "+ex.what();
}
// grab the mainWindow widget and hook up the window delete handler
GET_WIDGET(m_refBuilder,"mainWindow",m_pWindow)
m_pWindow->signal_delete_event().connect(sigc::mem_fun(*this,&MainWindow::on_delete));
// load the window size and position from the last run of the program
m_cfg.load_cfg();
int w,h;
m_cfg.get_mainWindow_size(w,h);
m_pWindow->set_default_size(w,h);
int x,y;
m_cfg.get_mainWindow_pos(x,y);
if( x != -1 && x != -1 ) {
m_pWindow->move(x,y);
}
m_refStyleContext = m_pWindow->get_style_context();
// zero prices will be shown in (usually, theme dependant) red
if( !(m_pWindow->get_style_context()->lookup_color("error_color",m_missingValueCellForeColor)) ) {
m_missingValueCellForeColor = Gdk::RGBA("red");
cout << "default error color" << endl;
}
// read only columns in tree views will get an inactive (usually grey, but theme dependant) background
m_readOnlyCellBackground = m_pWindow->get_style_context()->get_background_color(Gtk::STATE_FLAG_INSENSITIVE);
// set up the contents of each tab in the main window
CurrenciesSetup();
PricelistsSetup();
PartsSetup();
SetsSetup();
CollectionSetup();
ToMakeSetup();
// let all refresh/refill routines know that from now on they should run
// when called
m_initialized = true;
}
MainWindow::~MainWindow()
{
delete m_pWindow;
}
#endif
#ifndef _General_Routines
bool MainWindow::on_delete(GdkEventAny *e)
{
// save the main window position and size for the next program run
int width,height,x,y;
m_pWindow->get_size(width,height);
m_cfg.set_mainWindow_size(width,height);
m_pWindow->get_position(x,y);
m_cfg.set_mainWindow_pos(x,y);
m_cfg.set_collection_number(m_collectionNumber);
m_cfg.set_pricelist_number(m_pricelistNumber);
m_cfg.save_cfg();
return false;
}
// turn the wait cursor on or off
void MainWindow::WaitCursor(bool on)
{
Glib::RefPtr<Gdk::Window> refWindow = m_pWindow->get_window();
if( refWindow ) {
if( on ) {
Glib::RefPtr<Gdk::Cursor> waitCursor = Gdk::Cursor::create(Gdk::WATCH);
refWindow->set_cursor(waitCursor);
m_pWindow->set_sensitive(false);
} else {
refWindow->set_cursor();
m_pWindow->set_sensitive(true);
}
Gdk::flush();
while(Gtk::Main::events_pending()) {
Gtk::Main::iteration();
}
}
}
// change the background on all non editable columns
// I used to do this partially in the Glade file (for columns declared there)
// and partially in the various Setup functions (for columns added there). But
// Glade didn't know about the theme colours and so I'd picked a colour that
// matched *my* theme. Worked for me, maybe not for you. This way every non-
// editable text column gets the same colouring treatment, and its based on the
// theme.
void MainWindow::TagReadOnlyColumns(Gtk::TreeView *pTreeView)
{
guint numColumns = pTreeView->get_n_columns();
Glib::ustring editablePropertyName = "editable";
for( guint i=0; i<numColumns; ++i ) {
Gtk::CellRendererText *pTextCellRenderer = dynamic_cast<Gtk::CellRendererText *>(pTreeView->get_column_cell_renderer((int)i));
// I do have one combo box column in the pricelist, so when I hit it, I
// should get a null pointer out of the dynamic cast. Seems to work, anyhow.
if( pTextCellRenderer ) {
bool editable;
pTextCellRenderer->get_property(editablePropertyName,editable);
if( !editable ) {
// read-only, give it a different background. I went with the non
// sensitive background (i.e. a disabled widget's background)
pTextCellRenderer->property_background_rgba() = m_readOnlyCellBackground;
}
}
}
}
// utility routine to draw missing values (usually a zero price or quantity) in
// the theme's error colour
void MainWindow::DrawColumn(Gtk::CellRendererText *r,stringstream &text,Gtk::TreeView *t,bool missing)
{
// make sure that we've got a valid pointer
if( r ) {
// set the renderer's text
r->property_text() = text.str();
if( missing ) {
// missing values displayed in theme's error colour (usually red)
r->property_foreground_rgba() = m_missingValueCellForeColor;
} else {
// other values displayed in the theme's default foreground colour
Glib::RefPtr<Gtk::StyleContext> refStyleContext = t->get_style_context();
r->property_foreground_rgba() = refStyleContext->get_color(refStyleContext->get_state());
}
} else {
throw "null CellRendererText pointer passed to DrawColumn";
}
}
// Display a part. Look in the Pictures subdirectory (relative to where the executable is
// running from). Look for an image file named for the part with any of the following
// extensions: jpg, gif, png, bmp, jpeg, pxc, tif or tiff.
//
// If we find an image, it's scaled to fit into a 300x300 square.
void MainWindow::DisplayPicture(string partNumber,string description,string size,string notes)
{
static string imageExtensions[] = {".jpg",".gif",".png",".bmp",".jpeg",".pcx",".tif",".tiff"};
static int numImageExtensions = sizeof(imageExtensions)/sizeof(string);
Gtk::MessageDialog pictureDialog(*m_pWindow,partNumber,false,Gtk::MESSAGE_INFO,Gtk::BUTTONS_CLOSE);
if( !size.empty() ) {
pictureDialog.set_secondary_text(description+", "+size+"\n"+notes);
} else {
pictureDialog.set_secondary_text(description+"\n"+notes);
}
Gtk::Image *pImage = NULL;
bool foundFile = false;
for( int i=0; i<numImageExtensions; ++i ) {
string fileName = Glib::build_filename(m_baseDir,"Pictures",partNumber+imageExtensions[i]);
if( Glib::file_test(fileName,Glib::FILE_TEST_EXISTS) ) {
pImage = new Gtk::Image(Gdk::Pixbuf::create_from_file(fileName, 300, 300, true));
pictureDialog.set_image(*pImage);
foundFile = true;
break;
}
}
if( !foundFile ) {
pImage = new Gtk::Image(Gtk::Stock::MISSING_IMAGE,Gtk::ICON_SIZE_DIALOG);
pictureDialog.set_image(*pImage);
}
pImage->show();
pictureDialog.run();
delete pImage;
}
// Display a part drawing. Look in the Drawing subdirectory (relative to where the executable is
// running from). Look for an image file named for the part with a jpg extension.
// running from). Look for an image file named for the part with a jpg extension.
void MainWindow::DisplayDrawing(string partNumber)
{
string drawing = Glib::build_filename(m_baseDir,"Drawings",partNumber+".jpg");
if( Glib::file_test(drawing,Glib::FILE_TEST_EXISTS) ) {
vector<string> args;
args.push_back("/usr/bin/xdg-open");
args.push_back(drawing);
Glib::spawn_async("", args);
} else {
Gdk::Display::get_default()->beep();
}
}
#endif
#ifndef _Collection_Routines
// Collection tab setup: the Collection tab shows the contents of a set (ie a
// list of parts and the # of each part in the set). You can think of a collection
// as 'set parts' if it makes more sense to you. I just needed a name that
// differeniated a 'set' from the 'colleciton of parts in a set'.
//
// Possible future enhancements: printing the collection or exporting it to
// a csv file.
void MainWindow::CollectionSetup()
{
// set up a context menu on the collection view that pops up when the right mouse button is pressed
// this will be used to add parts, add sets or delete parts to/from the collection
GET_WIDGET(m_refBuilder,"collectionView",m_pCollectionView)
m_pCollectionView->signal_button_press_event().connect_notify(sigc::mem_fun(*this,&MainWindow::on_collection_button_pressed));
// total value of the parts in the collection
GET_WIDGET(m_refBuilder,"collectionCountCost",m_pCollectionCountCost);
// display collection manual
GET_WIDGET(m_refBuilder,"collectionManualButton",m_pCollectionManualButton);
m_pCollectionManualButton->signal_clicked().connect(sigc::mem_fun(*this,&MainWindow::on_collection_manual_button_clicked));
// the backing data store for the collection tree view
GET_OBJECT(m_refBuilder,"collectionStore",m_pCollectionStore,ListStore);
// add price, total columns and notes to the view. Glade doesn't have a nicely
// formatted numeric column so we add it manually.
m_collectionViewPriceColumnIndex = m_pCollectionView->append_column_numeric("Price",m_collectionStore.m_price,"%.2lf")-1;
m_pCollectionView->append_column_numeric("Total",m_collectionStore.m_total,"%.2lf");
int collectionViewNotesColumnIndex = m_pCollectionView->append_column_editable("Notes",m_collectionStore.m_notes)-1;
Gtk::CellRendererText *pCellRenderer;
GET_TEXT_RENDERER("collectionNotesCellRenderer",pCellRenderer,m_pCollectionView,collectionViewNotesColumnIndex);
pCellRenderer->set_property("editable",false);
m_pCollectionView->get_column(m_collectionStore.m_notes.index())->set_clickable(true);
// the number of each part present in the collection (editable)
GET_TEXT_RENDERER("collectionCountCellRenderer",m_pCollectionCountCellRenderer,m_pCollectionView,m_collectionStore.m_count.index())
m_pCollectionCountCellRenderer->signal_edited().connect(sigc::mem_fun(*this,&MainWindow::on_collection_count_edited));
// right align text
m_pCollectionCountCellRenderer->set_property("xalign",1.0);
// zero count will be shown in red
m_pCollectionView->get_column(m_collectionStore.m_count.index())->set_cell_data_func(*m_pCollectionCountCellRenderer,sigc::mem_fun(*this,&MainWindow::on_collection_count_column_drawn));
// the price of an individual part (non-editable in the collection view)
GET_TEXT_RENDERER("collectionPriceCellRenderer",m_pCollectionPriceCellRenderer,m_pCollectionView,m_collectionStore.m_price.index())
// right align column header
m_pCollectionView->get_column(m_collectionStore.m_price.index())->set_alignment(1.0);
// right align text
m_pCollectionPriceCellRenderer->set_property("xalign",1.0);
// zero prices will be shown in red
m_pCollectionView->get_column(m_collectionViewPriceColumnIndex)->set_cell_data_func(*m_pCollectionPriceCellRenderer,sigc::mem_fun(*this,&MainWindow::on_collection_price_column_drawn));
// the 'total value' of each part in the collection (cost of an individual
// part timex the count of this part in the collection)
GET_TEXT_RENDERER("collectionTotalCellRenderer",pCellRenderer,m_pCollectionView,m_collectionStore.m_total.index())
// right align column header
m_pCollectionView->get_column(m_collectionStore.m_total.index())->set_alignment(1.0);
// right align text
pCellRenderer->set_property("xalign",1.0);
// the collection combobox selector. Use the set description out of the
// sets data store in the drop down list and hook up an event on the
// selection changed event to list the newly chosen collection.
GET_WIDGET(m_refBuilder,"collectionSetComboBox",m_pCollectionSetComboBox);
m_pCollectionSetComboBox->pack_start(m_setsStore.m_description);
m_pCollectionSetComboBox->signal_changed().connect(sigc::mem_fun(*this,&MainWindow::on_collection_set_combobox_changed));
GET_WIDGET(m_refBuilder,"collectionScrolledWindow",m_pCollectionScrolledWindow);
// the view part/add part/add set/delete part popup menu for the collection
GET_WIDGET(m_refBuilder,"collectionContextMenu",m_pCollectionContextMenu)
// the view part popup menu item
GET_WIDGET(m_refBuilder,"collectionViewPartMenuItem",m_pCollectionViewPartMenuItem)
m_pCollectionViewPartMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_collectionViewPart_activated));
// the view drawing popup menu item
GET_WIDGET(m_refBuilder,"collectionViewDrawingMenuItem",m_pCollectionViewDrawingMenuItem)
m_pCollectionViewDrawingMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_collectionViewDrawing_activated));
// the add part popup menu item
GET_WIDGET(m_refBuilder,"collectionAddPartMenuItem",m_pCollectionAddPartMenuItem)
m_pCollectionAddPartMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_collectionAddPart_activated));
// the delete part popup menu item
GET_WIDGET(m_refBuilder,"collectionDeletePartMenuItem",m_pCollectionDeletePartMenuItem)
m_pCollectionDeletePartMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_collectionDeletePart_activated));
// the add set contents popup menu item
GET_WIDGET(m_refBuilder,"collectionAddSetMenuItem",m_pCollectionAddSetMenuItem)
m_pCollectionAddSetMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_collectionAddSet_activated));
GET_WIDGET(m_refBuilder,"collectionImportPartsMenuItem",m_pCollectionImportPartsMenuItem)
m_pCollectionImportPartsMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_collectionImportParts_activated));
// handle a click on the part number or part description column header
// (allows searching the collection on either the part number or description)
m_pCollectionView->get_column(m_collectionStore.m_partNumber.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_collection_partNumber_clicked));
m_pCollectionView->get_column(m_collectionStore.m_description.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_collection_description_clicked));
m_pCollectionView->get_column(m_collectionStore.m_size.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_collection_size_clicked));
m_pCollectionView->get_column(m_collectionStore.m_notes.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_collection_notes_clicked));
// change the background on all non editable columns
TagReadOnlyColumns(m_pCollectionView);
// select parts to add dialog
m_pSelectPartsDialog = new SelectPartsDialog(m_refBuilder,&m_cfg);
if( !m_pSelectPartsDialog ) {
throw "Could not get selectPartsDialog";
}
// select set to add dialog
m_pSelectSetDialog = new SelectSetDialog(m_refBuilder,&m_cfg);
if( !m_pSelectSetDialog ) {
throw "Could not get selectSetDialog";
}
// set the title of the part price column to the currently selected
// currency's code (which defaults to the current locale)
m_pCollectionView->get_column(m_collectionViewPriceColumnIndex)->set_title(m_baseCurrencyCode);
// select the last used collection to display
if( m_pSetsStore->children().size() > 0 ) {
string collectionNum= m_cfg.get_collection_number();
if( !collectionNum.empty() ) {
Gtk::TreeModel::Children setsRows = m_pSetsStore->children();
int setIndex = 0;
for( Gtk::TreeModel::iterator iter = setsRows.begin(); iter!= setsRows.end(); ++iter ) {
Gtk::TreeModel::Row setsRow = *iter;
string setNum = setsRow[m_setsStore.m_setNumber];
if( setNum == collectionNum ) {
m_pCollectionSetComboBox->set_active(setIndex);
break;
} else {
++setIndex;
}
}
} else {
// hmm. Couldn't find the last collection. Default to the first one.
m_pCollectionSetComboBox->set_active(0);
}
}
}
// show zero (ie not available or missing) parts in red
void MainWindow::on_collection_count_column_drawn(Gtk::CellRenderer *r,const Gtk::TreeModel::iterator &iter)
{
Gtk::TreeModel::Row row = *iter;
guint count = row[m_collectionStore.m_count];
stringstream temp;
temp << count;
DrawColumn(dynamic_cast<Gtk::CellRendererText *>(r),temp,m_pCollectionView,count==0);
}
// show zero (ie not available or missing) prices in red
void MainWindow::on_collection_price_column_drawn(Gtk::CellRenderer *r,const Gtk::TreeModel::iterator &iter)
{
Gtk::TreeModel::Row row = *iter;
double price = row[m_collectionStore.m_price];
stringstream temp;
temp << fixed << setprecision(2) << price;
DrawColumn(dynamic_cast<Gtk::CellRendererText *>(r),temp,m_pCollectionView,price==0.0);
}
// collection view context menu popup handler
void MainWindow::on_collection_button_pressed(GdkEventButton *pEvent)
{
// if right mouse button pressed
if( pEvent->type==GDK_BUTTON_PRESS && pEvent->button==GDK_BUTTON_SECONDARY ) {
// select the part (if any) under the cursor
Gtk::TreeModel::Path path;
if( m_pCollectionView->get_path_at_pos((int)pEvent->x,(int)pEvent->y,path) ) {
m_pCollectionView->set_cursor(path);
}
// view & delete are only active if there is a selected part
bool partSelected = m_pCollectionView->get_selection()->count_selected_rows() != 0;
m_pCollectionViewPartMenuItem->set_sensitive(partSelected);
m_pCollectionDeletePartMenuItem->set_sensitive(partSelected);
if( partSelected ) {
// view drawing only if it exists ###
Gtk::TreeModel::iterator iter = m_pCollectionView->get_selection()->get_selected();
if( iter ) {
Gtk::TreeModel::Row row = *iter;
string partNumber = row[m_collectionStore.m_partNumber];
string drawing = Glib::build_filename(m_baseDir,"Drawings",partNumber+".jpg");
m_pCollectionViewDrawingMenuItem->set_sensitive(Glib::file_test(drawing,Glib::FILE_TEST_EXISTS));
} else {
m_pCollectionViewDrawingMenuItem->set_sensitive(false);
}
} else {
m_pCollectionViewDrawingMenuItem->set_sensitive(false);
}
// show the popup menu
m_pCollectionContextMenu->popup(pEvent->button,pEvent->time);
}
}
// display a new collection
void MainWindow::on_collection_set_combobox_changed()
{
m_pCollectionStore->clear(); // empty the collection datastore of any previous list of parts
m_collectionPartsCount = 0; // zero parts and cost
m_collectionCost = 0;
m_pCollectionCountCost->set_text("");
m_pCollectionManualButton->set_sensitive(false);
// grab newly selected set
Gtk::TreeModel::iterator iter = m_pCollectionSetComboBox->get_active();
if(iter) {
Gtk::TreeModel::Row row = *iter;
if(row) {
// save collection # and description and fill the datastore
m_collectionNumber = row[m_setsStore.m_setNumber];
m_collectionDescription = row[m_setsStore.m_description];
// clear out the parts in the previously selected collection
if( m_pCollectionStore->children().size() > 0 ) {
m_pCollectionStore->clear();
m_collectionPartsCount = 0;
m_collectionCost = 0;
m_pCollectionCountCost->set_text("");
}
// select the parts from the current collection
stringstream cmd;
cmd
<< "SELECT p.rowid,p.num,p.description,p.size,sp.count,IFNULL(pp.price,0) price,"
<< "IFNULL(pp.price,0)*sp.count total,p.pnPrefix a,p.pnDigits b,p.pnSuffix c,p.notes "
<< "FROM parts p JOIN set_parts sp ON p.num=sp.part_num AND sp.set_num='" << m_collectionNumber <<"' "
<< "LEFT OUTER JOIN v_part_prices pp ON p.num=pp.part_num AND pp.pricelist_num=" << m_pricelistNumber
<< " ORDER BY p.pnPrefix,p.pnDigits,p.pnSuffix";
m_pSql->ExecQuery(&cmd, MainWindow::PopulateCollectionCallback);
// scroll to top of window on a new collection
m_pCollectionScrolledWindow->get_vadjustment()->set_value(0);
// update the total # of parts of cost of parts in the collection
stringstream temp;
temp << "# Parts: " << m_collectionPartsCount << " Total Cost: " << fixed << setprecision(2) << m_collectionCost;
m_pCollectionCountCost->set_text(temp.str());
string manual = Glib::build_filename(m_baseDir,"Manuals",m_collectionNumber+".pdf");
m_pCollectionManualButton->set_sensitive(Glib::file_test(manual,Glib::FILE_TEST_EXISTS));
}
}
}
// Display the manual associated with a collection.
// The manual PDF is looked for in ~/.mecparts/Manuals/[set #].pdf
void MainWindow::on_collection_manual_button_clicked()
{
string manual = Glib::build_filename(m_baseDir,"Manuals",m_collectionNumber+".pdf");
if( Glib::file_test(manual,Glib::FILE_TEST_EXISTS) ) {
vector<string> args;
args.push_back("/usr/bin/xdg-open");
args.push_back(manual);
Glib::spawn_async("", args);
} else {
Gdk::Display::get_default()->beep();
}
}
// Append a row to the collection and populate it. The sqlite3 library doesn't like calling a member
// function so this is actually a static function in MainWindow. Hence the necessity of grabbing
// a pointer to the mainWindow instance and referencing all member variables through it.
int MainWindow::PopulateCollectionCallback(void *wnd, int argc, char **argv, char **azColName)
{
MainWindow *pMainWindow = (MainWindow *)wnd;
gint64 rowId = atol(argv[0]);
string partNumber = argv[1];
string description = argv[2];
string size = argv[3];
guint count = atoi(argv[4]);
gdouble price = atof(argv[5]);
gdouble total = atof(argv[6]);
string pnPrefix = argv[7];
int pnDigits = atoi(argv[8]);
string pnSuffix = argv[9];
string notes = argv[10];
Gtk::TreeModel::Row row = *(pMainWindow->m_pCollectionStore->append());
row[pMainWindow->m_collectionStore.m_rowId] = rowId;
row[pMainWindow->m_collectionStore.m_partNumber] = partNumber;
row[pMainWindow->m_collectionStore.m_description] = description;
row[pMainWindow->m_collectionStore.m_size] = size;
row[pMainWindow->m_collectionStore.m_count] = count;
row[pMainWindow->m_collectionStore.m_price] = price;
row[pMainWindow->m_collectionStore.m_total] = total;
row[pMainWindow->m_collectionStore.m_pnPrefix] = pnPrefix;
row[pMainWindow->m_collectionStore.m_pnDigits] = pnDigits;
row[pMainWindow->m_collectionStore.m_pnSuffix] = pnSuffix;
row[pMainWindow->m_collectionStore.m_notes] = notes;
// update the collection parts count and cost
pMainWindow->m_collectionPartsCount += count;
pMainWindow->m_collectionCost += total;
return 0;
}
// display the currently selected part
void MainWindow::on_collectionViewPart_activated()
{
// fin the currently selected part
Gtk::TreeModel::iterator iter = m_pCollectionView->get_selection()->get_selected();
if( iter ) {
// grab its information
Gtk::TreeModel::Row row = *iter;
string partNumber = row[m_collectionStore.m_partNumber];
string description = row[m_collectionStore.m_description];
string size = row[m_collectionStore.m_size];
string notes = row[m_collectionStore.m_notes];
// and display it
DisplayPicture(partNumber,description,size,notes);
}
}
// display the currently selected part
void MainWindow::on_collectionViewDrawing_activated()
{
// fin the currently selected part
Gtk::TreeModel::iterator iter = m_pCollectionView->get_selection()->get_selected();
if( iter ) {
// grab its information
Gtk::TreeModel::Row row = *iter;
string partNumber = row[m_collectionStore.m_partNumber];
// and display it
DisplayDrawing(partNumber);
}
}
// add a part (or parts) to the current collection
void MainWindow::on_collectionAddPart_activated()
{
if( m_pSelectPartsDialog->Run() == Gtk::RESPONSE_OK ) {
m_pSelectPartsDialog->Hide();
WaitCursor(true);
// grab a list of the selected parts
Glib::RefPtr<Gtk::TreeSelection> pSelected = m_pSelectPartsDialog->Selected();
if( m_pSelectPartsDialog->SelectedCount() > 0 ) {
// add each selected part to the collection
pSelected->selected_foreach_iter(sigc::mem_fun(*this,&MainWindow::AddPartCallback));
}
CalculateCollectionTotals();
RefreshToMake();
WaitCursor(false);
} else {
m_pSelectPartsDialog->Hide();
}
}
// callback routine to add a part to the collection
void MainWindow::AddPartCallback(const Gtk::TreeModel::iterator &iter)
{
Gtk::TreeModel::Row partRow = *iter;
AddPartToCollection(partRow,0,false);
}
// Add a part to the current collection.
// partRow: a row from the parts datastore
// count: how many of the part to add
// updateExistingRow: true if we're expecting a corresponding part row to already
// exist in the collection, false otherwise
// returns TRUE if inserted, FALSE if updated
bool MainWindow::AddPartToCollection(Gtk::TreeModel::Row partRow,int count,bool updateExistingRow)
{
// grab the relevant info from the selected part
string partNumber = partRow[m_partsStore.m_partNumber];
string partRowPrefix = partRow[m_partsStore.m_pnPrefix];
int partRowDigits = partRow[m_partsStore.m_pnDigits];
string partRowSuffix = partRow[m_partsStore.m_pnSuffix];
// prepare to search the collection datastore
Gtk::TreeModel::Children rows = m_pCollectionStore->children();
// assume a new row was not inserted in the middle of the collection
bool inserted = false;
Gtk::TreeModel::Row newRow;
// look for an existing row or find the proper insertion point
for( Gtk::TreeModel::iterator r = rows.begin(); r != rows.end(); ++r ) {
Gtk::TreeModel::Row row = *r;
string collectionPartNumber = row[m_collectionStore.m_partNumber];
if( partNumber == collectionPartNumber ) {
// found the part in the collection
if( updateExistingRow ) {
// we expected to find an existing row and did
// so add the count and update the total price of the parts in the collection
row[m_collectionStore.m_count] = row[m_collectionStore.m_count]+count;
row[m_collectionStore.m_total] = row[m_collectionStore.m_count]*row[m_collectionStore.m_price];
stringstream sql;
string partNumber = partRow[m_partsStore.m_partNumber];
// update the database
sql << "UPDATE set_parts SET count=count+" << count << " WHERE set_num='" << m_pSql->Escape(m_collectionNumber) << "' AND part_num='" << m_pSql->Escape(partNumber) << "'";
m_pSql->ExecNonQuery(&sql);
} else {
// if we weren't expecting to find an existing part (ie when we're
// adding a part from the 'Add Part' menu), do nothing. This prevents
// part duplication in the collection due to chair-keyboard interface
// issues.
}
return FALSE; // part updated
} else {
// see if we're at the right point to insert the new part
string collectionRowPrefix = row[m_collectionStore.m_pnPrefix];
int collectionRowDigits = row[m_collectionStore.m_pnDigits];
string collectionRowSuffix = row[m_collectionStore.m_pnSuffix];
if( partRowPrefix < collectionRowPrefix || (partRowPrefix == collectionRowPrefix && partRowDigits < collectionRowDigits) || (partRowPrefix==collectionRowPrefix && partRowDigits==collectionRowDigits && partRowSuffix < collectionRowSuffix) ) {
// create a new row at the insertion and break out of the search loop
newRow = *(m_pCollectionStore->insert(r));
inserted = true;
break;
}
}
}
// if we didn't find the insertion point, add the new part at the end of the
// collection
if( !inserted ) {
newRow = *(m_pCollectionStore->append());
}
// populate the part data in the collection datastore
// use a temp string variable to assign datastore values to other
// datastore values. Trying to do it direct just doesn't work.
string temp;
newRow[m_collectionStore.m_partNumber] = temp = partRow[m_partsStore.m_partNumber];
newRow[m_collectionStore.m_description] = temp = partRow[m_partsStore.m_description];
newRow[m_collectionStore.m_size] = temp = partRow[m_partsStore.m_size];
newRow[m_collectionStore.m_notes] = temp = partRow[m_partsStore.m_notes];
newRow[m_collectionStore.m_count] = count;
// use a temp numeric variable to assign datastore values to other
// datastore values. Trying to do it direct just doesn't work.
double price;
newRow[m_collectionStore.m_price] = price = partRow[m_partsStore.m_price];
newRow[m_collectionStore.m_total] = price * count;
newRow[m_collectionStore.m_pnPrefix] = partRowPrefix;
newRow[m_collectionStore.m_pnDigits] = partRowDigits;
newRow[m_collectionStore.m_pnSuffix] = partRowSuffix;
// insert the new part into the set in the database
stringstream sql;
sql
<< "INSERT INTO set_parts(set_num,part_num,count) VALUES ('"
<< m_pSql->Escape(m_collectionNumber) << "','"
<< m_pSql->Escape(partNumber) << "'," << count << ")";
newRow[m_collectionStore.m_rowId] = m_pSql->ExecInsert(&sql);
return TRUE; // inserted
}
// delete a part from the collection
void MainWindow::on_collectionDeletePart_activated()
{
// find the currently selected part
Gtk::TreeModel::iterator iter = m_pCollectionView->get_selection()->get_selected();
if( iter ) {
// make sure!
Gtk::MessageDialog areYouSure(*m_pWindow,"Are you sure?",false,Gtk::MESSAGE_QUESTION,Gtk::BUTTONS_OK_CANCEL);
Gtk::TreeModel::Row row = *iter;
string partNum = row[m_collectionStore.m_partNumber];
string partDescription = row[m_collectionStore.m_description];
areYouSure.set_secondary_text("Delete part # "+partNum+" ("+partDescription+") from collection \""+m_collectionDescription+"\"?");
if( areYouSure.run() == Gtk::RESPONSE_OK ) {
// remove from the datastore
m_pCollectionStore->erase(iter);
// and remove from the database
stringstream sql;
sql
<< "DELETE FROM set_parts WHERE part_num='" << m_pSql->Escape(partNum)
<< "' AND set_num='" << m_pSql->Escape(m_collectionNumber) << "'";
m_pSql->ExecNonQuery(&sql);
// update the collection totals and refresh the to make contents
CalculateCollectionTotals();
RefreshToMake();
}
}
}
// add the entire contents of another set(s) to the current collection
void MainWindow::on_collectionAddSet_activated()
{
if( m_pSelectSetDialog->Run() == Gtk::RESPONSE_OK ) {
// they've approved the addition, go to it
m_pSelectSetDialog->Hide();
WaitCursor(true);
// get the selected set
Glib::RefPtr<Gtk::TreeSelection> pSelected = m_pSelectSetDialog->Selected();
// and add each part from it to the current collection
if( m_pSelectSetDialog->SelectedCount() > 0 ) {
pSelected->selected_foreach_iter(sigc::mem_fun(*this,&MainWindow::AddSetPartsCallback));
}
// update the parts count and total cost
CalculateCollectionTotals();
RefreshToMake();
WaitCursor(false);
} else {
m_pSelectSetDialog->Hide();
}
}
// called for each set to be added
void MainWindow::AddSetPartsCallback(const Gtk::TreeModel::iterator &iter)
{
// get the set number to add
Gtk::TreeModel::Row setRow = *iter;
string setNumber = setRow[m_setsStore.m_setNumber];
// clear out the set's part list map
m_partsList.clear();
// select the part # for part count list
stringstream sql;
sql << "SELECT part_num,count FROM set_parts WHERE set_num='" << m_pSql->Escape(setNumber) << "'";
m_pSql->ExecQuery(&sql,MainWindow::AddSetPartCallback);
// for each part in the set
for( map<string,int>::iterator iter=m_partsList.begin(); iter!=m_partsList.end(); ++iter ) {
string partNumber = (*iter).first;
int count = (*iter).second;
// search for the part in the parts datastore
Gtk::TreeModel::Row partRow;
if( PartExists(partNumber,partRow) ) {
// found the part, add it to the collection, and allow
// for the counts of existing parts in the collection
// to be updated
AddPartToCollection(partRow,count,true);
}
}
}
void MainWindow::on_collectionImportParts_activated()
{
// get a csv file
int response = m_pImportFileChooserDialog->run();
m_pImportFileChooserDialog->hide();
if( response == Gtk::RESPONSE_OK ) {
// grab the csv file name
if( !m_pImportFileChooserDialog->get_filename().empty() ) {
// set up to read the csv file
CsvReader reader(m_pImportFileChooserDialog->get_filename());
vector<string> fields;
WaitCursor(true);
int numUpdated = 0; // # of part prices updated
int numInserted = 0; // # of part prices inserted
vector<string> unknownPartNumbers; // part numbers not found in database
while( reader.Parse(fields) ) {
// some basic data checking: 2, and only 2, non empty fields
if( fields.size() == 2 && !fields[0].empty() && !fields[1].empty() ) {
int count = atoi(fields[1].c_str());
string num = fields[0];
Gtk::TreeModel::Row partRow;
if( PartExists(num,partRow) ) {
if ( AddPartToCollection(partRow,count,true) ) {
++numInserted;
} else {
++numUpdated;
}
} else {
unknownPartNumbers.push_back(num);
}
}
}
WaitCursor(false);
CalculateCollectionTotals();
RefreshToMake();
// show the import results
m_pImportResultDialog->Run(numInserted,numUpdated,unknownPartNumbers);
m_pImportResultDialog->Hide();
}
}
}
int MainWindow::AddSetPartCallback(void *wnd,int argc,char **argv, char **azColName)
{
MainWindow *pMainWindow = (MainWindow *)wnd;
pMainWindow->m_partsList[argv[0]] = atoi(argv[1]);
return 0;
}
// set up searching on the part # column when the part # column header is clicked
void MainWindow::on_collection_partNumber_clicked()
{
m_pCollectionView->set_search_column(m_collectionStore.m_partNumber.index());
m_pCollectionView->grab_focus();
}
// set up searching on the part description column when the part description column header is clicked
void MainWindow::on_collection_description_clicked()
{
m_pCollectionView->set_search_column(m_collectionStore.m_description.index());
m_pCollectionView->grab_focus();
}
void MainWindow::on_collection_size_clicked()
{
m_pCollectionView->set_search_column(m_collectionStore.m_size.index());
m_pCollectionView->grab_focus();
}
void MainWindow::on_collection_notes_clicked()
{
m_pCollectionView->set_search_column(m_collectionStore.m_notes.index());
m_pCollectionView->grab_focus();
}
// When a part's count is edited, update the count in the datastore and calculate
// the new total and update that in the datastore as well. Then update the
// parts count in the database and recalculate the collection totals. Finally,
// update the "To Make" tab info on the chance that the part we've updated is
// in the "to make" set.
void MainWindow::on_collection_count_edited(Glib::ustring pathStr, Glib::ustring text)
{
GET_ITER(iter,m_pCollectionStore,pathStr)
// grab the new count
int count = atoi(text.c_str());
// grab the part price and number
double price = (*iter)[m_collectionStore.m_price];
string num = (*iter)[m_collectionStore.m_partNumber];
// update the count and total in the datastore
(*iter)[m_collectionStore.m_count] = count;
(*iter)[m_collectionStore.m_total] = count * price;
// update the count in the database
stringstream sql;
sql
<< "UPDATE set_parts SET count=" << count
<< " WHERE part_num='" << m_pSql->Escape(num)
<< "' AND set_num='" << m_pSql->Escape(m_collectionNumber) << "'";
m_pSql->ExecNonQuery(&sql);
// recalculate the collection parts count and cost
CalculateCollectionTotals();
// update the to make tab info
RefreshToMake();
}
// iterate through the parts in the collection datastore to update the
// parts count and cost
void MainWindow::CalculateCollectionTotals()
{
Gtk::TreeModel::Children rows = m_pCollectionStore->children();
m_collectionPartsCount = 0;
m_collectionCost = 0;
for( Gtk::TreeModel::iterator r = rows.begin(); r != rows.end(); ++r ) {
Gtk::TreeModel::Row row = *r;
m_collectionPartsCount += row[m_collectionStore.m_count];
m_collectionCost += row[m_collectionStore.m_total];
}
stringstream temp;
temp << "# Parts: " << m_collectionPartsCount << " Total Cost: " << fixed << setprecision(2) << m_collectionCost;
m_pCollectionCountCost->set_text(temp.str());
}
#endif
#ifndef _Parts_Routines
// Parts tab setup: the Parts tab shows the parts list.
void MainWindow::PartsSetup()
{
// parts datastore
GET_OBJECT(m_refBuilder,"partsStore",m_pPartsStore,ListStore)
// parts treeview. Append an editable numeric column for the part price
// and an editable text column for the notes. Oh, c'mon Glade! :(
GET_WIDGET(m_refBuilder,"partsView",m_pPartsView)
// parts price: why not just use append_column_numeric_editable? Because that
// includes code that updates the liststore automatically. And I want a chance
// to vet the data first!
m_partsViewPriceColumnIndex = m_pPartsView->append_column_numeric("Price",m_partsStore.m_price,"%.2lf")-1;
m_pPartsView->append_column_editable("Notes",m_partsStore.m_notes);
GET_TEXT_RENDERER("partsPriceCellRenderer",m_pPartsPriceCellRenderer,m_pPartsView,m_partsStore.m_price.index())
m_pPartsPriceCellRenderer->set_property("editable",true);
m_pPartsPriceCellRenderer->signal_edited().connect(sigc::mem_fun(*this,&MainWindow::on_parts_price_edited));
// right align text
m_pPartsPriceCellRenderer->set_property("xalign",1.0);
// right align column header
m_pPartsView->get_column(m_partsViewPriceColumnIndex)->set_alignment(1.0);
m_pPartsView->get_column(m_partsViewPriceColumnIndex)->set_cell_data_func(*m_pPartsPriceCellRenderer,sigc::mem_fun(*this,&MainWindow::on_parts_price_column_drawn));
// set the title of the part price column to the currently selected
// currency's code (which defaults to the current locale)
m_pPartsView->get_column(m_partsViewPriceColumnIndex)->set_title(m_baseCurrencyCode);
// part description
Gtk::CellRendererText *pCellRenderer;
GET_TEXT_RENDERER("partsDescriptionCellRenderer",pCellRenderer,m_pPartsView,m_partsStore.m_description.index())
pCellRenderer->signal_edited().connect(sigc::mem_fun(*this,&MainWindow::on_parts_description_edited));
// parts size. Essentially more description
GET_TEXT_RENDERER("partsSizeCellRenderer",pCellRenderer,m_pPartsView,m_partsStore.m_size.index())
pCellRenderer->signal_edited().connect(sigc::mem_fun(*this,&MainWindow::on_parts_size_edited));
// parts notes
GET_TEXT_RENDERER("partsNotesCellRenderer",pCellRenderer,m_pPartsView,m_partsStore.m_notes.index())
pCellRenderer->signal_edited().connect(sigc::mem_fun(*this,&MainWindow::on_parts_notes_edited));
m_pPartsView->get_column(m_partsStore.m_notes.index())->set_clickable(true);
// parts view popup context menu
m_pPartsView->signal_button_press_event().connect_notify(sigc::mem_fun(*this,&MainWindow::on_parts_button_pressed));
// allow searching on part number or part description
m_pPartsView->get_column(m_partsStore.m_partNumber.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_parts_partNumber_clicked));
m_pPartsView->get_column(m_partsStore.m_description.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_parts_description_clicked));
m_pPartsView->get_column(m_partsStore.m_size.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_parts_size_clicked));
m_pPartsView->get_column(m_partsStore.m_notes.index())->signal_clicked().connect_notify(sigc::mem_fun(*this,&MainWindow::on_parts_notes_clicked));
// parts context menu
GET_WIDGET(m_refBuilder,"partsContextMenu",m_pPartsContextMenu)
GET_WIDGET(m_refBuilder,"partsViewPartMenuItem",m_pPartsViewPartMenuItem)
m_pPartsViewPartMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_partsViewPart_activated));
GET_WIDGET(m_refBuilder,"partsViewDrawingMenuItem",m_pPartsViewDrawingMenuItem)
m_pPartsViewDrawingMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_partsViewDrawing_activated));
// create new part menu item
GET_WIDGET(m_refBuilder,"partsNewPartMenuItem",m_pPartsNewPartMenuItem)
m_pPartsNewPartMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_partsNewPart_activated));
// delete part menu item
GET_WIDGET(m_refBuilder,"partsDeletePartMenuItem",m_pPartsDeletePartMenuItem)
m_pPartsDeletePartMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_partsDeletePart_activated));
// filter sets on part (only show sets containing this part)
GET_WIDGET(m_refBuilder,"partsFilterSetsMenuItem",m_pPartsFilterSetsMenuItem)
m_pPartsFilterSetsMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_partsFilterSets_activated));
// remove part filter
GET_WIDGET(m_refBuilder,"partsUnfilterSetsMenuItem",m_pPartsUnfilterSetsMenuItem)
m_pPartsUnfilterSetsMenuItem->signal_activate().connect(sigc::mem_fun(*this,&MainWindow::on_partsUnfilterSets_activated));
// change the background on all non editable columns
TagReadOnlyColumns(m_pPartsView);
// create a new part dialog
m_pNewPartDialog = new NewPartDialog(m_refBuilder);
if( !m_pNewPartDialog ) {
throw "Could not get newPartDialog";
}
// fill the parts liststore
stringstream cmd;
cmd
<< "SELECT p.rowid,p.num,p.description,p.size,IFNULL(pp.price,0) price,"
<< "p.notes,p.pnPrefix a,p.pnDigits b,p.pnSuffix c "
<< "FROM parts p LEFT OUTER JOIN v_part_prices pp ON p.num=pp.part_num AND pp.pricelist_num=" << m_pricelistNumber
<< " ORDER BY p.pnPrefix,p.pnDigits,p.pnSuffix";