Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/diagrams/diagramdialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               diagramdialog.cpp
00003                              -------------------
00004     begin                : Sun Oct 5 2003
00005     copyright            : (C) 2003 by Michael Margraf
00006     email                : michael.margraf@alumni.tu-berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00022 #include "diagramdialog.h"
00023 #include "qucs.h"
00024 #include "schematic.h"
00025 #include "rect3ddiagram.h"
00026 
00027 #include <cmath>
00028 #include <assert.h>
00029 
00030 #include <QPaintEvent>
00031 #include <QPushButton>
00032 #include <QTabWidget>
00033 #include <QLabel>
00034 #include <QStringList>
00035 #include <QColorDialog>
00036 #include <QLineEdit>
00037 #include <QCheckBox>
00038 #include <QSlider>
00039 #include <QComboBox>
00040 #include <QListWidget>
00041 #include <QTableWidget>
00042 #include <QPainter>
00043 #include <QVBoxLayout>
00044 #include <QGroupBox>
00045 #include <QHeaderView>
00046 #include <QDir>
00047 #include <QDebug>
00048 
00049 
00050 #define CROSS3D_SIZE   30
00051 #define WIDGET3D_SIZE  2*CROSS3D_SIZE
00052 // This widget class paints a small 3-dimensional coordinate cross.
00053 class Cross3D : public QWidget  {
00054 public:
00055   Cross3D(float rx_, float ry_, float rz_, QWidget *parent = 0)
00056           : QWidget(parent) {
00057     rotX = rx_;
00058     rotY = ry_;
00059     rotZ = rz_;
00060     setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
00061     setMinimumSize(WIDGET3D_SIZE, WIDGET3D_SIZE);
00062     resize(WIDGET3D_SIZE, WIDGET3D_SIZE);
00063   };
00064  ~Cross3D() {};
00065 
00066   double rotX, rotY, rotZ;   // in radians !!!!
00067 
00068 private:
00069   void  paintEvent(QPaintEvent*) {
00070     QPainter Painter(this);
00071     float cxx = cos(rotZ);
00072     float cxy = sin(rotZ);
00073     float cxz = sin(rotY);
00074     float cyz = sin(rotX);
00075     float cyy = cos(rotX);
00076     float cyx = cyy * cxy + cyz * cxz * cxx;
00077     cyy = cyy * cxx - cyz * cxz * cxy;
00078     cyz *= cos(rotY);
00079     cxx *= cos(rotY);
00080     cxy *= cos(rotY);
00081 
00082     Painter.setPen(QPen(Qt::red,2));
00083     Painter.drawLine(CROSS3D_SIZE, CROSS3D_SIZE,
00084          int(CROSS3D_SIZE * (1.0+cxx)),
00085          int(CROSS3D_SIZE * (1.0-cyx)));
00086     Painter.setPen(QPen(Qt::green,2));
00087     Painter.drawLine(CROSS3D_SIZE, CROSS3D_SIZE,
00088          int(CROSS3D_SIZE * (1.0-cxy)),
00089          int(CROSS3D_SIZE * (1.0-cyy)));
00090     Painter.setPen(QPen(Qt::blue,2));
00091     Painter.drawLine(CROSS3D_SIZE, CROSS3D_SIZE,
00092          int(CROSS3D_SIZE * (1.0+cxz)),
00093          int(CROSS3D_SIZE * (1.0+cyz)));
00094   };
00095 };
00096 
00097 
00098 
00099 // standard colors: blue, red, magenta, green, cyan, yellow, grey, black
00100 static const QRgb DefaultColors[]
00101           = {0x0000ff, 0xff0000, 0xff00ff, 0x00ff00, 0x00ffff, 0xffff00,
00102              0x777777, 0x000000};
00103 
00104 static const int NumDefaultColors = 8;
00105 
00106 
00107 DiagramDialog::DiagramDialog(Diagram *d, QWidget *parent, Graph *currentGraph)
00108                     : QDialog(parent, 0, TRUE, Qt::WDestructiveClose)
00109 {
00110   Diag = d;
00111   Graphs.setAutoDelete(true);
00112   copyDiagramGraphs();   // make a copy of all graphs
00113   if(parent){
00114     const Schematic* s = dynamic_cast<const Schematic*>(parent);
00115     assert(s);
00116     QFileInfo Info(s->DocName);
00117     defaultDataSet = Info.dirPath() + QDir::separator() + s->DataSet;
00118   }else{
00119     defaultDataSet = "unknown";
00120   }
00121   setWindowTitle(tr("Edit Diagram Properties"));
00122   changed = false;
00123   transfer = false;  // have changes be applied ? (used by "Cancel")
00124   toTake = false;   // double-clicked variable be inserted into graph list ?
00125 
00126   Expr.setPattern("[^\"]+");
00127   Validator  = new QRegExpValidator(Expr, this);
00128   ValInteger = new QIntValidator(0, 360, this);
00129   ValDouble  = new QDoubleValidator(-1e200, 1e200, 6, this);
00130 
00131   QString NameY, NameZ;
00132   if((Diag->Name == "Rect") || (Diag->Name == "Curve")) {
00133     NameY = tr("left Axis");
00134     NameZ = tr("right Axis");
00135   }
00136   else if(Diag->Name == "Polar") {
00137     NameY = tr("y-Axis");
00138   }
00139   else if((Diag->Name == "Smith") || (Diag->Name == "ySmith")) {
00140     NameY = tr("y-Axis");
00141   }
00142   else if(Diag->Name == "PS") {
00143     NameY = tr("smith Axis");
00144     NameZ = tr("polar Axis");
00145   }
00146   else if(Diag->Name == "SP") {
00147     NameY = tr("polar Axis");
00148     NameZ = tr("smith Axis");
00149   }
00150   else if(Diag->Name == "Rect3D") {
00151     NameY = tr("y-Axis");
00152     NameZ = tr("z-Axis");
00153   }
00154 
00155   
00156   all = new QVBoxLayout(this); // to provide neccessary size
00157   QTabWidget *t = new QTabWidget();
00158   all->addWidget(t);
00159 
00160   // Tab #1 - Data ...........................................................
00161   QWidget *Tab1 = new QWidget();
00162   QVBoxLayout *Tab1Layout = new QVBoxLayout();
00163   Tab1Layout->setSpacing(0);
00164   Tab1->setLayout(Tab1Layout);
00165 
00166   Label4 = 0;     // different types with same content
00167   yrLabel = 0;
00168   yAxisBox = 0;
00169   Property2 = 0;
00170   ColorButt = 0;
00171   hideInvisible = 0;
00172   rotationX = rotationY = rotationZ = 0;
00173 
00174   QGroupBox *InputGroup = new QGroupBox(tr("Graph Input"));
00175   QVBoxLayout *InputGroupLayout = new QVBoxLayout();
00176   InputGroup->setLayout(InputGroupLayout);
00177   Tab1Layout->addWidget(InputGroup);
00178   GraphInput = new QLineEdit();
00179   InputGroupLayout->addWidget(GraphInput);
00180   GraphInput->setValidator(Validator);
00181   connect(GraphInput, SIGNAL(textChanged(const QString&)), SLOT(slotResetToTake(const QString&)));
00182   QWidget *Box2 = new QWidget();
00183   QHBoxLayout *Box2Layout = new QHBoxLayout();
00184   Box2->setLayout(Box2Layout);
00185   InputGroupLayout->addWidget(Box2);
00186   Box2Layout->setSpacing(5);
00187 
00188   if(Diag->Name == "Tab") {
00189     Label1 = new QLabel(tr("Number Notation: "));
00190     Box2Layout->addWidget(Label1);
00191     PropertyBox = new QComboBox();
00192     Box2Layout->addWidget(PropertyBox);
00193     PropertyBox->insertItem(tr("real/imaginary"));
00194     PropertyBox->insertItem(tr("magnitude/angle (degree)"));
00195     PropertyBox->insertItem(tr("magnitude/angle (radian)"));
00196     PropertyBox->setCurrentItem(1);
00197     connect(PropertyBox, SIGNAL(activated(int)), SLOT(slotSetNumMode(int)));
00198     Box2Layout->setStretchFactor(new QWidget(Box2), 5); // stretchable placeholder
00199 
00200     Label2 = new QLabel(tr("Precision:"));
00201     Box2Layout->addWidget(Label2);
00202     Property2 = new QLineEdit();
00203     Box2Layout->addWidget(Property2);
00204     Property2->setValidator(ValInteger);
00205     Property2->setMaxLength(2);
00206     Property2->setMaximumWidth(25);
00207     Property2->setText("3");
00208   }
00209   else if(Diag->Name != "Truth") {
00210     Label1 = new QLabel(tr("Color:"));
00211     Box2Layout->addWidget(Label1);
00212     ColorButt = new QPushButton("   ");
00213     Box2Layout->addWidget(ColorButt);
00214     ColorButt->setMinimumWidth(50);
00215     ColorButt->setEnabled(false);
00216     connect(ColorButt, SIGNAL(clicked()), SLOT(slotSetColor()));
00217     Box2Layout->setStretchFactor(new QWidget(Box2), 5); // stretchable placeholder
00218 
00219     Label3 = new QLabel(tr("Style:"));
00220     Box2Layout->addWidget(Label3);
00221     Label3->setEnabled(false);
00222     PropertyBox = new QComboBox();
00223     Box2Layout->addWidget(PropertyBox);
00224     PropertyBox->insertItem(tr("solid line"));
00225     PropertyBox->insertItem(tr("dash line"));
00226     PropertyBox->insertItem(tr("dot line"));
00227     if(Diag->Name != "Time") {
00228       PropertyBox->insertItem(tr("long dash line"));
00229       PropertyBox->insertItem(tr("stars"));
00230       PropertyBox->insertItem(tr("circles"));
00231       PropertyBox->insertItem(tr("arrows"));
00232     }
00233     connect(PropertyBox, SIGNAL(activated(int)),
00234        SLOT(slotSetGraphStyle(int)));
00235     Box2Layout->setStretchFactor(new QWidget(Box2), 5); // stretchable placeholder
00236 
00237     Label2 = new QLabel(tr("Thickness:"));
00238     Box2Layout->addWidget(Label2);
00239     Property2 = new QLineEdit();
00240     Box2Layout->addWidget(Property2);
00241     Property2->setValidator(ValInteger);
00242     Property2->setMaximumWidth(25);
00243     Property2->setMaxLength(2);
00244     Property2->setText("0");
00245 
00246     if((Diag->Name=="Rect") || (Diag->Name=="PS") || (Diag->Name=="SP") || (Diag->Name=="Curve")) {
00247       Label4 = new QLabel(tr("y-Axis:"));
00248       Box2Layout->addWidget(Label4);
00249       Label4->setEnabled(false);
00250       yAxisBox = new QComboBox();
00251       Box2Layout->addWidget(yAxisBox);
00252       yAxisBox->insertItem(NameY);
00253       yAxisBox->insertItem(NameZ);
00254       yAxisBox->setEnabled(false);
00255       connect(yAxisBox, SIGNAL(activated(int)), SLOT(slotSetYAxis(int)));
00256     }
00257   }
00258   if(Property2) {
00259     connect(Property2, SIGNAL(textChanged(const QString&)),
00260       SLOT(slotSetProp2(const QString&)));
00261 
00262     Label1->setEnabled(false);
00263     PropertyBox->setEnabled(false);
00264     Label2->setEnabled(false);
00265     Property2->setEnabled(false);
00266   }
00267 
00268   QWidget *Box1 = new QWidget();
00269   Tab1Layout->addWidget(Box1);
00270   QHBoxLayout *Box1Layout = new QHBoxLayout();
00271   Box1->setLayout(Box1Layout);
00272   Box1Layout->setSpacing(5);
00273   Box1Layout->setContentsMargins(0, 0, 0, 0);
00274 
00275   QGroupBox *DataGroup = new QGroupBox(tr("Dataset"));
00276   Box1Layout->addWidget(DataGroup);
00277   QVBoxLayout *DataGroupLayout = new QVBoxLayout();
00278   DataGroup->setLayout(DataGroupLayout);
00279   ChooseData = new QComboBox();
00280   DataGroupLayout->addWidget(ChooseData);
00281   ChooseData->setMinimumWidth(300); // will force also min width of table below
00282   connect(ChooseData, SIGNAL(activated(int)), SLOT(slotReadVars(int)));
00283   // todo: replace by QTableWidget
00284   // see https://gist.github.com/ClemensFMN/8955411
00285   ChooseVars = new QTableWidget(1, 3);
00286   ChooseVars->verticalHeader()->setVisible(false);
00287   ChooseVars->horizontalHeader()->setStretchLastSection(true);
00288   ChooseVars->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
00289   // make sure sorting is disabled before inserting items
00290   ChooseVars->setSortingEnabled(false);
00291   ChooseVars->horizontalHeader()->setSortIndicatorShown(true);
00292   ChooseVars->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
00293 
00294   ChooseVars->setSelectionBehavior(QAbstractItemView::SelectRows);
00295   //ChooseVars->selectRow(0);
00296   DataGroupLayout->addWidget(ChooseVars);
00297   //ChooseVars->addColumn(tr("Name"));
00298   //ChooseVars->addColumn(tr("Type"));
00299   //ChooseVars->addColumn(tr("Size"));
00300   QStringList headers;
00301   headers << tr("Name") << tr("Type") << tr("Size");
00302   ChooseVars->setHorizontalHeaderLabels(headers);
00303 
00304   connect(ChooseVars, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), SLOT(slotTakeVar(QTableWidgetItem*)));
00305 
00306 
00307   QGroupBox *GraphGroup = new QGroupBox(tr("Graph"));
00308   Box1Layout->addWidget(GraphGroup);
00309   QVBoxLayout *GraphGroupLayout = new QVBoxLayout();
00310   GraphGroup->setLayout(GraphGroupLayout);
00311   GraphList = new QListWidget();
00312   GraphGroupLayout->addWidget(GraphList);
00313   connect(GraphList, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(slotSelectGraph(QListWidgetItem*)));
00314   connect(GraphList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(slotDeleteGraph()));
00315   QPushButton *NewButt = new QPushButton(tr("New Graph"));
00316   GraphGroupLayout->addWidget(NewButt);
00317   connect(NewButt, SIGNAL(clicked()), SLOT(slotNewGraph()));
00318   QPushButton *DelButt = new QPushButton(tr("Delete Graph"));
00319   GraphGroupLayout->addWidget(DelButt);
00320   connect(DelButt, SIGNAL(clicked()), SLOT(slotDeleteGraph()));
00321 
00322   t->addTab(Tab1, tr("Data"));
00323 
00324 
00325 
00326   // Tab #2...........................................................
00327   int Row = 0;
00328   if(Diag->Name.at(0) != 'T') {  // not tabular or timing diagram
00329     QWidget *Tab2 = new QWidget(t);
00330     QGridLayout *gp = new QGridLayout(Tab2,13,3,5,5);
00331 
00332     gp->addMultiCellWidget(new QLabel(tr("x-Axis Label:"), Tab2), Row,Row,0,0);
00333     xLabel = new QLineEdit(Tab2);
00334     xLabel->setValidator(Validator);
00335     gp->addMultiCellWidget(xLabel, Row,Row,1,2);
00336     Row++;
00337 
00338     gp->addMultiCellWidget(
00339     new QLabel(NameY+" "+tr("Label:"), Tab2), Row,Row,0,0);
00340     ylLabel = new QLineEdit(Tab2);
00341     ylLabel->setValidator(Validator);
00342     gp->addMultiCellWidget(ylLabel, Row,Row,1,2);
00343     Row++;
00344 
00345     if((Diag->Name != "Smith") && (Diag->Name != "Polar")) {
00346       gp->addMultiCellWidget(
00347     new QLabel(NameZ +" "+tr("Label:"), Tab2), Row,Row,0,0);
00348       yrLabel = new QLineEdit(Tab2);
00349       yrLabel->setValidator(Validator);
00350       gp->addMultiCellWidget(yrLabel, Row,Row,1,2);
00351       Row++;
00352     }
00353 
00354     gp->addMultiCellWidget(new QLabel(
00355         tr("<b>Label text</b>: Use LaTeX style for special characters, e.g. \\tau"),
00356         Tab2),  Row,Row,0,2);
00357     Row++;
00358 
00359     if(Diag->Name != "Rect3D") {
00360       GridOn = new QCheckBox(tr("show Grid"), Tab2);
00361       gp->addMultiCellWidget(GridOn, Row,Row,0,2);
00362       Row++;
00363 
00364       GridLabel1 = new QLabel(tr("Grid Color:"),Tab2);
00365       gp->addMultiCellWidget(GridLabel1, Row,Row,0,0);
00366       GridColorButt = new QPushButton("        ",Tab2);
00367       connect(GridColorButt, SIGNAL(clicked()), SLOT(slotSetGridColor()));
00368       gp->addMultiCellWidget(GridColorButt, Row,Row,1,2);
00369       Row++;
00370       GridColorButt->setPaletteBackgroundColor(Diag->GridPen.color());
00371 
00372       GridLabel2 = new QLabel(tr("Grid Style: "), Tab2);
00373       gp->addMultiCellWidget(GridLabel2, Row,Row,0,0);
00374       GridStyleBox = new QComboBox(Tab2);
00375       GridStyleBox->insertItem(tr("solid line"));
00376       GridStyleBox->insertItem(tr("dash line"));
00377       GridStyleBox->insertItem(tr("dot line"));
00378       GridStyleBox->insertItem(tr("dash dot line"));
00379       GridStyleBox->insertItem(tr("dash dot dot line"));
00380       gp->addMultiCellWidget(GridStyleBox, Row,Row,1,2);
00381       Row++;
00382       GridStyleBox->setCurrentItem(Diag->GridPen.style()-1);
00383     
00384       GridOn->setChecked(Diag->xAxis.GridOn);
00385       if(!Diag->xAxis.GridOn) slotSetGridBox(0);
00386       connect(GridOn, SIGNAL(stateChanged(int)), SLOT(slotSetGridBox(int)));
00387     }
00388     else {
00389       GridOn = 0;
00390       GridColorButt = 0;
00391       GridStyleBox = 0;
00392     }
00393 
00394     // ...........................................................
00395     xLabel->setText(Diag->xAxis.Label);
00396     ylLabel->setText(Diag->yAxis.Label);
00397     if(yrLabel)  yrLabel->setText(Diag->zAxis.Label);
00398 
00399     if((Diag->Name.left(4) == "Rect") || (Diag->Name == "Curve")) {
00400       GridLogX = new QCheckBox(tr("logarithmical X Axis Grid"), Tab2);
00401       gp->addMultiCellWidget(GridLogX, Row,Row,0,2);
00402       Row++;
00403 
00404       GridLogY = new QCheckBox(tr("logarithmical")+" "+NameY+" "+tr("Grid"), Tab2);
00405       gp->addMultiCellWidget(GridLogY, Row,Row,0,2);
00406       Row++;
00407 
00408       GridLogZ = new QCheckBox(tr("logarithmical")+" "+NameZ+" "+tr("Grid"), Tab2);
00409       gp->addMultiCellWidget(GridLogZ, Row,Row,0,2);
00410       Row++;
00411 
00412       // ...........................................................
00413       // transfer the diagram properties to the dialog
00414       GridLogX->setChecked(Diag->xAxis.log);
00415       GridLogY->setChecked(Diag->yAxis.log);
00416       GridLogZ->setChecked(Diag->zAxis.log);
00417 
00418 
00419       if(Diag->Name == "Rect3D") {
00420         hideInvisible = new QCheckBox(tr("hide invisible lines"), Tab2);
00421         gp->addMultiCellWidget(hideInvisible, Row,Row,0,2);
00422         Row++;
00423 
00424         QLabel *LabelRotX = new QLabel(tr("Rotation around x-Axis:"), Tab2);
00425         LabelRotX->setPaletteForegroundColor(Qt::red);
00426         gp->addWidget(LabelRotX, Row,0);
00427         SliderRotX = new QSlider(0,360,20, ((Rect3DDiagram*)Diag)->rotX,
00428          Qt::Horizontal, Tab2);
00429         gp->addWidget(SliderRotX, Row,1);
00430         connect(SliderRotX, SIGNAL(valueChanged(int)), SLOT(slotNewRotX(int)));
00431         rotationX = new QLineEdit(Tab2);
00432         rotationX->setValidator(ValInteger);
00433         rotationX->setMaxLength(3);
00434         rotationX->setMaximumWidth(40);
00435         gp->addWidget(rotationX, Row,2);
00436         connect(rotationX, SIGNAL(textChanged(const QString&)),
00437          SLOT(slotEditRotX(const QString&)));
00438         Row++;
00439 
00440         QLabel *LabelRotY = new QLabel(tr("Rotation around y-Axis:"), Tab2);
00441         LabelRotY->setPaletteForegroundColor(Qt::green);
00442         gp->addWidget(LabelRotY, Row,0);
00443         SliderRotY = new QSlider(0,360,20, ((Rect3DDiagram*)Diag)->rotY,
00444          Qt::Horizontal, Tab2);
00445         gp->addWidget(SliderRotY, Row,1);
00446         connect(SliderRotY, SIGNAL(valueChanged(int)), SLOT(slotNewRotY(int)));
00447         rotationY = new QLineEdit(Tab2);
00448         rotationY->setValidator(ValInteger);
00449         rotationY->setMaxLength(3);
00450         rotationY->setMaximumWidth(40);
00451         gp->addWidget(rotationY, Row,2);
00452         connect(rotationY, SIGNAL(textChanged(const QString&)),
00453          SLOT(slotEditRotY(const QString&)));
00454         Row++;
00455 
00456         QLabel *LabelRotZ = new QLabel(tr("Rotation around z-Axis:"), Tab2);
00457         LabelRotZ->setPaletteForegroundColor(Qt::blue);
00458         gp->addWidget(LabelRotZ, Row,0);
00459         SliderRotZ = new QSlider(0,360,20, ((Rect3DDiagram*)Diag)->rotZ,
00460          Qt::Horizontal, Tab2);
00461         gp->addWidget(SliderRotZ, Row,1);
00462         connect(SliderRotZ, SIGNAL(valueChanged(int)), SLOT(slotNewRotZ(int)));
00463         rotationZ = new QLineEdit(Tab2);
00464         rotationZ->setValidator(ValInteger);
00465         rotationZ->setMaxLength(3);
00466         rotationZ->setMaximumWidth(40);
00467         gp->addWidget(rotationZ, Row,2);
00468         connect(rotationZ, SIGNAL(textChanged(const QString&)),
00469          SLOT(slotEditRotZ(const QString&)));
00470         Row++;
00471 
00472         gp->addWidget(new QLabel(tr("2D-projection:"), Tab2), Row,0);
00473         DiagCross = new Cross3D(((Rect3DDiagram*)Diag)->rotX,
00474         ((Rect3DDiagram*)Diag)->rotY,
00475         ((Rect3DDiagram*)Diag)->rotZ, Tab2);
00476         gp->addWidget(DiagCross, Row,1);
00477 
00478         // transfer the diagram properties to the dialog
00479         hideInvisible->setChecked(Diag->hideLines);
00480         rotationX->setText(QString::number(((Rect3DDiagram*)Diag)->rotX));
00481         rotationY->setText(QString::number(((Rect3DDiagram*)Diag)->rotY));
00482         rotationZ->setText(QString::number(((Rect3DDiagram*)Diag)->rotZ));
00483 
00484       }
00485     }
00486     else GridLogX = GridLogY = GridLogZ = 0;
00487 
00488     t->addTab(Tab2, tr("Properties"));
00489 
00490     // Tab #3 - Limits ...........................................................
00491     QWidget *Tab3 = new QWidget();
00492     QVBoxLayout *Tab3Layout = new QVBoxLayout();
00493 
00494     QGroupBox *axisX = new QGroupBox(tr("x-Axis"));
00495     QHBoxLayout *axisXLayout = new QHBoxLayout();
00496 
00497     QWidget *VBox1 = new QWidget();
00498     axisXLayout->addWidget(VBox1);
00499     QVBoxLayout *VBox1Layout = new QVBoxLayout();
00500     VBox1Layout->addStretch();
00501     manualX = new QCheckBox(tr("manual"));//, VBox1);
00502     VBox1Layout->addWidget(manualX);
00503     VBox1->setLayout(VBox1Layout);
00504     connect(manualX, SIGNAL(stateChanged(int)), SLOT(slotManualX(int)));
00505 
00506     QWidget *VBox2 = new QWidget();
00507     axisXLayout->addWidget(VBox2);
00508     QVBoxLayout *VBox2Layout = new QVBoxLayout();
00509     VBox2Layout->addWidget(new QLabel(tr("start")));
00510     startX = new QLineEdit();
00511     VBox2Layout->addWidget(startX);
00512     startX->setValidator(ValDouble);
00513     VBox2->setLayout(VBox2Layout);
00514 
00515     QWidget *VBox3 = new QWidget();
00516     axisXLayout->addWidget(VBox3);
00517     QVBoxLayout *VBox3Layout = new QVBoxLayout();
00518     VBox3Layout->addWidget(new QLabel(tr("step")));
00519     stepX = new QLineEdit();//VBox3);
00520     VBox3Layout->addWidget(stepX);
00521     stepX->setValidator(ValDouble);
00522     VBox3->setLayout(VBox3Layout);
00523 
00524     QWidget *VBox4 = new QWidget();
00525     axisXLayout->addWidget(VBox4);
00526     QVBoxLayout *VBox4Layout = new QVBoxLayout();
00527     VBox4Layout->addWidget(new QLabel(tr("stop")));
00528     stopX = new QLineEdit();
00529     VBox4Layout->addWidget(stopX);
00530     stopX->setValidator(ValDouble);
00531     VBox4->setLayout(VBox4Layout);
00532 
00533     axisX->setLayout(axisXLayout);
00534     Tab3Layout->addWidget(axisX);
00535     Tab3Layout->addStretch();
00536 
00537     QGroupBox *axisY = new QGroupBox(NameY);
00538     QHBoxLayout *axisYLayout = new QHBoxLayout();
00539 
00540     QWidget *VBox5 = new QWidget();
00541     axisYLayout->addWidget(VBox5);
00542     QVBoxLayout *VBox5Layout = new QVBoxLayout();
00543     VBox5Layout->addStretch();
00544     manualY = new QCheckBox(tr("manual"));
00545     VBox5Layout->addWidget(manualY);
00546     connect(manualY, SIGNAL(stateChanged(int)), SLOT(slotManualY(int)));
00547     VBox5->setLayout(VBox5Layout);
00548 
00549     QWidget *VBox6 = new QWidget();
00550     axisYLayout->addWidget(VBox6);
00551     QVBoxLayout *VBox6Layout = new QVBoxLayout();
00552     VBox6Layout->addWidget(new QLabel(tr("start")));
00553     startY = new QLineEdit();
00554     VBox6Layout->addWidget(startY);
00555     startY->setValidator(ValDouble);
00556     VBox6->setLayout(VBox6Layout);
00557 
00558     QWidget *VBox7 = new QWidget();
00559     axisYLayout->addWidget(VBox7);
00560     QVBoxLayout *VBox7Layout = new QVBoxLayout();
00561     if((Diag->Name=="Smith") || (Diag->Name=="ySmith") || (Diag->Name=="PS"))
00562       VBox7Layout->addWidget(new QLabel(tr("number")));
00563     else  VBox7Layout->addWidget(new QLabel(tr("step")));
00564     stepY = new QLineEdit();
00565     VBox7Layout->addWidget(stepY);
00566     stepY->setValidator(ValDouble);
00567     VBox7->setLayout(VBox7Layout);
00568 
00569     QWidget *VBox8 = new QWidget();
00570     axisYLayout->addWidget(VBox8);
00571     QVBoxLayout *VBox8Layout = new QVBoxLayout();
00572     VBox8Layout->addWidget(new QLabel(tr("stop")));
00573     stopY = new QLineEdit();
00574     VBox8Layout->addWidget(stopY);
00575     stopY->setValidator(ValDouble);
00576     VBox8->setLayout(VBox8Layout);
00577 
00578     axisY->setLayout(axisYLayout);
00579     Tab3Layout->addWidget(axisY);
00580     Tab3Layout->addStretch();
00581 
00582     QGroupBox *axisZ = new QGroupBox(NameZ);
00583     QHBoxLayout *axisZLayout = new QHBoxLayout();
00584 
00585     QWidget *VBox9 = new QWidget();
00586     axisZLayout->addWidget(VBox9);
00587     QVBoxLayout *VBox9Layout = new QVBoxLayout();
00588     VBox9Layout->addStretch();
00589     manualZ = new QCheckBox(tr("manual"));
00590     VBox9Layout->addWidget(manualZ);
00591     connect(manualZ, SIGNAL(stateChanged(int)), SLOT(slotManualZ(int)));
00592     VBox9->setLayout(VBox9Layout);
00593 
00594     QWidget *VBox10 = new QWidget();
00595     axisZLayout->addWidget(VBox10);
00596     QVBoxLayout *VBox10Layout = new QVBoxLayout();
00597     VBox10Layout->addWidget(new QLabel(tr("start")));
00598     startZ = new QLineEdit();
00599     VBox10Layout->addWidget(startZ);
00600     startZ->setValidator(ValDouble);
00601     VBox10->setLayout(VBox10Layout);
00602 
00603     QWidget *VBox11 = new QWidget();
00604     axisZLayout->addWidget(VBox11);
00605     QVBoxLayout *VBox11Layout = new QVBoxLayout();
00606     if(Diag->Name == "SP") VBox11Layout->addWidget(new QLabel(tr("number")));
00607     else VBox11Layout->addWidget(new QLabel(tr("step")));
00608     stepZ = new QLineEdit();
00609     VBox11Layout->addWidget(stepZ);
00610     stepZ->setValidator(ValDouble);
00611     VBox11->setLayout(VBox11Layout);
00612 
00613     QWidget *VBox12 = new QWidget();
00614     axisZLayout->addWidget(VBox12);
00615     QVBoxLayout *VBox12Layout = new QVBoxLayout();
00616     VBox12Layout->addWidget(new QLabel(tr("stop")));
00617     stopZ = new QLineEdit();
00618     VBox12Layout->addWidget(stopZ);
00619     stopZ->setValidator(ValDouble);
00620     VBox12->setLayout(VBox12Layout);
00621 
00622     Tab3Layout->setStretchFactor(new QWidget(Tab3),5); // stretchable placeholder
00623 
00624     axisZ->setLayout(axisZLayout);
00625     Tab3Layout->addWidget(axisZ);
00626 
00627     Tab3->setLayout(Tab3Layout);
00628     t->addTab(Tab3, tr("Limits"));
00629 
00630     // ...........................................................
00631     // transfer the diagram properties to the dialog
00632     if(Diag->xAxis.autoScale)  slotManualX(0);
00633     else  manualX->setChecked(true);
00634     if(Diag->yAxis.autoScale)  slotManualY(0);
00635     else  manualY->setChecked(true);
00636     if(Diag->zAxis.autoScale)  slotManualZ(0);
00637     else  manualZ->setChecked(true);
00638 
00639     Diag->calcLimits();    // inserts auto-scale values if not manual
00640 
00641     startX->setText(QString::number(Diag->xAxis.limit_min));
00642     stepX->setText(QString::number(Diag->xAxis.step));
00643     stopX->setText(QString::number(Diag->xAxis.limit_max));
00644 
00645     startY->setText(QString::number(Diag->yAxis.limit_min));
00646     stepY->setText(QString::number(Diag->yAxis.step));
00647     stopY->setText(QString::number(Diag->yAxis.limit_max));
00648 
00649     startZ->setText(QString::number(Diag->zAxis.limit_min));
00650     stepZ->setText(QString::number(Diag->zAxis.step));
00651     stopZ->setText(QString::number(Diag->zAxis.limit_max));
00652 
00653     if((Diag->Name == "Smith") || (Diag->Name == "ySmith") ||
00654        (Diag->Name == "Polar")) {
00655        axisZ->setEnabled(false);
00656     }
00657     if(Diag->Name.left(4) != "Rect")   // cartesian 2D and 3D
00658       if(Diag->Name != "Curve") {
00659         axisX->setEnabled(false);
00660         startY->setEnabled(false);
00661         startZ->setEnabled(false);
00662       }
00663   }
00664   else  stepX = 0;
00665 
00666   connect(t, SIGNAL(currentChanged(QWidget*)), SLOT(slotChangeTab(QWidget*)));
00667   // ...........................................................
00668   QWidget *Butts = new QWidget();
00669   QHBoxLayout *ButtsLayout = new QHBoxLayout();
00670   ButtsLayout->setSpacing(5);
00671   ButtsLayout->setMargin(5);
00672   Butts->setLayout(ButtsLayout);
00673   all->addWidget(Butts);
00674 
00675   QPushButton *OkButt = new QPushButton(tr("OK"));
00676   ButtsLayout->addWidget(OkButt);
00677   connect(OkButt, SIGNAL(clicked()), SLOT(slotOK()));
00678   QPushButton *ApplyButt = new QPushButton(tr("Apply"));
00679   ButtsLayout->addWidget(ApplyButt);
00680   connect(ApplyButt, SIGNAL(clicked()), SLOT(slotApply()));
00681   QPushButton *CancelButt = new QPushButton(tr("Cancel"));
00682   ButtsLayout->addWidget(CancelButt);
00683   connect(CancelButt, SIGNAL(clicked()), SLOT(slotCancel()));
00684 
00685   OkButt->setDefault(true);
00686 
00687 
00688   // ...........................................................
00689   // put all data files into ComboBox
00690   QFileInfo Info(defaultDataSet);
00691   QDir ProjDir(Info.dirPath());
00692   QStringList Elements = ProjDir.entryList("*.dat", QDir::Files, QDir::Name);
00693   QStringList::iterator it;
00694   for(it = Elements.begin(); it != Elements.end(); ++it) {
00695     ChooseData->insertItem((*it).left((*it).length()-4));
00696     if((*it) == Info.fileName())
00697       // default dataset should be the current
00698       ChooseData->setCurrentItem(ChooseData->count()-1);
00699   }
00700   slotReadVars(0);  // put variables into the ListView
00701 
00702   // ...........................................................
00703   // put all graphs into the ListBox
00704   Row = 0;
00705   foreach(Graph *pg, Diag->Graphs) {
00706     GraphList->insertItem(Row, pg->Var);
00707     if(pg == currentGraph) {
00708       GraphList->setCurrentRow(Row);   // select current graph
00709       SelectGraph(currentGraph);
00710     }
00711     Row++;
00712   }
00713 
00714   if(ColorButt) {
00715     if(!currentGraph) {
00716       QColor selectedColor(DefaultColors[GraphList->count()%NumDefaultColors]);
00717       QString stylesheet = QString("QPushButton {background-color: %1};").arg(selectedColor.name());
00718       ColorButt->setStyleSheet(stylesheet);
00719       ColorButt->setPaletteBackgroundColor(selectedColor);
00720     }
00721   }
00722 }
00723 
00724 DiagramDialog::~DiagramDialog()
00725 {
00726   delete all;   // delete all widgets from heap
00727   delete ValInteger;
00728   delete ValDouble;
00729   delete Validator;
00730 }
00731 
00732 // --------------------------------------------------------------------------
00733 void DiagramDialog::slotReadVars(int)
00734 {
00735   QFileInfo Info(defaultDataSet);
00736   QString DocName = ChooseData->currentText()+".dat";
00737 
00738   QFile file(Info.dirPath() + QDir::separator() + DocName);
00739   if(!file.open(QIODevice::ReadOnly)) {
00740     return;
00741   }
00742 
00743   QString Line, tmp, Var;
00744   int varNumber = 0;
00745   // reading the file as a whole improves speed very much, also using
00746   // a QByteArray rather than a QString
00747   QByteArray FileString = file.readAll();
00748   file.close();
00749 
00750   // make sure sorting is disabled before inserting items
00751   ChooseVars->setSortingEnabled(false);
00752   ChooseVars->clearContents();
00753   int i=0, j=0;
00754   i = FileString.indexOf('<')+1;
00755   if(i > 0)
00756   do {
00757     j = FileString.indexOf('>', i);
00758     for(int k=0;k<j-i;k++) Line[k]=FileString[k+i];
00759     Line.truncate(j-i);
00760     i = FileString.indexOf('<', j)+1;
00761 
00762     Var = Line.section(' ', 1, 1).remove('>');
00763     if(Var.length()>0)
00764       if(Var.at(0) == '_')  continue;
00765 
00766     if(Line.left(3) == "dep") {
00767       tmp = Line.section(' ', 2);
00768       //new Q3ListViewItem(ChooseVars, Var, "dep", tmp.remove('>'));
00769       qDebug() << varNumber << Var << tmp.remove('>');
00770       ChooseVars->setRowCount(varNumber+1);
00771       QTableWidgetItem *cell = new QTableWidgetItem(Var);
00772       cell->setFlags(cell->flags() ^ Qt::ItemIsEditable);
00773       ChooseVars->setItem(varNumber, 0, cell);
00774       cell = new QTableWidgetItem("dep");
00775       cell->setFlags(cell->flags() ^ Qt::ItemIsEditable);
00776       ChooseVars->setItem(varNumber, 1, cell);
00777       cell = new QTableWidgetItem(tmp.remove('>'));
00778       cell->setFlags(cell->flags() ^ Qt::ItemIsEditable);
00779       ChooseVars->setItem(varNumber, 2, cell);
00780       varNumber++;
00781     }
00782     else if(Line.left(5) == "indep") {
00783       tmp = Line.section(' ', 2, 2);
00784       //new Q3ListViewItem(ChooseVars, Var, "indep", tmp.remove('>'));
00785       qDebug() << varNumber << Var << tmp.remove('>');
00786       ChooseVars->setRowCount(varNumber+1);
00787       QTableWidgetItem *cell = new QTableWidgetItem(Var);
00788       cell->setFlags(cell->flags() ^ Qt::ItemIsEditable);
00789       ChooseVars->setItem(varNumber, 0, cell);
00790       cell = new QTableWidgetItem("indep");
00791       cell->setFlags(cell->flags() ^ Qt::ItemIsEditable);
00792       ChooseVars->setItem(varNumber, 1, cell);
00793       cell = new QTableWidgetItem(tmp.remove('>'));
00794       cell->setFlags(cell->flags() ^ Qt::ItemIsEditable);
00795       ChooseVars->setItem(varNumber, 2, cell);
00796       varNumber++;
00797 
00798     }
00799   } while(i > 0);
00800   // sorting should be enabled only after adding items
00801   ChooseVars->setSortingEnabled(true);
00802 }
00803 
00804 // ------------------------------------------------------------------------
00805 // Inserts the double-clicked variable into the Graph Input Line at the
00806 // cursor position. If the Graph Input is empty, then the variable is
00807 // also inserted as graph.
00808 void DiagramDialog::slotTakeVar(QTableWidgetItem* Item)
00809 {
00810   GraphInput->blockSignals(true);
00811   if(toTake) GraphInput->setText("");
00812 
00813   GraphInput->cursorPosition();
00814   //QString s="";
00815   //QString s1 = Item->text();
00816   int row = Item->row();
00817   QString s1 = ChooseVars->item(row, 0)->text();
00818   QFileInfo Info(defaultDataSet);
00819   if(ChooseData->currentText() != Info.baseName(true))
00820     s1 = ChooseData->currentText() + ":" + s1;
00821   GraphInput->setText(s1);
00822 
00823   //if(s.isEmpty()) {
00824     GraphList->addItem(GraphInput->text());
00825     GraphList->setCurrentRow(GraphList->count()-1);
00826 
00827     Graph *g = new Graph(Diag, GraphInput->text());   // create a new graph
00828 
00829     if(Diag->Name != "Tab") {
00830       if(Diag->Name != "Truth") {
00831         g->Color = ColorButt->paletteBackgroundColor();
00832         g->Thick = Property2->text().toInt();
00833         QColor selectedColor(DefaultColors[GraphList->count()%NumDefaultColors]);
00834         QString stylesheet = QString("QPushButton {background-color: %1};").arg(selectedColor.name());
00835         ColorButt->setStyleSheet(stylesheet);
00836         ColorButt->setPaletteBackgroundColor(selectedColor);
00837         if(g->Var.right(3) == ".Vb")   // harmonic balance output ?
00838           if(PropertyBox->count() >= GRAPHSTYLE_ARROW)
00839             PropertyBox->setCurrentItem(GRAPHSTYLE_ARROW);
00840         g->Style = toGraphStyle(PropertyBox->currentItem());
00841         assert(g->Style!=GRAPHSTYLE_INVALID);
00842         if(yAxisBox) {
00843           g->yAxisNo = yAxisBox->currentItem();
00844           yAxisBox->setEnabled(true);
00845           Label4->setEnabled(true);
00846         }
00847         else if(Diag->Name == "Rect3D") g->yAxisNo = 1;
00848 
00849         Label3->setEnabled(true);
00850         ColorButt->setEnabled(true);
00851       }
00852     }
00853     else {
00854       g->Precision = Property2->text().toInt();
00855       g->numMode   = PropertyBox->currentItem();
00856     }
00857 
00858     Graphs.append(g);
00859     changed = true;
00860     toTake  = true;
00861   //}
00862 
00863   GraphInput->blockSignals(false);
00864 
00865   if(Property2) {
00866     Label1->setEnabled(true);
00867     PropertyBox->setEnabled(true);
00868     Label2->setEnabled(true);
00869     Property2->setEnabled(true);
00870   }
00871 }
00872 
00876 void DiagramDialog::slotSelectGraph(QListWidgetItem *item)
00877 {
00878   if(item == 0) {
00879     GraphList->clearSelection();
00880     return;
00881   }
00882 
00883   SelectGraph (Graphs.at (GraphList->currentRow()));
00884 }
00885 
00889 void DiagramDialog::SelectGraph(Graph *g)
00890 {
00891   GraphInput->blockSignals(true);
00892   GraphInput->setText(g->Var);
00893   GraphInput->blockSignals(false);
00894 
00895   if(Diag->Name != "Tab") {
00896     if(Diag->Name != "Truth") {
00897       Property2->setText(QString::number(g->Thick));
00898       QString stylesheet = QString("QPushButton {background-color: %1};").arg(g->Color.name());
00899       ColorButt->setStyleSheet(stylesheet);
00900       ColorButt->setPaletteBackgroundColor(g->Color);
00901       PropertyBox->setCurrentItem(g->Style);
00902       if(yAxisBox) {
00903         yAxisBox->setCurrentItem(g->yAxisNo);
00904         yAxisBox->setEnabled(true);
00905         Label4->setEnabled(true);
00906       }
00907 
00908       Label3->setEnabled(true);
00909       ColorButt->setEnabled(true);
00910     }
00911   }
00912   else {
00913     Property2->setText(QString::number(g->Precision));
00914     PropertyBox->setCurrentItem(g->numMode);
00915   }
00916   toTake = false;
00917 
00918   if(Property2) {
00919     Label1->setEnabled(true);
00920     PropertyBox->setEnabled(true);
00921     Label2->setEnabled(true);
00922     Property2->setEnabled(true);
00923   }
00924 }
00925 
00929 void DiagramDialog::slotDeleteGraph()
00930 {
00931   int i = GraphList->currentRow();
00932   if(i < 0) return;   // return, if no item selected
00933 
00934   GraphList->takeItem(i);
00935   Graphs.remove(i);
00936 
00937   int k=0;
00938   if (GraphList->count()!=0) {
00939       if (i>(GraphList->count()-1)) {
00940           k = GraphList->count()-1;
00941       } else {
00942           k=i;
00943       }
00944       GraphInput->setText(GraphList->item(k)->text());
00945   } else {
00946       GraphInput->setText("");  // erase input line and back to default values
00947   }
00948 
00949   if(Diag->Name != "Tab") {
00950     if(Diag->Name != "Truth") {
00951       QColor selectedColor(DefaultColors[GraphList->count()%NumDefaultColors]);
00952       QString stylesheet = QString("QPushButton {background-color: %1};").arg(selectedColor.name());
00953       ColorButt->setStyleSheet(stylesheet);
00954       ColorButt->setPaletteBackgroundColor(selectedColor);
00955       Property2->setText("0");
00956       if(yAxisBox) {
00957         yAxisBox->setCurrentItem(0);
00958         yAxisBox->setEnabled(false);
00959         Label4->setEnabled(false);
00960       }
00961 
00962       Label3->setEnabled(false);
00963       ColorButt->setEnabled(false);
00964     }
00965   }
00966   else  Property2->setText("3");
00967   changed = true;
00968   toTake  = false;
00969 
00970   if(Property2) {
00971     PropertyBox->setCurrentItem(0);
00972 
00973     Label1->setEnabled(false);
00974     PropertyBox->setEnabled(false);
00975     Label2->setEnabled(false);
00976     Property2->setEnabled(false);
00977   }
00978 }
00979 
00980 // --------------------------------------------------------------------------
00981 void DiagramDialog::slotNewGraph()
00982 {
00983   assert(Diag);
00984   if(GraphInput->text().isEmpty()) return;
00985 
00986   GraphList->addItem(GraphInput->text());
00987 
00988   Graph *g = new Graph(Diag, GraphInput->text());
00989 // FIXME: call  Diag->whateverelse();
00990   if(Diag->Name != "Tab") { // BUG
00991     if(Diag->Name != "Truth") { // BUG
00992       g->Color = ColorButt->paletteBackgroundColor();
00993       g->Thick = Property2->text().toInt();
00994       g->Style = toGraphStyle(PropertyBox->currentItem());
00995       assert(g->Style!=GRAPHSTYLE_INVALID);
00996       if(yAxisBox)  g->yAxisNo = yAxisBox->currentItem();
00997       else if(Diag->Name == "Rect3D")  g->yAxisNo = 1;
00998     }
00999   }
01000   else {
01001     g->Precision = Property2->text().toInt();
01002     g->numMode   = PropertyBox->currentItem();
01003   }
01004   Graphs.append(g);
01005   changed = true;
01006   toTake  = false;
01007 }
01008 
01012 void DiagramDialog::slotOK()
01013 {
01014   slotApply();
01015   slotCancel();
01016 }
01017 
01021 void DiagramDialog::slotApply()
01022 {
01023   if(Diag->Name.at(0) != 'T') {  // not tabular or timing
01024     if(Diag->xAxis.Label.isEmpty())
01025       Diag->xAxis.Label = ""; // can be not 0 and empty!
01026     if(xLabel->text().isEmpty()) xLabel->setText("");
01027     if(Diag->xAxis.Label != xLabel->text()) {
01028       Diag->xAxis.Label = xLabel->text();
01029       changed = true;
01030     }
01031     if(Diag->yAxis.Label.isEmpty())
01032       Diag->yAxis.Label = ""; // can be not 0 and empty!
01033     if(ylLabel->text().isEmpty()) ylLabel->setText("");
01034     if(Diag->yAxis.Label != ylLabel->text()) {
01035       Diag->yAxis.Label = ylLabel->text();
01036       changed = true;
01037     }
01038     
01039     if(GridOn) if(Diag->xAxis.GridOn != GridOn->isChecked()) {
01040       Diag->xAxis.GridOn = GridOn->isChecked();
01041       Diag->yAxis.GridOn = GridOn->isChecked();
01042       changed = true;
01043     }
01044     if(GridColorButt)
01045       if(Diag->GridPen.color() != GridColorButt->paletteBackgroundColor()) {
01046       Diag->GridPen.setColor(GridColorButt->paletteBackgroundColor());
01047       changed = true;
01048     }
01049     if(GridStyleBox)
01050       if(Diag->GridPen.style()!=(Qt::PenStyle)(GridStyleBox->currentItem()+1)) {
01051       Diag->GridPen.setStyle((Qt::PenStyle)(GridStyleBox->currentItem()+1));
01052       changed = true;
01053     }
01054     if((Diag->Name != "Smith") && (Diag->Name != "Polar")) {
01055       if(Diag->zAxis.Label.isEmpty())
01056         Diag->zAxis.Label = ""; // can be not 0 and empty!
01057       if(yrLabel->text().isEmpty()) yrLabel->setText("");
01058       if(Diag->zAxis.Label != yrLabel->text()) {
01059         Diag->zAxis.Label = yrLabel->text();
01060         changed = true;
01061       }
01062     }
01063 
01064     if(Diag->Name.left(4) == "Rect") {
01065       if(Diag->xAxis.log != GridLogX->isChecked()) {
01066         Diag->xAxis.log = GridLogX->isChecked();
01067         changed = true;
01068       }
01069       if(Diag->yAxis.log != GridLogY->isChecked()) {
01070         Diag->yAxis.log = GridLogY->isChecked();
01071         changed = true;
01072       }
01073       if(Diag->zAxis.log != GridLogZ->isChecked()) {
01074         Diag->zAxis.log = GridLogZ->isChecked();
01075         changed = true;
01076       }
01077     }
01078 
01079     if((Diag->Name == "Smith") || (Diag->Name == "ySmith") ||
01080           (Diag->Name == "PS"))
01081       if(stopY->text().toDouble() < 1.0)
01082         stopY->setText("1");
01083 
01084     if(Diag->Name == "SP")
01085       if(stopZ->text().toDouble() < 1.0)
01086         stopZ->setText("1");
01087 
01088     if(Diag->xAxis.autoScale == manualX->isChecked()) {
01089       Diag->xAxis.autoScale = !(manualX->isChecked());
01090       changed = true;
01091     }
01092 
01093     // Use string compares for all floating point numbers, in
01094     // order to avoid rounding problems.
01095     if(QString::number(Diag->xAxis.limit_min) != startX->text()) {
01096       Diag->xAxis.limit_min = startX->text().toDouble();
01097       changed = true;
01098     }
01099     if(QString::number(Diag->xAxis.step) != stepX->text()) {
01100       Diag->xAxis.step = stepX->text().toDouble();
01101       changed = true;
01102     }
01103     if(QString::number(Diag->xAxis.limit_max) != stopX->text()) {
01104       Diag->xAxis.limit_max = stopX->text().toDouble();
01105       changed = true;
01106     }
01107     if(Diag->yAxis.autoScale == manualY->isChecked()) {
01108       Diag->yAxis.autoScale = !(manualY->isChecked());
01109       changed = true;
01110     }
01111     if(QString::number(Diag->yAxis.limit_min) != startY->text()) {
01112       Diag->yAxis.limit_min = startY->text().toDouble();
01113       changed = true;
01114     }
01115     if(QString::number(Diag->yAxis.step) != stepY->text()) {
01116       Diag->yAxis.step = stepY->text().toDouble();
01117       changed = true;
01118     }
01119     if(QString::number(Diag->yAxis.limit_max) != stopY->text()) {
01120       Diag->yAxis.limit_max = stopY->text().toDouble();
01121       changed = true;
01122     }
01123     if(Diag->zAxis.autoScale == manualZ->isChecked()) {
01124       Diag->zAxis.autoScale = !(manualZ->isChecked());
01125       changed = true;
01126     }
01127     if(QString::number(Diag->zAxis.limit_min) != startZ->text()) {
01128       Diag->zAxis.limit_min = startZ->text().toDouble();
01129       changed = true;
01130     }
01131     if(QString::number(Diag->zAxis.step) != stepZ->text()) {
01132       Diag->zAxis.step = stepZ->text().toDouble();
01133       changed = true;
01134     }
01135     if(QString::number(Diag->zAxis.limit_max) != stopZ->text()) {
01136       Diag->zAxis.limit_max = stopZ->text().toDouble();
01137       changed = true;
01138     }
01139 
01140     // for "rect3D"
01141     if(hideInvisible)
01142       if(((Rect3DDiagram*)Diag)->hideLines != hideInvisible->isChecked()) {
01143         ((Rect3DDiagram*)Diag)->hideLines = hideInvisible->isChecked();
01144         changed = true;
01145       }
01146 
01147     if(rotationX)
01148       if(((Rect3DDiagram*)Diag)->rotX != rotationX->text().toInt()) {
01149         ((Rect3DDiagram*)Diag)->rotX = rotationX->text().toInt();
01150         changed = true;
01151       }
01152 
01153     if(rotationY)
01154       if(((Rect3DDiagram*)Diag)->rotY != rotationY->text().toInt()) {
01155         ((Rect3DDiagram*)Diag)->rotY = rotationY->text().toInt();
01156         changed = true;
01157       }
01158 
01159     if(rotationZ)
01160       if(((Rect3DDiagram*)Diag)->rotZ != rotationZ->text().toInt()) {
01161         ((Rect3DDiagram*)Diag)->rotZ = rotationZ->text().toInt();
01162         changed = true;
01163       }
01164 
01165   }   // of "if(Diag->Name != "Tab")"
01166 
01167   Diag->Graphs.clear();   // delete the graphs
01168   Graphs.setAutoDelete(false);
01169   for(Graph *pg = Graphs.first(); pg != 0; pg = Graphs.next())
01170     Diag->Graphs.append(pg);  // transfer the new graphs to diagram
01171   Graphs.clear();
01172   Graphs.setAutoDelete(true);
01173 
01174   Diag->loadGraphData(defaultDataSet);
01175   ((Schematic*)parent())->viewport()->repaint();
01176   copyDiagramGraphs();
01177   if(changed) transfer = true;   // changes have been applied ?
01178 }
01179 
01180 
01181 // --------------------------------------------------------------------------
01182 // Is called if "Cancel" button is pressed.
01183 void DiagramDialog::slotCancel()
01184 {
01185 //  Diag->loadGraphData(defaultDataSet);
01186 //  ((QucsView*)parent())->viewport()->repaint();
01187   if(transfer) done(QDialog::Accepted);
01188   else done(QDialog::Rejected);
01189 }
01190 
01191 //-----------------------------------------------------------------
01192 // To get really all close events (even <Escape> key).
01193 void DiagramDialog::reject()
01194 {
01195   slotCancel();
01196 }
01197 
01198 // --------------------------------------------------------------------------
01199 void DiagramDialog::slotSetColor()
01200 {
01201   QColor c = QColorDialog::getColor(ColorButt->paletteBackgroundColor(),this);
01202   if(!c.isValid()) return;
01203   QString stylesheet = QString("QPushButton {background-color: %1};").arg(c.name());
01204   ColorButt->setStyleSheet(stylesheet);
01205   ColorButt->setPaletteBackgroundColor(c);
01206 
01207   int i = GraphList->currentRow();
01208   if(i < 0) return;   // return, if no item selected
01209 
01210   Graph *g = Graphs.at(i);
01211   g->Color = c;
01212   changed = true;
01213   toTake  = false;
01214 }
01215 
01216 // --------------------------------------------------------------------------
01217 void DiagramDialog::slotSetGridColor()
01218 {
01219   QColor c = QColorDialog::getColor(
01220       GridColorButt->paletteBackgroundColor(),this);
01221   if(!c.isValid()) return;
01222   GridColorButt->setPaletteBackgroundColor(c);
01223   changed = true;
01224 }
01225 
01229 void DiagramDialog::slotResetToTake(const QString& s)
01230 {
01231   int i = GraphList->currentRow();
01232   if(i < 0) return;   // return, if no item selected
01233 
01234   Graph *g = Graphs.at(i);
01235   g->Var = s;
01236   // \todo GraphList->changeItem(s, i);   // must done after the graph settings !!!
01237   changed = true;
01238   toTake  = false;
01239 }
01240 
01244 void DiagramDialog::slotSetProp2(const QString& s)
01245 {
01246   int i = GraphList->currentRow();
01247   if(i < 0) return;   // return, if no item selected
01248 
01249   Graph *g = Graphs.at(i);
01250   if(Diag->Name == "Tab") g->Precision = s.toInt();
01251   else  g->Thick = s.toInt();
01252   changed = true;
01253   toTake  = false;
01254 }
01255 
01259 void DiagramDialog::slotSetNumMode(int Mode)
01260 {
01261   int i = GraphList->currentRow();
01262   if(i < 0) return;   // return, if no item selected
01263 
01264   Graph *g = Graphs.at(i);
01265   g->numMode = Mode;
01266   changed = true;
01267   toTake  = false;
01268 }
01269 
01273 void DiagramDialog::slotSetGridBox(int state)
01274 {
01275   if(state == 2) {
01276     GridColorButt->setEnabled(true);
01277     GridStyleBox->setEnabled(true);
01278     GridLabel1->setEnabled(true);
01279     GridLabel2->setEnabled(true);
01280   }
01281   else {
01282     GridColorButt->setEnabled(false);
01283     GridStyleBox->setEnabled(false);
01284     GridLabel1->setEnabled(false);
01285     GridLabel2->setEnabled(false);
01286   }
01287 }
01288 
01292 void DiagramDialog::slotSetGraphStyle(int style)
01293 {
01294   int i = GraphList->currentRow();
01295   if(i < 0) return;   // return, if no item selected
01296 
01297   Graph *g = Graphs.at(i);
01298   g->Style = toGraphStyle(style);
01299   assert(g->Style!=GRAPHSTYLE_INVALID);
01300   changed = true;
01301   toTake  = false;
01302 }
01303 
01307 void DiagramDialog::copyDiagramGraphs()
01308 {
01309   foreach(Graph *pg, Diag->Graphs)
01310     Graphs.append(pg->sameNewOne());
01311 }
01312 
01316 void DiagramDialog::slotSetYAxis(int axis)
01317 {
01318   int i = GraphList->currentRow();
01319   if(i < 0) return;   // return, if no item selected
01320 
01321   Graph *g = Graphs.at(i);
01322   g->yAxisNo = axis;
01323   changed = true;
01324   toTake  = false;
01325 }
01326 
01327 // --------------------------------------------------------------------------
01328 void DiagramDialog::slotManualX(int state)
01329 {
01330   if(state == 2) {
01331     if((Diag->Name.left(4) == "Rect") || (Diag->Name == "Curve"))
01332       startX->setEnabled(true);
01333     stopX->setEnabled(true);
01334     if(GridLogX) if(GridLogX->isChecked())  return;
01335     stepX->setEnabled(true);
01336   }
01337   else {
01338     startX->setEnabled(false);
01339     stepX->setEnabled(false);
01340     stopX->setEnabled(false);
01341   }
01342 }
01343 
01344 // --------------------------------------------------------------------------
01345 void DiagramDialog::slotManualY(int state)
01346 {
01347   if(state == 2) {
01348     if((Diag->Name.left(4) == "Rect") || (Diag->Name == "Curve"))
01349       startY->setEnabled(true);
01350     stopY->setEnabled(true);
01351     if(GridLogY) if(GridLogY->isChecked())  return;
01352     stepY->setEnabled(true);
01353   }
01354   else {
01355     startY->setEnabled(false);
01356     stepY->setEnabled(false);
01357     stopY->setEnabled(false);
01358   }
01359 }
01360 
01361 // --------------------------------------------------------------------------
01362 void DiagramDialog::slotManualZ(int state)
01363 {
01364   if(state == 2) {
01365     if((Diag->Name.left(4) == "Rect") || (Diag->Name == "Curve"))
01366       startZ->setEnabled(true);
01367     stopZ->setEnabled(true);
01368     if(GridLogZ) if(GridLogZ->isChecked())  return;
01369     stepZ->setEnabled(true);
01370   }
01371   else {
01372     startZ->setEnabled(false);
01373     stepZ->setEnabled(false);
01374     stopZ->setEnabled(false);
01375   }
01376 }
01377 
01381 void DiagramDialog::slotChangeTab(QWidget*)
01382 {
01383   if(stepX == 0) return;   // defined ?
01384   if(GridLogX) {
01385     if(GridLogX->isChecked())  stepX->setEnabled(false);
01386     else  if(manualX->isChecked())  stepX->setEnabled(true);
01387   }
01388   if(GridLogY) {
01389     if(GridLogY->isChecked())  stepY->setEnabled(false);
01390     else  if(manualY->isChecked())  stepY->setEnabled(true);
01391   }
01392   if(GridLogZ) {
01393     if(GridLogZ->isChecked())  stepZ->setEnabled(false);
01394     else  if(manualZ->isChecked())  stepZ->setEnabled(true);
01395   }
01396 }
01397 
01398 
01402 void DiagramDialog::slotNewRotX(int Value)
01403 {
01404   rotationX->setText(QString::number(Value));
01405   DiagCross->rotX = float(Value) * pi/180.0;
01406   DiagCross->update();
01407 }
01408 
01412 void DiagramDialog::slotNewRotY(int Value)
01413 {
01414   rotationY->setText(QString::number(Value));
01415   DiagCross->rotY = float(Value) * pi/180.0;
01416   DiagCross->update();
01417 }
01418 
01422 void DiagramDialog::slotNewRotZ(int Value)
01423 {
01424   rotationZ->setText(QString::number(Value));
01425   DiagCross->rotZ = float(Value) * pi/180.0;
01426   DiagCross->update();
01427 }
01428 
01432 void DiagramDialog::slotEditRotX(const QString& Text)
01433 {
01434   SliderRotX->setValue(Text.toInt());
01435   DiagCross->rotX = Text.toFloat() * pi/180.0;
01436   DiagCross->update();
01437 }
01438 
01442 void DiagramDialog::slotEditRotY(const QString& Text)
01443 {
01444   SliderRotY->setValue(Text.toInt());
01445   DiagCross->rotY = Text.toFloat() * pi/180.0;
01446   DiagCross->update();
01447 }
01448 
01452 void DiagramDialog::slotEditRotZ(const QString& Text)
01453 {
01454   SliderRotZ->setValue(Text.toInt());
01455   DiagCross->rotZ = Text.toFloat() * pi/180.0;
01456   DiagCross->update();
01457 }
01458 
01459 // vim:ts=8:sw=2:noet
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines