1 // File: QtxResourceEditor.cxx
3 // Author: Sergey TELKOV
6 #include "QtxResourceEditor.h"
9 Class: QtxResourceEditor::Item
10 Descr: Class for incapsulation of one preference item
13 //=======================================================================
16 //=======================================================================
18 QtxResourceEditor::Item::Item( QtxResourceEditor* ed )
25 //=======================================================================
28 //=======================================================================
30 QtxResourceEditor::Item::~Item()
34 //=======================================================================
37 //=======================================================================
39 int QtxResourceEditor::Item::GetId() const
44 //=======================================================================
47 //=======================================================================
49 int QtxResourceEditor::Item::GetType() const
54 //=======================================================================
57 //=======================================================================
59 void QtxResourceEditor::Item::Set( const QString& sect, const QString& name,
60 const int type, const QString& label )
68 //=======================================================================
71 //=======================================================================
73 QString QtxResourceEditor::Item::Get( QString& name, int& type, QString& label ) const
81 //=======================================================================
84 //=======================================================================
86 void QtxResourceEditor::Item::SetList( const QValueList<int>&, const QStringList& )
90 //=======================================================================
93 //=======================================================================
95 void QtxResourceEditor::Item::SetRange( const double, const double, const double, const double )
99 //=======================================================================
101 //purpose : default implementation do nothing
102 //=======================================================================
104 void QtxResourceEditor::Item::Update()
108 //=======================================================================
111 //=======================================================================
113 bool QtxResourceEditor::Item::GetInteger( const QString& sect, const QString& name, int& val ) const
115 bool ok = resMgr() && resMgr()->hasValue( sect, name );
117 val = resMgr()->integerValue( sect, name );
121 //=======================================================================
124 //=======================================================================
126 bool QtxResourceEditor::Item::GetBoolean( const QString& sect, const QString& name, bool& val ) const
128 bool ok = resMgr() && resMgr()->hasValue( sect, name );
130 val = resMgr()->booleanValue( sect, name );
134 //=======================================================================
137 //=======================================================================
139 bool QtxResourceEditor::Item::GetDouble( const QString& sect, const QString& name, double& val ) const
141 bool ok = resMgr() && resMgr()->hasValue( sect, name );
143 val = resMgr()->doubleValue( sect, name );
147 //=======================================================================
150 //=======================================================================
152 bool QtxResourceEditor::Item::GetString( const QString& sect, const QString& name, QString& val ) const
154 bool ok = resMgr() && resMgr()->hasValue( sect, name );
156 val = resMgr()->stringValue( sect, name );
160 //=======================================================================
163 //=======================================================================
165 bool QtxResourceEditor::Item::GetColor( const QString& sect, const QString& name, QColor& val ) const
167 bool ok = resMgr() && resMgr()->hasValue( sect, name );
169 val = resMgr()->colorValue( sect, name );
173 //=======================================================================
176 //=======================================================================
178 void QtxResourceEditor::Item::SetInteger( const QString& sect, const QString& name, const int val )
181 resMgr()->setValue( sect, name, val );
184 //=======================================================================
187 //=======================================================================
189 void QtxResourceEditor::Item::SetBoolean( const QString& sect, const QString& name, const bool val )
192 resMgr()->setValue( sect, name, val );
195 //=======================================================================
198 //=======================================================================
200 void QtxResourceEditor::Item::SetDouble( const QString& sect, const QString& name, const double val )
203 resMgr()->setValue( sect, name, val );
206 //=======================================================================
209 //=======================================================================
211 void QtxResourceEditor::Item::SetString( const QString& sect, const QString& name, const QString& val )
214 resMgr()->setValue( sect, name, val );
217 //=======================================================================
220 //=======================================================================
222 void QtxResourceEditor::Item::SetColor( const QString& sect, const QString& name, const QColor& val )
225 resMgr()->setValue( sect, name, val );
228 //=======================================================================
231 //=======================================================================
233 QtxResourceMgr* QtxResourceEditor::Item::resMgr() const
235 return myEditor ? myEditor->resMgr() : NULL;
239 Class: QtxResourceEditor::Group
240 Descr: Class for incapsulation of one group of preferences.
243 //=======================================================================
246 //=======================================================================
248 QtxResourceEditor::Group::Group( const QString& theName )
253 //=======================================================================
256 //=======================================================================
258 QtxResourceEditor::Group::~Group()
262 //=======================================================================
265 //=======================================================================
267 QString QtxResourceEditor::Group::GetName() const
272 //=======================================================================
275 //=======================================================================
277 void QtxResourceEditor::Group::SetName( const QString& name )
282 //=======================================================================
285 //=======================================================================
287 int QtxResourceEditor::Group::Add( const QString& sect, const QString& name,
288 const int type, const QString& label )
291 Item* item = createItem( type, label );
294 item->Set( sect, name, type, label );
295 myItems.append( item );
301 //=======================================================================
304 //=======================================================================
306 bool QtxResourceEditor::Group::IsExist( const int id ) const
309 for ( QPtrListIterator<Item> it( myItems ); it.current() && !res; ++it )
310 if ( it.current()->GetId() == id )
315 //=======================================================================
318 //=======================================================================
320 void QtxResourceEditor::Group::SetList( const int id, const QValueList<int>& ids,
321 const QStringList& names )
323 Item* item = getItem( id );
325 item->SetList( ids, names );
328 //=======================================================================
329 //function : SetRange
331 //=======================================================================
333 void QtxResourceEditor::Group::SetRange( const int id, const double min, const double max,
334 const double prec, const double step )
336 Item* item = getItem( id );
338 item->SetRange( min, max, prec, step );
341 //=======================================================================
342 //function : SetColumns
344 //=======================================================================
346 void QtxResourceEditor::Group::SetColumns( const int )
350 //=======================================================================
351 //function : SetTitle
353 //=======================================================================
355 void QtxResourceEditor::Group::SetTitle( const QString& )
359 //=======================================================================
362 //=======================================================================
364 void QtxResourceEditor::Group::Store()
366 for ( QPtrListIterator<Item> it( myItems ); it.current(); ++it )
367 it.current()->Store();
370 //=======================================================================
371 //function : Retrieve
373 //=======================================================================
375 void QtxResourceEditor::Group::Retrieve()
377 for ( QPtrListIterator<Item> it( myItems ); it.current(); ++it )
378 it.current()->Retrieve();
381 //=======================================================================
383 //purpose : default implementation invoke update of all items
384 //=======================================================================
386 void QtxResourceEditor::Group::Update()
388 for ( QPtrListIterator<Item> it( myItems ); it.current(); ++it )
389 it.current()->Update();
392 //=======================================================================
395 //=======================================================================
397 QtxResourceEditor::Item* QtxResourceEditor::Group::getItem( const int id ) const
400 for ( QPtrListIterator<Item> it( myItems ); it.current() && !anItem; ++it )
401 if ( it.current()->GetId() == id )
402 anItem = it.current();
407 Class: QtxResourceEditor::Tab
408 Descr: Class for incapsulation of one tab of preferences.
411 //=======================================================================
414 //=======================================================================
416 QtxResourceEditor::Tab::Tab( const QString& name )
421 //=======================================================================
424 //=======================================================================
426 QtxResourceEditor::Tab::~Tab()
430 //=======================================================================
433 //=======================================================================
435 int QtxResourceEditor::Tab::Add( const QString& group, const QString& sect,
436 const QString& name, const int type, const QString& label )
438 Group* aGroup = getGroup( group );
441 aGroup = createGroup( group );
442 myGroups.append( aGroup );
446 return aGroup->Add( sect, name, type, label );
451 //=======================================================================
454 //=======================================================================
456 QString QtxResourceEditor::Tab::GetName() const
461 //=======================================================================
464 //=======================================================================
466 void QtxResourceEditor::Tab::SetList( const int id, const QValueList<int>& ids,
467 const QStringList& names )
470 if ( IsExist( id, group ) )
472 Group* aGroup = getGroup( group );
474 aGroup->SetList( id, ids, names );
478 //=======================================================================
479 //function : SetRange
481 //=======================================================================
483 void QtxResourceEditor::Tab::SetRange( const int id, const double min, const double max,
484 const double prec, const double step )
487 if ( IsExist( id, group ) )
489 Group* aGroup = getGroup( group );
491 aGroup->SetRange( id, min, max, prec, step );
495 //=======================================================================
496 //function : getGroup
498 //=======================================================================
500 bool QtxResourceEditor::Tab::IsExist( const int id, QString& group ) const
503 for ( QPtrListIterator<Group> it( myGroups ); it.current() && !aGroup; ++it )
504 if ( it.current()->IsExist( id ) )
505 aGroup = it.current();
508 group = aGroup->GetName();
513 //=======================================================================
514 //function : SetColumns
516 //=======================================================================
518 void QtxResourceEditor::Tab::SetColumns( const QString& group, const int cols )
520 Group* aGroup = getGroup( group );
522 aGroup->SetColumns( cols );
525 //=======================================================================
526 //function : SetTitle
528 //=======================================================================
530 void QtxResourceEditor::Tab::SetTitle( const QString& )
534 //=======================================================================
535 //function : SetTitle
537 //=======================================================================
539 void QtxResourceEditor::Tab::SetTitle( const QString& title, const QString& group )
541 Group* aGroup = getGroup( group );
543 aGroup->SetTitle( title );
546 //=======================================================================
549 //=======================================================================
551 void QtxResourceEditor::Tab::Store()
553 for ( QPtrListIterator<Group> it( myGroups ); it.current(); ++it )
554 it.current()->Store();
557 //=======================================================================
558 //function : Retrieve
560 //=======================================================================
562 void QtxResourceEditor::Tab::Retrieve()
564 for ( QPtrListIterator<Group> it( myGroups ); it.current(); ++it )
565 it.current()->Retrieve();
568 //=======================================================================
570 //purpose : default implementation invoke update of all groups
571 //=======================================================================
573 void QtxResourceEditor::Tab::Update()
575 for ( QPtrListIterator<Group> it( myGroups ); it.current(); ++it )
576 it.current()->Update();
579 //=======================================================================
580 //function : getGroup
582 //=======================================================================
584 QtxResourceEditor::Group* QtxResourceEditor::Tab::getGroup( const QString& name ) const
587 for ( QPtrListIterator<Group> it( myGroups ); it.current() && !aGroup; ++it )
588 if ( it.current()->GetName() == name )
589 aGroup = it.current();
594 Class: QtxResourceEditor::Category
595 Descr: Class for incapsulation of one tab widget of preferences.
598 //=======================================================================
599 //function : Category
601 //=======================================================================
603 QtxResourceEditor::Category::Category( const QString& name )
608 //=======================================================================
609 //function : ~Category
611 //=======================================================================
613 QtxResourceEditor::Category::~Category()
617 //=======================================================================
620 //=======================================================================
622 int QtxResourceEditor::Category::Add( const QString& tab, const QString& group,
623 const QString& sect, const QString& name,
624 const int type, const QString& label )
626 Tab* aTab = getTab( tab );
629 aTab = createTab( tab );
630 myTabs.append( aTab );
634 return aTab->Add( group, sect, name, type, label );
639 //=======================================================================
642 //=======================================================================
644 QString QtxResourceEditor::Category::GetName() const
649 //=======================================================================
652 //=======================================================================
654 void QtxResourceEditor::Category::SetList( const int id, const QValueList<int>& ids,
655 const QStringList& names )
658 if ( IsExist( id, tab, group ) )
660 Tab* aTab = getTab( tab );
662 aTab->SetList( id, ids, names );
666 //=======================================================================
667 //function : SetRange
669 //=======================================================================
671 void QtxResourceEditor::Category::SetRange( const int id, const double min, const double max,
672 const double prec, const double step )
675 if ( IsExist( id, tab, group ) )
677 Tab* aTab = getTab( tab );
679 aTab->SetRange( id, min, max, prec, step );
683 //=======================================================================
684 //function : getGroup
686 //=======================================================================
688 bool QtxResourceEditor::Category::IsExist( const int id, QString& tab, QString& group ) const
691 for ( QPtrListIterator<Tab> it( myTabs ); it.current() && !aTab; ++it )
692 if ( it.current()->IsExist( id, group ) )
696 tab = aTab->GetName();
701 //=======================================================================
702 //function : SetColumns
704 //=======================================================================
706 void QtxResourceEditor::Category::SetColumns( const QString& tab, const QString& group, const int cols )
708 Tab* aTab = getTab( tab );
710 aTab->SetColumns( group, cols );
713 //=======================================================================
714 //function : SetTitle
716 //=======================================================================
718 void QtxResourceEditor::Category::SetTitle( const QString& )
722 //=======================================================================
723 //function : SetTitle
725 //=======================================================================
727 void QtxResourceEditor::Category::SetTitle( const QString& title, const QString& tab )
729 Tab* aTab = getTab( tab );
731 aTab->SetTitle( title );
734 //=======================================================================
735 //function : SetTitle
737 //=======================================================================
739 void QtxResourceEditor::Category::SetTitle( const QString& title, const QString& tab, const QString& group )
741 Tab* aTab = getTab( tab );
743 aTab->SetTitle( title, group );
746 //=======================================================================
749 //=======================================================================
751 void QtxResourceEditor::Category::Store()
753 for ( QPtrListIterator<Tab> it( myTabs ); it.current(); ++it )
754 it.current()->Store();
757 //=======================================================================
758 //function : Retrieve
760 //=======================================================================
762 void QtxResourceEditor::Category::Retrieve()
764 for ( QPtrListIterator<Tab> it( myTabs ); it.current(); ++it )
765 it.current()->Retrieve();
768 //=======================================================================
770 //purpose : default implementation invoke update of all groups
771 //=======================================================================
773 void QtxResourceEditor::Category::Update()
775 for ( QPtrListIterator<Tab> it( myTabs ); it.current(); ++it )
776 it.current()->Update();
779 //=======================================================================
782 //=======================================================================
784 QtxResourceEditor::Tab* QtxResourceEditor::Category::getTab( const QString& name ) const
787 for ( QPtrListIterator<Tab> it( myTabs ); it.current() && !aTab; ++it )
788 if ( it.current()->GetName() == name )
794 Class: QtxResourceEditor
795 Descr: Class for managing preferences items, also container of tabs
798 //=======================================================================
799 //function : QtxResourceEditor
801 //=======================================================================
803 QtxResourceEditor::QtxResourceEditor( QtxResourceMgr* mgr )
808 //=======================================================================
809 //function : ~QtxResourceEditor
811 //=======================================================================
813 QtxResourceEditor::~QtxResourceEditor()
817 //=======================================================================
818 //function : GenerateId
820 //=======================================================================
822 int QtxResourceEditor::GenerateId()
828 //=======================================================================
831 //=======================================================================
833 int QtxResourceEditor::Add( const QString& cat, const QString& tab,
834 const QString& group, const QString& sect,
835 const QString& name, const int type, const QString& label )
837 Category* aCat = getCategory( cat );
840 aCat = createCategory( cat );
841 myCategories.append( aCat );
843 return aCat->Add( tab, group, sect, name, type, label );
846 //=======================================================================
849 //=======================================================================
851 bool QtxResourceEditor::IsExist( const int id, QString& cat,
852 QString& tab, QString& group ) const
855 for ( QPtrListIterator<Category> it( myCategories ); it.current() && !aCat; ++it )
856 if ( it.current()->IsExist( id, tab, group ) )
860 cat = aCat->GetName();
865 //=======================================================================
868 //=======================================================================
870 void QtxResourceEditor::SetList( const int id, const QValueList<int>& ids, const QStringList& names )
872 QString cat, tab, group;
873 if ( IsExist( id, cat, tab, group ) )
875 Category* aCat = getCategory( cat );
877 aCat->SetList( id, ids, names );
881 //=======================================================================
882 //function : SetRange
884 //=======================================================================
886 void QtxResourceEditor::SetRange( const int id, const double min, const double max,
887 const double prec, const double step )
889 QString cat, tab, group;
890 if ( IsExist( id, cat, tab, group ) )
892 Category* aCat = getCategory( cat );
894 aCat->SetRange( id, min, max, prec, step );
898 //=======================================================================
899 //function : SetColumns
901 //=======================================================================
903 void QtxResourceEditor::SetColumns( const QString& cat, const QString& tab,
904 const QString& group, const int cols )
906 Category* aCat = getCategory( cat );
908 aCat->SetColumns( tab, group, cols );
911 //=======================================================================
912 //function : SetTitle
914 //=======================================================================
916 void QtxResourceEditor::SetTitle( const QString& title, const QString& cat )
918 Category* aCat = getCategory( cat );
920 aCat->SetTitle( title );
923 //=======================================================================
924 //function : SetTitle
926 //=======================================================================
928 void QtxResourceEditor::SetTitle( const QString& title, const QString& cat, const QString& tab )
930 Category* aCat = getCategory( cat );
932 aCat->SetTitle( title, tab );
935 //=======================================================================
936 //function : SetTitle
938 //=======================================================================
940 void QtxResourceEditor::SetTitle( const QString& title, const QString& cat,
941 const QString& tab, const QString& group )
943 Category* aCat = getCategory( cat );
945 aCat->SetTitle( title, tab, group );
948 //=======================================================================
951 //=======================================================================
953 void QtxResourceEditor::Store()
955 for ( QPtrListIterator<Category> it( myCategories ); it.current(); ++it )
956 it.current()->Store();
958 //for ( QPtrListIterator<LH3DGui_PreferencesMgr> pmIt( myPrefMgrs ); pmIt.current(); ++pmIt )
959 // pmIt.current()->UpdatePreferences();
962 //=======================================================================
963 //function : Retrieve
965 //=======================================================================
967 void QtxResourceEditor::Retrieve()
969 for ( QPtrListIterator<Category> it( myCategories ); it.current(); ++it )
970 it.current()->Retrieve();
973 //=======================================================================
975 //purpose : invoke update of all tabs
976 //=======================================================================
978 void QtxResourceEditor::Update()
980 for ( QPtrListIterator<Category> it( myCategories ); it.current(); ++it )
981 it.current()->Update();
984 //=======================================================================
985 //function : getCategory
987 //=======================================================================
989 QtxResourceEditor::Category* QtxResourceEditor::getCategory( const QString& name ) const
992 for ( QPtrListIterator<Category> it( myCategories ); it.current() && !aCat; ++it )
993 if ( it.current()->GetName() == name )
998 //=======================================================================
999 //function : categories
1001 //=======================================================================
1003 const QtxResourceEditor::CategoryList& QtxResourceEditor::categories() const
1005 return myCategories;
1008 //=======================================================================
1009 //function : categories
1011 //=======================================================================
1013 QtxResourceMgr* QtxResourceEditor::resMgr() const