00001 /*************************************************************************** 00002 omdataseries.cpp - description 00003 ------------------- 00004 begin : April 2007 00005 copyright : (C) 2007 by Tim Sutton 00006 email : tim@linfiniti.com 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 00018 #include "omgdataseries.h" 00019 #include "omgui.h" 00020 #include <algorithm> //needed for sort 00021 OmgDataSeries::OmgDataSeries() 00022 { 00023 mLineColor = Omgui::randomColour(); 00024 mFillColor = Omgui::randomColour(); 00025 } 00026 OmgDataSeries::~OmgDataSeries() 00027 { 00028 } 00029 00030 int OmgDataSeries::size() const 00031 { 00032 return mYList.size(); 00033 } 00034 double OmgDataSeries::xAt(int thePosition) 00035 { 00036 if (mXList.size() <= thePosition) 00037 { 00038 qDebug("Error requesting non existing position in OmgDataSeries::xAt(), returning -9999!"); 00039 QString myString = QString("x list size: %1 position requestd %2 ( %3 line %4 )") 00040 .arg(mXList.size()).arg(thePosition).arg(__FILE__).arg(__LINE__); 00041 qDebug(myString); 00042 return -9999; 00043 } 00044 return mXList.at(thePosition); 00045 } 00046 double OmgDataSeries::yAt(int thePosition) 00047 { 00048 if (mYList.size() <= thePosition) 00049 { 00050 qDebug("Error requesting non existing position in OmgDataSeries::yAt(), returning -9999!"); 00051 QString myString = QString("y list size: %1 position requestd %2 ( %3 line %4 )") 00052 .arg(mYList.size()).arg(thePosition).arg(__FILE__).arg(__LINE__); 00053 qDebug(myString); 00054 return -9999; 00055 } 00056 return mYList.at(thePosition); 00057 } 00058 double OmgDataSeries::xMin() const 00059 { 00060 bool myFirstFlag=true; 00061 double myMin=0; 00062 QListIterator< double > myIterator( mXList ); 00063 while (myIterator.hasNext()) 00064 { 00065 double myVal = myIterator.next(); 00066 if ( myVal < myMin || myFirstFlag ) 00067 { 00068 myMin=myVal; 00069 } 00070 myFirstFlag=false; 00071 } 00072 return myMin; 00073 } 00074 00075 double OmgDataSeries::yMin() const 00076 { 00077 bool myFirstFlag=true; 00078 double myMin=0; 00079 QListIterator< double > myIterator( mYList ); 00080 while (myIterator.hasNext()) 00081 { 00082 double myVal = myIterator.next(); 00083 if ( myVal < myMin || myFirstFlag ) 00084 { 00085 myMin=myVal; 00086 } 00087 myFirstFlag=false; 00088 } 00089 return myMin; 00090 } 00091 00092 double OmgDataSeries::xMax() const 00093 { 00094 bool myFirstFlag=true; 00095 double myMax=0; 00096 QListIterator< double > myIterator( mXList ); 00097 while (myIterator.hasNext()) 00098 { 00099 double myVal = myIterator.next(); 00100 if ( myVal > myMax || myFirstFlag ) 00101 { 00102 myMax=myVal; 00103 } 00104 myFirstFlag=false; 00105 } 00106 return myMax; 00107 } 00108 00109 double OmgDataSeries::yMax() const 00110 { 00111 bool myFirstFlag=true; 00112 double myMax=0; 00113 QListIterator< double > myIterator( mYList ); 00114 while (myIterator.hasNext()) 00115 { 00116 double myVal = myIterator.next(); 00117 if ( myVal > myMax || myFirstFlag ) 00118 { 00119 myMax=myVal; 00120 } 00121 myFirstFlag=false; 00122 } 00123 return myMax; 00124 } 00125 00126 void OmgDataSeries::sortX(Qt::SortOrder theOrder) 00127 { 00128 if (theOrder==Qt::DescendingOrder) 00129 { 00130 qSort(mXList.begin(),mXList.end(),qGreater<double>()); 00131 } 00132 else //ascending sort 00133 { 00134 qSort(mXList.begin(),mXList.end()); 00135 } 00136 } 00137 00138 void OmgDataSeries::sortY(Qt::SortOrder theOrder) 00139 { 00140 if (theOrder==Qt::DescendingOrder) 00141 { 00142 qSort(mYList.begin(),mYList.end(),qGreater<double>()); 00143 } 00144 else //ascending sort 00145 { 00146 qSort(mYList.begin(),mYList.end()); 00147 } 00148 } 00149 00150 QList<double> OmgDataSeries::xValuesList() const 00151 { 00152 return mXList; 00153 } 00154 00155 void OmgDataSeries::setXValuesList(QList<double> theXValues) 00156 { 00157 mXList=theXValues; 00158 //autofill the Y axis 00159 QList<double> myYList; 00160 for (int myCount=0; myCount < mXList.size(); ++myCount) 00161 { 00162 myYList << myCount; 00163 } 00164 mYList = myYList; 00165 } 00166 00167 QList<double> OmgDataSeries::yValuesList() const 00168 { 00169 return mYList; 00170 } 00171 00172 void OmgDataSeries::setYValuesList(QList<double> theYValues) 00173 { 00174 mYList=theYValues; 00175 //autofill the X axis 00176 QList<double> myXList; 00177 for (int myCount=0; myCount < mYList.size(); ++myCount) 00178 { 00179 myXList << myCount; 00180 } 00181 mXList = myXList; 00182 } 00183 00184 void OmgDataSeries::setXYValueLists(QList<double> theXValues,QList<double> theYValues) 00185 { 00186 mXList=theXValues; 00187 mYList=theYValues; 00188 } 00189 00190 QString OmgDataSeries::xLabel() 00191 { 00192 return mXLabel; 00193 } 00194 00195 void OmgDataSeries::setXLabel(QString theLabel) 00196 { 00197 mXLabel=theLabel; 00198 } 00199 00200 QString OmgDataSeries::yLabel() 00201 { 00202 return mYLabel; 00203 } 00204 00205 void OmgDataSeries::setYLabel(QString theLabel) 00206 { 00207 mYLabel=theLabel; 00208 } 00209 00210 QString OmgDataSeries::label() 00211 { 00212 return mLabel; 00213 } 00214 00215 void OmgDataSeries::setLabel(QString theLabel) 00216 { 00217 mLabel=theLabel; 00218 } 00219 00220 QColor OmgDataSeries::lineColor() 00221 { 00222 return mLineColor; 00223 } 00224 00225 void OmgDataSeries::setLineColor(QColor theColor) 00226 { 00227 mLineColor=theColor; 00228 } 00229 00230 QColor OmgDataSeries::fillColor() 00231 { 00232 return mFillColor; 00233 } 00234 00235 void OmgDataSeries::setFillColor(QColor theColor) 00236 { 00237 mFillColor=theColor; 00238 } 00239