Salome HOME
ENV: Windows porting
[modules/gui.git] / src / SPlot2d / SPlot2d_SetupPlot2dDlg.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : Plot2d_SetupPlot2dDlg.cxx
6 //  Author : Vadim SANDLER
7 //  Module : SALOME
8 //  $Header$
9
10 #include "SPlot2d_SetupPlot2dDlg.h"
11 #include "SPlot2d_Curve.h"
12
13 #include "SUIT_Tools.h"
14 #include "SUIT_MessageBox.h"
15
16 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
17 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
18
19 #include <qlabel.h>
20 #include <qpushbutton.h>
21 #include <qcheckbox.h>
22 #include <qtoolbutton.h>
23 #include <qcombobox.h>
24 #include <qscrollview.h>
25 #include <qlayout.h>
26 #include <qcolordialog.h>
27 #include <qspinbox.h>
28
29 #include <vector>
30 #include <string>
31
32 #include "utilities.h"
33
34 using namespace std;
35
36 #define DLG_SIZE_WIDTH    500 
37 #define DLG_SIZE_HEIGHT   400
38 #define MAX_LINE_WIDTH    100
39 #define MARGIN_SIZE       11
40 #define SPACING_SIZE      6
41
42 /*!
43   Constructor
44 */
45 SPlot2d_SetupPlot2dDlg::SPlot2d_SetupPlot2dDlg( _PTR(SObject) object, QWidget* parent )
46     : QDialog( parent, 
47                "SPlot2d_SetupPlot2dDlg", 
48                true, 
49                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
50 {
51   setCaption( tr("TLT_SETUP_PLOT2D") );
52   setSizeGripEnabled( TRUE );
53   QGridLayout* topLayout = new QGridLayout( this ); 
54   topLayout->setSpacing( SPACING_SIZE );
55   topLayout->setMargin( MARGIN_SIZE );
56
57   myItems.setAutoDelete( false );
58
59   myObject = object;
60
61   /* Top scroll view */
62   myView = new QScrollView( this );
63   QFrame* frame  = new QFrame( myView );
64   frame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
65   QGridLayout* frameLayout = new QGridLayout( frame, 1, 12 );
66   frameLayout->setMargin( MARGIN_SIZE ); frameLayout->setSpacing( SPACING_SIZE );
67   
68   QFrame* lin;
69
70   QLabel* labAxis = new QLabel( tr( "AXIS_LBL" ),       frame );
71   QLabel* labData = new QLabel( tr( "DATA_LBL" ),       frame );
72   QLabel* labUnit = new QLabel( tr( "UNITS_LBL" ),      frame );
73   QLabel* labAttr = new QLabel( tr( "ATTRIBUTES_LBL" ), frame );
74   labAxis->setAlignment( AlignCenter );
75   labData->setAlignment( AlignCenter );
76   labUnit->setAlignment( AlignCenter );
77   labAttr->setAlignment( AlignCenter );
78   QFont font = labAxis->font(); font.setBold( true );
79   labAxis->setFont( font );
80   labData->setFont( font );
81   labUnit->setFont( font );
82   labAttr->setFont( font );
83
84   frameLayout->addMultiCellWidget( labAxis, 0,  0, 0, 1 );
85       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
86       frameLayout->addWidget( lin,          0,     2 );
87   frameLayout->addWidget( labData,          0,     3 );
88       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
89       frameLayout->addWidget( lin,          0,     4 );
90   frameLayout->addWidget( labUnit,          0,     5 );
91       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
92       frameLayout->addWidget( lin,          0,     6 );
93   frameLayout->addMultiCellWidget( labAttr, 0,  0, 7, 11 );
94   frameLayout->setColStretch(               12, 5 );
95   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::HLine | QFrame::Sunken );
96   frameLayout->addMultiCellWidget( lin, 1, 1, 0, 12 );
97
98   int row = 2;
99   _PTR(GenericAttribute)        anAttr;
100   _PTR(AttributeTableOfInteger) tblIntAttr;
101   _PTR(AttributeTableOfReal)    tblRealAttr;
102   
103   /* Try table of integer */
104   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
105     tblIntAttr = anAttr;
106     if ( tblIntAttr ) {
107       try {
108         int nbRows = tblIntAttr->GetNbRows() ; 
109         vector<string> rowTitles = tblIntAttr->GetRowTitles();
110         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
111         for ( int i = 0; i < nbRows; i++ ) {
112           SPlot2d_ItemContainer* item = new SPlot2d_ItemContainer( this );
113           item->createWidgets( frame );
114           frameLayout->addWidget( item->myHBtn,        row, 0 );
115           frameLayout->addWidget( item->myVBtn,        row, 1 );
116           frameLayout->addWidget( item->myTitleLab,    row, 3 );
117           if ( rowTitles.size() > 0 )
118             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
119           frameLayout->addWidget( item->myUnitLab,     row, 5 );
120           if ( rowUnits.size() > 0 )
121             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
122           frameLayout->addWidget( item->myAutoCheck,   row, 7 );
123           frameLayout->addWidget( item->myLineCombo,   row, 8 );
124           frameLayout->addWidget( item->myLineSpin,    row, 9 );
125           frameLayout->addWidget( item->myMarkerCombo, row, 10 );
126           frameLayout->addWidget( item->myColorBtn,    row, 11 );
127           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
128           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
129           myItems.append( item );
130           row++;
131         }
132       }
133       catch( ... ) {
134         MESSAGE("SPlot2d_SetupPlot2dDlg::SPlot2d_SetupPlot2dDlg : Exception has been caught (int)!!!");
135       }
136     }
137   }
138   /* Try table of real */
139   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
140     tblRealAttr = anAttr;
141     if ( tblRealAttr ) {
142       try {
143         int nbRows = tblRealAttr->GetNbRows() ; 
144         vector<string> rowTitles = tblRealAttr->GetRowTitles();
145         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
146         for ( int i = 0; i < nbRows; i++ ) {
147           SPlot2d_ItemContainer* item = new SPlot2d_ItemContainer( this );
148           item->createWidgets( frame );
149           frameLayout->addWidget( item->myHBtn,        row, 0 );
150           frameLayout->addWidget( item->myVBtn,        row, 1 );
151           frameLayout->addWidget( item->myTitleLab,    row, 3 );
152           if ( rowTitles.size() > 0 )
153             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
154           frameLayout->addWidget( item->myUnitLab,     row, 5 );
155           if ( rowUnits.size() > 0 )
156             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
157           frameLayout->addWidget( item->myAutoCheck,   row, 7 );
158           frameLayout->addWidget( item->myLineCombo,   row, 8 );
159           frameLayout->addWidget( item->myLineSpin,    row, 9 );
160           frameLayout->addWidget( item->myMarkerCombo, row, 10 );
161           frameLayout->addWidget( item->myColorBtn,    row, 11 );
162           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
163           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
164           myItems.append( item );
165           row++;
166         }
167       }
168       catch( ... ) {
169         MESSAGE("SPlot2d_SetupPlot2dDlg::SPlot2d_SetupPlot2dDlg : Exception has been caught (real)!!!");
170       }
171     }
172   }
173   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
174   frameLayout->addMultiCellWidget( lin, 2, row+1, 2, 2 );
175   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
176   frameLayout->addMultiCellWidget( lin, 2, row+1, 4, 4 );
177   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
178   frameLayout->addMultiCellWidget( lin, 2, row+1, 6, 6 );
179   frameLayout->setRowStretch( row+1, 5 );
180
181   myView->addChild( frame, 0, 0 );
182   myView->setResizePolicy( QScrollView::AutoOneFit );
183   
184   myView->setMinimumWidth( frame->sizeHint().width() + MARGIN_SIZE * 2 );
185
186   /* OK/Cancel buttons */
187   myOkBtn = new QPushButton( tr( "BUT_OK" ), this, "buttonOk" );
188   myOkBtn->setAutoDefault( TRUE );
189   myOkBtn->setDefault( TRUE );
190   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this, "buttonCancel" );
191   myCancelBtn->setAutoDefault( TRUE );
192
193   topLayout->addMultiCellWidget( myView, 0, 0, 0, 2 );
194   topLayout->addWidget( myOkBtn, 1, 0 );
195   topLayout->setColStretch( 1, 5 );
196   topLayout->addWidget( myCancelBtn, 1, 2 );
197
198   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
199   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
200
201   enableControls();
202
203   /* Center widget inside it's parent widget */
204   resize( DLG_SIZE_WIDTH, DLG_SIZE_HEIGHT  );
205   SUIT_Tools::centerWidget( this, parentWidget() );
206 }
207 /*!
208   Destructor
209 */
210 SPlot2d_SetupPlot2dDlg::~SPlot2d_SetupPlot2dDlg()
211 {
212 }
213 /*!
214   Gets curves info ( indexes of row data in the table for horizontal and verical axes )
215 */
216 void SPlot2d_SetupPlot2dDlg::getCurvesSource( int& horIndex, QValueList<int>& verIndexes )
217 {
218   /* collecting horizontal and vertical axis items */
219   horIndex = -1;
220   int i;
221   for ( i = 0; i < myItems.count(); i++ ) {
222     if ( myItems.at( i )->isHorizontalOn() ) {
223       horIndex = i;
224     }
225     else if ( myItems.at( i )->isVerticalOn() ) {
226       verIndexes.append( i );
227     }
228   }
229 }
230 /*!
231   Gets curve attributes
232 */
233 bool SPlot2d_SetupPlot2dDlg::getCurveAttributes( const int vIndex, 
234                                                    bool&     isAuto, 
235                                                    int&      marker, 
236                                                    int&      line, 
237                                                    int&      lineWidth, 
238                                                    QColor&   color)
239 {
240   if ( vIndex >= 0 && vIndex < myItems.count() ) {
241     isAuto    = myItems.at( vIndex )->isAutoAssign();
242     marker    = myItems.at( vIndex )->getMarker();
243     line      = myItems.at( vIndex )->getLine();
244     lineWidth = myItems.at( vIndex )->getLineWidth();
245     color     = myItems.at( vIndex )->getColor();
246     return true;
247   }
248   return false;
249 }
250 /*!
251   Creates and returns curves presentations
252 */
253 void SPlot2d_SetupPlot2dDlg::getCurves( QPtrList<Plot2d_Curve>& container )
254 {
255   _PTR(GenericAttribute)        anAttr;
256   _PTR(AttributeTableOfInteger) tblIntAttr;
257   _PTR(AttributeTableOfReal)    tblRealAttr;
258   
259   /* clearing container contents */
260   container.clear();
261
262   /* collecting horizontal and vertical axis items */
263   int horIndex;
264   int i, j;
265   QValueList<int> verIndex;
266   getCurvesSource( horIndex, verIndex );
267   if ( horIndex < 0 || verIndex.isEmpty() ) /* no curves can be created */
268     return;
269     
270   /* Try table of integer */
271   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
272     tblIntAttr = anAttr;
273     if ( tblIntAttr ) {
274       try {
275         int nbCols = tblIntAttr->GetNbColumns() ; 
276         vector<string> rowTitles = tblIntAttr->GetRowTitles();
277         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
278
279         for ( i = 0; i < verIndex.count(); i++ ) {
280           SPlot2d_Curve* curve = new SPlot2d_Curve();
281           // curve titles
282           if ( rowTitles.size() > 0 ) {
283             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
284             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
285           }
286           // curve units
287           if ( rowUnits.size() > 0 ) {
288             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
289             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
290           }
291           // curve data
292           int nbPoints = 0;
293           for ( j = 1; j <= nbCols; j++ ) {
294             if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) )
295               nbPoints++;
296           }
297           if ( nbPoints > 0 ) {
298             double* xList = new double[ nbPoints ];
299             double* yList = new double[ nbPoints ];
300             for ( j = 1; j <= nbCols; j++ ) {
301               if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) ) {
302                 xList[j-1] = tblIntAttr->GetValue( horIndex   +1, j );
303                 yList[j-1] = tblIntAttr->GetValue( verIndex[i]+1, j );
304               }
305             }
306             curve->setData( xList, yList, nbPoints );
307           }
308           // curve attributes
309           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
310           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
311           curve->setColor( myItems.at( verIndex[i] )->getColor() );
312           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
313           // add curve into container
314           container.append( curve );
315         }
316       }
317       catch( ... ) {
318         MESSAGE("SPlot2d_SetupPlot2dDlg::getCurves : Exception has been caught (int)!!!");
319       }
320     }
321   }
322   /* Try table of real */
323   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
324     tblRealAttr = anAttr;
325     if ( tblRealAttr ) {
326       try {
327         int nbCols = tblRealAttr->GetNbColumns() ; 
328         vector<string> rowTitles = tblRealAttr->GetRowTitles();
329         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
330
331         for ( i = 0; i < verIndex.count(); i++ ) {
332           SPlot2d_Curve* curve = new SPlot2d_Curve();
333           // curve titles
334           if ( rowTitles.size() > 0 ) {
335             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
336             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
337           }
338           // curve units
339           if ( rowUnits.size() > 0 ) {
340             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
341             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
342           }
343           // curve data
344           int nbPoints = 0;
345           for ( j = 1; j <= nbCols; j++ ) {
346             if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) )
347               nbPoints++;
348           }
349           if ( nbPoints > 0 ) {
350             double* xList = new double[ nbPoints ];
351             double* yList = new double[ nbPoints ];
352             for ( j = 1; j <= nbCols; j++ ) {
353               if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) ) {
354                 xList[j-1] = tblRealAttr->GetValue( horIndex   +1, j );
355                 yList[j-1] = tblRealAttr->GetValue( verIndex[i]+1, j );
356               }
357             }
358             curve->setData( xList, yList, nbPoints );
359           }
360           // curve attributes
361           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
362           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
363           curve->setColor( myItems.at( verIndex[i] )->getColor() );
364           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
365           // add curve into container
366           container.append( curve );
367         }
368       }
369       catch( ... ) {
370         MESSAGE("SPlot2d_SetupPlot2dDlg::getCurves : Exception has been caught (real)!!!");
371       }
372     }
373   }
374 }
375 /*!
376   Slot, called when any <H> button is clicked
377 */
378 void SPlot2d_SetupPlot2dDlg::onHBtnToggled( bool on )
379 {
380   SPlot2d_ItemContainer* item = ( SPlot2d_ItemContainer* )sender();
381   if ( on ) {
382     for ( int i = 0; i < myItems.count(); i++ ) {
383       if ( myItems.at( i ) != item )
384         myItems.at( i )->setHorizontalOn( false );
385     }
386   }
387   enableControls();
388 }
389 /*!
390   Slot, called when any <V> button is clicked
391 */
392 void SPlot2d_SetupPlot2dDlg::onVBtnToggled( bool on )
393 {
394   SPlot2d_ItemContainer* item = ( SPlot2d_ItemContainer* )sender();
395   QPtrList<SPlot2d_ItemContainer> itemList;
396   itemList.setAutoDelete( false );
397   int i;
398   if ( on ) {
399     int totalOn = 0;
400     for ( i = 0; i < myItems.count(); i++ ) {
401       if ( myItems.at( i ) != item && !myItems.at( i )->isHorizontalOn() ) {
402         if ( myItems.at( i )->myUnitLab->text() == item->myUnitLab->text() ) {
403           if ( myItems.at( i )->isVerticalOn() )
404             totalOn++;
405           else
406             itemList.append( myItems.at( i ) );
407         }
408         else {
409           myItems.at( i )->setVerticalOn( false );
410         }
411       }
412     }
413     if ( totalOn == 0 && !itemList.isEmpty() && 
414          SUIT_MessageBox::info2( this, 
415                                 this->caption(), 
416                                 tr( "QUE_WANT_SAME_UNITS" ),
417                                 tr( "BUT_YES" ), 
418                                 tr( "BUT_NO" ), 
419                                 0, 1, 1 ) == 0 ) {
420       for ( i = 0; i < itemList.count(); i++ ) {
421         itemList.at( i )->blockSignals( true );
422         itemList.at( i )->setVerticalOn( true );
423         itemList.at( i )->blockSignals( false );
424       }
425     }
426   }
427   enableControls();
428 }
429 /*!
430   Enables/disables buttons 
431 */
432 void SPlot2d_SetupPlot2dDlg::enableControls()
433 {
434   bool bHSet = false;
435   bool bVSet = false;
436   for ( int i = 0; i < myItems.count(); i++ ) {
437     if ( myItems.at( i )->isHorizontalOn() ) {
438       bHSet = true;
439       break;
440     }
441   }
442 #ifndef WNT
443   for ( int i = 0; i < myItems.count(); i++ ) {
444 #else
445   for ( i = 0; i < myItems.count(); i++ ) {
446 #endif
447     if ( myItems.at( i )->isVerticalOn() )
448       bVSet = true;
449     myItems.at( i )->enableWidgets( bHSet && myItems.at( i )->isVerticalOn() );
450   }
451   myOkBtn->setEnabled( bHSet && bVSet );
452 }
453
454 // ====================================================================================
455 /*!
456   Constructor
457 */
458 SPlot2d_ItemContainer::SPlot2d_ItemContainer( QObject* parent, const char* name )
459      : QObject( parent, name ), 
460        myEnabled( true )
461 {
462 }
463 /*!
464   Creates widgets
465 */
466 void SPlot2d_ItemContainer::createWidgets( QWidget* parentWidget )
467 {
468   myHBtn = new QToolButton( parentWidget );
469   myHBtn->setText( tr( "H" ) );
470   myHBtn->setToggleButton( true );
471   myHBtn->setOn( false );
472
473   myVBtn = new QToolButton( parentWidget );
474   myVBtn->setText( tr( "V" ) );
475   myVBtn->setToggleButton( true );
476   myVBtn->setOn( false );
477   
478   myTitleLab = new QLabel( parentWidget );
479   myUnitLab  = new QLabel( parentWidget );
480   myUnitLab->setAlignment( AlignCenter);
481   
482   myAutoCheck = new QCheckBox( tr( "AUTO_CHECK_LBL" ), parentWidget );
483   myAutoCheck->setChecked( true );
484
485   myLineCombo = new QComboBox( false, parentWidget );
486   myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) );
487   myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) );
488   myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) );
489   myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) );
490   myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) );
491   myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
492   myLineCombo->setCurrentItem( 1 ); // SOLID by default
493
494   myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, parentWidget );
495   myLineSpin->setValue( 0 );        // width = 0 by default
496
497   myMarkerCombo = new QComboBox( false, parentWidget );
498   myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) );
499   myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) );
500   myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) );
501   myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) );
502   myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) );
503   myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) );
504   myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) );
505   myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) );
506   myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) );
507   myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) );
508   myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default
509
510   myColorBtn = new QToolButton( parentWidget );
511
512   connect( myAutoCheck, SIGNAL( clicked() ),       this, SLOT( onAutoChanged() ) );
513   connect( myColorBtn,  SIGNAL( clicked() ),       this, SLOT( onColorChanged() ) );
514   connect( myHBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
515   connect( myVBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
516   setColor( QColor( 0, 0, 0 ) );
517   updateState();
518 }
519 /*!
520   Enables attributes widgets
521 */
522 void SPlot2d_ItemContainer::enableWidgets( bool enable )
523 {
524   myEnabled = enable;
525   updateState();
526 }
527 /*!
528   Sets horizontal button's state on
529 */
530 void SPlot2d_ItemContainer::setHorizontalOn( bool on )
531 {
532   myHBtn->setOn( on );
533 }
534 /*!
535   Gets horizontal button's state
536 */
537 bool SPlot2d_ItemContainer::isHorizontalOn() const
538 {
539   return myHBtn->isOn();
540 }
541 /*!
542   Sets vertical button's state on
543 */
544 void SPlot2d_ItemContainer::setVerticalOn( bool on )
545 {
546   myVBtn->setOn( on );
547 }
548 /*!
549   Gets vertical button's state
550 */
551 bool SPlot2d_ItemContainer::isVerticalOn() const
552 {
553   return myVBtn->isOn();
554 }
555 /*!
556   Sets item AutoAssign flag state
557 */
558 void SPlot2d_ItemContainer::setAutoAssign( bool on )
559 {
560   myAutoCheck->setChecked( on );
561   updateState();
562 }
563 /*!
564   Gets item AutoAssign flag state
565 */
566 bool SPlot2d_ItemContainer::isAutoAssign() const
567 {
568   return myAutoCheck->isChecked();
569 }
570 /*!
571   Sets item line type and width
572 */
573 void SPlot2d_ItemContainer::setLine( const int line, const int width )
574 {
575   myLineCombo->setCurrentItem( line );
576 }
577 /*!
578   Gets item line type
579 */
580 int SPlot2d_ItemContainer::getLine() const
581 {
582   return myLineCombo->currentItem();
583 }
584 /*!
585   Gets item line width
586 */
587 int SPlot2d_ItemContainer::getLineWidth() const
588 {
589   return myLineSpin->value();
590 }
591 /*!
592   Sets item marker type
593 */
594 void SPlot2d_ItemContainer::setMarker( const int marker )
595 {
596   myMarkerCombo->setCurrentItem( marker );
597 }
598 /*!
599   Gets item marker type
600 */
601 int SPlot2d_ItemContainer::getMarker() const
602 {
603   return myMarkerCombo->currentItem();
604 }
605 /*!
606   Sets item color
607 */
608 void SPlot2d_ItemContainer::setColor( const QColor& color )
609 {
610   QPalette pal = myColorBtn->palette();
611   QColorGroup ca = pal.active();
612   ca.setColor( QColorGroup::Button, color );
613   QColorGroup ci = pal.inactive();
614   ci.setColor( QColorGroup::Button, color );
615   pal.setActive( ca );
616   pal.setInactive( ci );
617   myColorBtn->setPalette( pal );
618 }
619 /*!
620   Gets item color
621 */
622 QColor SPlot2d_ItemContainer::getColor() const
623 {
624   return myColorBtn->palette().active().button();
625 }
626 /*!
627   Enables/disables widgets
628 */
629 void SPlot2d_ItemContainer::updateState()
630 {
631   myAutoCheck->setEnabled( myEnabled );
632   myLineCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
633   myLineSpin->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
634   myMarkerCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
635   myColorBtn->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
636 }
637 /*!
638   Slot, called when user clickes <Auto assign> check box
639 */
640 void SPlot2d_ItemContainer::onAutoChanged()
641 {
642   updateState();
643   emit( autoClicked() );
644 }
645 /*!
646   <Color> button slot, invokes color selection dialog box
647 */
648 void SPlot2d_ItemContainer::onColorChanged()
649 {
650   QColor color = QColorDialog::getColor( getColor() );
651   if ( color.isValid() ) {
652     setColor( color );
653   }
654 }
655 /*!
656   <H> and <V> buttons slot
657 */
658 void SPlot2d_ItemContainer::onHVToggled( bool on )
659 {
660   const QObject* snd = sender();
661   if ( snd == myHBtn ) {
662     if ( on ) {
663       if ( myVBtn->isOn() ) {
664 //      blockSignals( true );
665         myVBtn->setOn( false );
666 //      blockSignals( false );
667       }
668     }
669     emit horToggled( on );
670   }
671   else {
672     if ( on ) {
673       if ( myHBtn->isOn() ) {
674 //      blockSignals( true );
675         myHBtn->setOn( false );
676 //      blockSignals( false );
677       }
678     }
679     emit verToggled( on );
680   }
681 }
682
683
684
685
686