File indexing completed on 2024-04-21 03:40:35

0001 /*************************************************************************************
0002  *  Copyright (C) 2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>      *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 #include <QMainWindow>
0020 #include <QTreeView>
0021 #include <QSplitter>
0022 #include <QStatusBar>
0023 #include <QVBoxLayout>
0024 
0025 #include <QCommandLineParser>
0026 #include <QApplication>
0027 
0028 #include "analitzaplot/planecurve.h"
0029 #include "analitzaplot/surface.h"
0030 #include "analitzaplot/plotsmodel.h"
0031 #include "analitzawidgets/plotsview2d.h"
0032 #include <plotsfactory.h>
0033 #include <analitza/expression.h>
0034 
0035 using namespace Analitza;
0036 
0037 int main(int argc, char *argv[])
0038 {
0039     QApplication app(argc, argv);
0040     QCommandLineParser parser;
0041     parser.setApplicationDescription(QStringLiteral("PlotView2DTest"));
0042     parser.addOption(QCommandLineOption(QStringLiteral("all-disabled"), app.tr("marks all the plots as not visible")));
0043     parser.process(app);
0044 
0045     QMainWindow *mainWindow = new QMainWindow();
0046     mainWindow->setMinimumSize(640, 480);
0047     mainWindow->statusBar()->show();
0048 
0049     QWidget *central = new QWidget(mainWindow);
0050     QVBoxLayout *layout = new QVBoxLayout(central);
0051     
0052     QSplitter *tabs = new QSplitter(Qt::Horizontal, central);
0053 
0054     layout->addWidget(tabs);
0055 
0056     //BEGIN test calls
0057     
0058     PlotsModel *model = new PlotsModel(tabs);
0059     
0060     PlotsView2D *view2d = new PlotsView2D(tabs);
0061 //     view2d->setSquares(false);
0062     view2d->setModel(model);
0063 
0064     PlotsFactory* s = PlotsFactory::self();
0065     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("4*sin(2*q)")), Dim2D).create(Qt::cyan, QStringLiteral("polar curv")));
0066     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("p**2=cos(r)*(3*pi/4)**2")), Dim2D).create(Qt::yellow, QStringLiteral("implicit polar curv")));
0067     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("x->x*x")), Dim2D).create(Qt::magenta, QStringLiteral("f(x)")));
0068     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("(2*x+y)*(x^2+y^2)^4+2*y*(5*x^4+10*x^2*y^2-3*y^4)+y=2*x")), Dim2D).create(Qt::green, QStringLiteral("khipu")));
0069     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("t->vector{t*t+1, t+2}")), Dim2D).create(Qt::blue, QStringLiteral("param2d1")));
0070     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("(x,y)->x*x-y*y")), Dim3D).create(Qt::red, QStringLiteral("3D")));
0071 
0072     //END test calls
0073 
0074     if(parser.isSet(QStringLiteral("all-disabled")))
0075         for(int i=0; i<model->rowCount(); ++i)
0076             model->setData(model->index(i), false, Qt::CheckStateRole);
0077 
0078     QTreeView *viewsource = new QTreeView(tabs);
0079     viewsource->setModel(model);
0080     
0081     view2d->setSelectionModel(viewsource->selectionModel());
0082     
0083     tabs->addWidget(viewsource);
0084     tabs->addWidget(view2d);
0085 
0086     PlotsModel *model2 = new PlotsModel(tabs);
0087     view2d->setModel(model2);
0088     
0089     view2d->setModel(model);
0090 
0091     mainWindow->setCentralWidget(central);
0092 
0093     mainWindow->show();
0094 
0095     return app.exec();
0096 }
0097