Salome HOME
View type definition
[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   for ( int i = 0; i < myItems.count(); i++ ) {
443     if ( myItems.at( i )->isVerticalOn() )
444       bVSet = true;
445     myItems.at( i )->enableWidgets( bHSet && myItems.at( i )->isVerticalOn() );
446   }
447   myOkBtn->setEnabled( bHSet && bVSet );
448 }
449
450 // ====================================================================================
451 /*!
452   Constructor
453 */
454 SPlot2d_ItemContainer::SPlot2d_ItemContainer( QObject* parent, const char* name )
455      : QObject( parent, name ), 
456        myEnabled( true )
457 {
458 }
459 /*!
460   Creates widgets
461 */
462 void SPlot2d_ItemContainer::createWidgets( QWidget* parentWidget )
463 {
464   myHBtn = new QToolButton( parentWidget );
465   myHBtn->setText( tr( "H" ) );
466   myHBtn->setToggleButton( true );
467   myHBtn->setOn( false );
468
469   myVBtn = new QToolButton( parentWidget );
470   myVBtn->setText( tr( "V" ) );
471   myVBtn->setToggleButton( true );
472   myVBtn->setOn( false );
473   
474   myTitleLab = new QLabel( parentWidget );
475   myUnitLab  = new QLabel( parentWidget );
476   myUnitLab->setAlignment( AlignCenter);
477   
478   myAutoCheck = new QCheckBox( tr( "AUTO_CHECK_LBL" ), parentWidget );
479   myAutoCheck->setChecked( true );
480
481   myLineCombo = new QComboBox( false, parentWidget );
482   myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) );
483   myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) );
484   myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) );
485   myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) );
486   myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) );
487   myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
488   myLineCombo->setCurrentItem( 1 ); // SOLID by default
489
490   myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, parentWidget );
491   myLineSpin->setValue( 0 );        // width = 0 by default
492
493   myMarkerCombo = new QComboBox( false, parentWidget );
494   myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) );
495   myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) );
496   myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) );
497   myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) );
498   myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) );
499   myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) );
500   myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) );
501   myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) );
502   myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) );
503   myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) );
504   myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default
505
506   myColorBtn = new QToolButton( parentWidget );
507
508   connect( myAutoCheck, SIGNAL( clicked() ),       this, SLOT( onAutoChanged() ) );
509   connect( myColorBtn,  SIGNAL( clicked() ),       this, SLOT( onColorChanged() ) );
510   connect( myHBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
511   connect( myVBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
512   setColor( QColor( 0, 0, 0 ) );
513   updateState();
514 }
515 /*!
516   Enables attributes widgets
517 */
518 void SPlot2d_ItemContainer::enableWidgets( bool enable )
519 {
520   myEnabled = enable;
521   updateState();
522 }
523 /*!
524   Sets horizontal button's state on
525 */
526 void SPlot2d_ItemContainer::setHorizontalOn( bool on )
527 {
528   myHBtn->setOn( on );
529 }
530 /*!
531   Gets horizontal button's state
532 */
533 bool SPlot2d_ItemContainer::isHorizontalOn() const
534 {
535   return myHBtn->isOn();
536 }
537 /*!
538   Sets vertical button's state on
539 */
540 void SPlot2d_ItemContainer::setVerticalOn( bool on )
541 {
542   myVBtn->setOn( on );
543 }
544 /*!
545   Gets vertical button's state
546 */
547 bool SPlot2d_ItemContainer::isVerticalOn() const
548 {
549   return myVBtn->isOn();
550 }
551 /*!
552   Sets item AutoAssign flag state
553 */
554 void SPlot2d_ItemContainer::setAutoAssign( bool on )
555 {
556   myAutoCheck->setChecked( on );
557   updateState();
558 }
559 /*!
560   Gets item AutoAssign flag state
561 */
562 bool SPlot2d_ItemContainer::isAutoAssign() const
563 {
564   return myAutoCheck->isChecked();
565 }
566 /*!
567   Sets item line type and width
568 */
569 void SPlot2d_ItemContainer::setLine( const int line, const int width )
570 {
571   myLineCombo->setCurrentItem( line );
572 }
573 /*!
574   Gets item line type
575 */
576 int SPlot2d_ItemContainer::getLine() const
577 {
578   return myLineCombo->currentItem();
579 }
580 /*!
581   Gets item line width
582 */
583 int SPlot2d_ItemContainer::getLineWidth() const
584 {
585   return myLineSpin->value();
586 }
587 /*!
588   Sets item marker type
589 */
590 void SPlot2d_ItemContainer::setMarker( const int marker )
591 {
592   myMarkerCombo->setCurrentItem( marker );
593 }
594 /*!
595   Gets item marker type
596 */
597 int SPlot2d_ItemContainer::getMarker() const
598 {
599   return myMarkerCombo->currentItem();
600 }
601 /*!
602   Sets item color
603 */
604 void SPlot2d_ItemContainer::setColor( const QColor& color )
605 {
606   QPalette pal = myColorBtn->palette();
607   QColorGroup ca = pal.active();
608   ca.setColor( QColorGroup::Button, color );
609   QColorGroup ci = pal.inactive();
610   ci.setColor( QColorGroup::Button, color );
611   pal.setActive( ca );
612   pal.setInactive( ci );
613   myColorBtn->setPalette( pal );
614 }
615 /*!
616   Gets item color
617 */
618 QColor SPlot2d_ItemContainer::getColor() const
619 {
620   return myColorBtn->palette().active().button();
621 }
622 /*!
623   Enables/disables widgets
624 */
625 void SPlot2d_ItemContainer::updateState()
626 {
627   myAutoCheck->setEnabled( myEnabled );
628   myLineCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
629   myLineSpin->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
630   myMarkerCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
631   myColorBtn->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
632 }
633 /*!
634   Slot, called when user clickes <Auto assign> check box
635 */
636 void SPlot2d_ItemContainer::onAutoChanged()
637 {
638   updateState();
639   emit( autoClicked() );
640 }
641 /*!
642   <Color> button slot, invokes color selection dialog box
643 */
644 void SPlot2d_ItemContainer::onColorChanged()
645 {
646   QColor color = QColorDialog::getColor( getColor() );
647   if ( color.isValid() ) {
648     setColor( color );
649   }
650 }
651 /*!
652   <H> and <V> buttons slot
653 */
654 void SPlot2d_ItemContainer::onHVToggled( bool on )
655 {
656   const QObject* snd = sender();
657   if ( snd == myHBtn ) {
658     if ( on ) {
659       if ( myVBtn->isOn() ) {
660 //      blockSignals( true );
661         myVBtn->setOn( false );
662 //      blockSignals( false );
663       }
664     }
665     emit horToggled( on );
666   }
667   else {
668     if ( on ) {
669       if ( myHBtn->isOn() ) {
670 //      blockSignals( true );
671         myHBtn->setOn( false );
672 //      blockSignals( false );
673       }
674     }
675     emit verToggled( on );
676   }
677 }
678
679
680
681
682