00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef EVENTSPROVIDER_H
00019 #define EVENTSPROVIDER_H
00020
00021
00022 #include <dataprovider.h>
00023 #include <array.h>
00024 #include <types.h>
00025
00026
00027 #include <qptrlist.h>
00028 #include <qobject.h>
00029 #include <qfile.h>
00030
00031
00032 #include <math.h>
00033
00040 class EventDescription : public QString{
00041 public:
00042 inline EventDescription():QString(){};
00043 inline EventDescription(const QString& s):QString(s){};
00044 };
00045
00046 bool operator<(const EventDescription& s1,const EventDescription& s2);
00047
00048
00049 class EventsProvider : public DataProvider {
00050 Q_OBJECT
00051 public:
00052
00054 enum loadReturnMessage {OK=0,OPEN_ERROR=1,INCORRECT_CONTENT=2,COUNT_ERROR=3};
00055
00056
00062 EventsProvider(KURL fileUrl,double currentSamplingRate,int position = 25);
00063 ~EventsProvider();
00064
00071 void requestData(long startTime,long endTime,QObject* initiator,long startTimeInRecordingUnits = 0);
00072
00081 void requestNextEventData(long startTime,long timeFrame,QValueList<int> selectedIds,QObject* initiator);
00082
00083
00092 void requestPreviousEventData(long endTime,long timeFrame,QValueList<int> selectedIds,QObject* initiator);
00093
00097 int loadData();
00098
00102 inline int getNbEvents() const {return nbEvents;};
00103
00106 inline QMap<EventDescription,int> eventDescriptionIdMap() const{return eventIds;};
00107
00110 inline QMap<int,EventDescription> eventIdDescriptionMap() const{return idsDescriptions;};
00111
00115 inline QString getName() const {return name;}
00116
00120 inline int getDescriptionLength() const {return descriptionLength;};
00121
00125 inline void setEventPosition(int position){eventPosition = static_cast<float>(position) / 100.0;};
00126
00132 void modifiedEvent(int selectedEventId,double time,double newTime);
00133
00138 void removeEvent(int selectedEventId,double time);
00139
00144 void addEvent(QString eventDescriptionToAdd,double time);
00145
00147 void undo();
00148
00150 void redo();
00151
00153 void clearUndoRedoData();
00154
00159 int save(QFile* eventFile);
00160
00164 bool isModified() const {return modified;};
00165
00167 void initializeEmptyProvider();
00168
00172 inline void updateSamplingRate(double rate){
00173 currentSamplingRate = static_cast<double>(rate / 1000.0);
00174
00175
00176 previousStartTime = 0;
00177 previousStartIndex = 1;
00178 previousEndIndex = nbEvents;
00179 previousEndTime = static_cast<long>(floor(0.5 + timeStamps(1,nbEvents)));
00180 fileMaxTime = previousEndTime;
00181 };
00182
00188 void renameEvent(int selectedEventId,QString newEventDescription,double time);
00189
00190 signals:
00197 void dataReady(Array<dataType>& times,Array<int>& ids,QObject* initiator,QString providerName);
00198
00206 void nextEventDataReady(Array<dataType>& times,Array<int>& ids,QObject* initiator,QString providerName,long startingTime);
00207
00215 void previousEventDataReady(Array<dataType>& times,Array<int>& ids,QObject* initiator,QString providerName,long startingTime);
00216
00223 void newEventDescriptionCreated(QString providerName,QMap<int,int> oldNewEventIds,QMap<int,int> newOldEventIds,QString eventDescriptionAdded);
00224
00232 void eventDescriptionRemoved(QString providerName,QMap<int,int> oldNewEventIds,QMap<int,int> newOldEventIds,int eventIdToRemove,QString eventDescriptionToRemove);
00233
00234 private:
00235
00237 QString name;
00238
00240 double currentSamplingRate;
00241
00243 Array<double> timeStamps;
00244
00246 pArray<EventDescription> events;
00247
00249 Array<double> timeStampsUndo;
00250
00252 pArray<EventDescription> eventsUndo;
00253
00255 Array<double> timeStampsRedo;
00256
00258 pArray<EventDescription> eventsRedo;
00259
00261 long previousStartTime;
00262
00264 long previousEndTime;
00265
00267 long previousStartIndex;
00268
00270 long previousEndIndex;
00271
00273 long nbEvents;
00274
00276 QMap<EventDescription,int> eventIds;
00277
00279 QMap<int,EventDescription> idsDescriptions;
00280
00282 int descriptionLength;
00283
00285 long fileMaxTime;
00286
00288 float eventPosition;
00289
00291 bool modified;
00292
00294 QMap<EventDescription,int> eventDescriptionCounter;
00295
00297 QMap<EventDescription,int> eventDescriptionCounterUndo;
00298
00300 QMap<EventDescription,int> eventDescriptionCounterRedo;
00301
00302
00303
00309 void retrieveData(long startTime,long endTime,QObject* initiator);
00310
00315 long findIndex(double eventTime,int eventId = -1);
00316
00320 void addEventDescription(QString eventDescriptionToAdd);
00321
00325 void removeEventDescription(QString eventDescriptionToRemove);
00326 };
00327
00328
00329 #endif