Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 28th, 2013  |  syntax: C++  |  size: 3.81 KB  |  views: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <QtSql/QSqlDatabase>
  2. #include <QtSql/QSqlQuery>
  3. #include <QtGui>
  4. #include <QObject>
  5. #include <QInputDialog>
  6. #include <QDebug>
  7. #include "graph.h"
  8.  
  9. Graph::Graph(QMainWindow *parent) :
  10.     QMainWindow(parent)
  11. {
  12.     customPlot = new QCustomPlot;
  13.     customPlot->setEnabled(false);
  14.  
  15.     srand(QDateTime::currentDateTime().toTime_t());
  16.  
  17.     customPlot->setInteractions(QCustomPlot::iRangeDrag | QCustomPlot::iRangeZoom | QCustomPlot::iSelectAxes |
  18.                                     QCustomPlot::iSelectLegend | QCustomPlot::iSelectPlottables | QCustomPlot::iSelectTitle);
  19.     customPlot->setRangeDrag(Qt::Horizontal|Qt::Vertical);
  20.     customPlot->setRangeZoom(Qt::Horizontal|Qt::Vertical);
  21.     customPlot->xAxis->setRange(0, 1);
  22.     customPlot->yAxis->setRange(0, 1);
  23.     customPlot->yAxis->setRangeReversed(true);
  24.     customPlot->setupFullAxesBox();
  25.     customPlot->xAxis->setLabel("x Axis");
  26.     customPlot->yAxis->setLabel("y Axis");
  27.     customPlot->legend->setVisible(true);
  28.     QFont legendFont = font();
  29.     legendFont.setPointSize(10);
  30.     customPlot->legend->setFont(legendFont);
  31.     customPlot->legend->setSelectedFont(legendFont);
  32.     customPlot->legend->setSelectable(QCPLegend::spItems); // legend box shall not be selectable, only legend items
  33.  
  34.  
  35.     // connect slot that ties some axis selections together (especially opposite axes):
  36.     connect(customPlot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
  37.     // connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
  38.     connect(customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
  39.     connect(customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
  40.  
  41.     // make bottom and left axes transfer their ranges to top and right axes:
  42.     connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
  43.     connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
  44.  
  45.     // connect some interaction slots:
  46.     connect(customPlot, SIGNAL(titleDoubleClick(QMouseEvent*)), this, SLOT(titleDoubleClick()));
  47.     connect(customPlot, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
  48.     connect(customPlot, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));
  49.  
  50.     // connect slot that shows a message in the status bar when a graph is clicked:
  51.     connect(customPlot, SIGNAL(plottableClick(QCPAbstractPlottable*,QMouseEvent*)), this, SLOT(graphClicked(QCPAbstractPlottable*)));
  52.  
  53.     // setup policy and connect slot for context menu popup:
  54.     customPlot->setContextMenuPolicy(Qt::CustomContextMenu);
  55.     connect(customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.     // Oppretter databasen med databasedriver QODBC
  63.     db = QSqlDatabase::addDatabase("QODBC");
  64.  
  65.     // Setter maksverdiene for x og y aksene til -1 for å være sikker på at de blir overskrevet
  66.     xMax = -1;
  67.     yMax = -1;
  68.  
  69.     // Setter startverdi for fargevelger variabelen
  70.     colorCounter = 0;
  71. }
  72.  
  73. Qt::GlobalColor Graph::getColor()
  74. {
  75.     // Oppretter en tabell av farger, og legger inn noen farger
  76.     Qt::GlobalColor colorArray[7] = {Qt::red, Qt::green, Qt::cyan, Qt::magenta, Qt::yellow, Qt::gray, Qt::darkRed};
  77.     int temp;
  78.  
  79.     // Om telleren har nådd maks, nullstill teller og return. Hvis ikke, øk teller og return
  80.     if (colorCounter == 6) {
  81.         temp = colorCounter;
  82.         colorCounter = 0;
  83.         return colorArray[temp];
  84.     }
  85.     else {
  86.         temp = colorCounter;
  87.         colorCounter ++;
  88.         return colorArray[temp];
  89.     }
  90.  
  91. }
clone this paste RAW Paste Data