diff --git a/src/neuroscope.cpp b/src/neuroscope.cpp index 1d2d393..327723b 100644 --- a/src/neuroscope.cpp +++ b/src/neuroscope.cpp @@ -568,6 +568,12 @@ void NeuroscopeApp::initActions() connect(doc, SIGNAL(loadFirstDisplay(QList*,bool,bool,bool,bool,bool,bool,bool,QList,QList,QList,QMap&,long,long,QString,bool,int,bool)),this, SLOT(slotSetUp(QList*,bool,bool,bool,bool,bool,bool,bool,QList,QList,QList,QMap&,long,long,QString,bool,int,bool))); + connect(doc, SIGNAL(clusterFileLoaded(const QString&)), + this, SLOT(slotClusterFileLoaded(const QString&))); + + connect(doc, SIGNAL(eventFileLoaded(const QString&)), + this, SLOT(slotEventFileLoaded(const QString&))); + connect(displayChannelPalette, SIGNAL(singleChangeColor(int)),this, SLOT(slotSingleChannelColorUpdate(int))); connect(spikeChannelPalette, SIGNAL(singleChangeColor(int)),this, SLOT(slotSingleChannelColorUpdate(int))); connect(displayChannelPalette, SIGNAL(singleChangeColor(int)),spikeChannelPalette, SLOT(updateColor(int))); @@ -1091,16 +1097,6 @@ void NeuroscopeApp::openNetworkStream(CerebusTracesProvider::SamplingGroup group return; } - // Set up cluster palette - int channelCount = this->doc->getChannelNb(); - createClusterPalette("1"); - for (int i = 2; i <= channelCount; i++) - addClusterFile(QString::number(i)); - - // Set up event palette - QString eventFileId = this->doc->lastLoadedProviderName(); - createEventPalette(eventFileId); - // Update the spike and event browsing status updateBrowsingStatus(); @@ -1163,7 +1159,7 @@ void NeuroscopeApp::updateBrowsingStatus(){ } } - if (!palette) + if (!palette) return; NeuroscopeView* view = activeView(); QStringList::iterator iterator; @@ -1451,11 +1447,6 @@ void NeuroscopeApp::slotCreateEventFile(){ QMessageBox::critical (this, tr("Error!"),tr("The selected file name is already opened.")); } else{ - const QString eventFileId = doc->lastLoadedProviderName(); - if(eventFileList.isEmpty()) - createEventPalette(eventFileId); - else - addEventFile(eventFileId); eventsModified = true; QApplication::restoreOverrideCursor(); } @@ -2334,7 +2325,7 @@ void NeuroscopeApp::slotTabChange(int index){ /// Added by M.Zugaro to enable automatic forward paging if ( isStill() ) slotStateChanged("pageOffState"); else slotStateChanged("pageOnState"); - + QWidget *channelPalette = paletteTabsParent->currentWidget(); if(qobject_cast(channelPalette)){ @@ -2864,7 +2855,6 @@ void NeuroscopeApp::loadClusterFiles(const QStringList &urls){ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); //Loop on the files - int counter = 0; QStringList::const_iterator iterator; for(iterator = urls.constBegin();iterator != urls.constEnd();++iterator){ //Create the provider @@ -2906,17 +2896,19 @@ void NeuroscopeApp::loadClusterFiles(const QStringList &urls){ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); continue; } - - //Create the cluster palette if need it - counter++; - QString clusterFileId = doc->lastLoadedProviderName(); - if(clusterFileList.isEmpty() && counter == 1) - createClusterPalette(clusterFileId); - else addClusterFile(clusterFileId); } QApplication::restoreOverrideCursor(); } +/** Updates view, because a new cluster file was loaded. */ +void NeuroscopeApp::slotClusterFileLoaded(const QString& fileID) { + // Create the cluster palette if need it + if(clusterFileList.isEmpty()) + createClusterPalette(fileID); + else + addClusterFile(fileID); +} + void NeuroscopeApp::createClusterPalette(const QString& clusterFileId) { ItemPalette* clusterPalette = new ItemPalette(ItemPalette::CLUSTER,backgroundColor,this,"clusterPanel"); @@ -3083,7 +3075,6 @@ void NeuroscopeApp::loadEventFiles(const QStringList& urls){ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); //Loop on the files - int counter = 0; QStringList::const_iterator iterator; for(iterator = urls.constBegin();iterator != urls.constEnd();++iterator){ //Create the provider @@ -3118,18 +3109,17 @@ void NeuroscopeApp::loadEventFiles(const QStringList& urls){ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); continue; } - - //Create the event palette if need it - counter++; - QString eventFileId = doc->lastLoadedProviderName(); - if(eventFileList.isEmpty() && counter == 1) - createEventPalette(eventFileId); - else - addEventFile(eventFileId); } QApplication::restoreOverrideCursor(); } +void NeuroscopeApp::slotEventFileLoaded(const QString& fileId) { + //Create the event palette if need it; + if(eventFileList.isEmpty()) + createEventPalette(fileId); + else + addEventFile(fileId); +} void NeuroscopeApp::createEventPalette(const QString& eventFileId){ diff --git a/src/neuroscope.h b/src/neuroscope.h index 0aac273..eaec255 100644 --- a/src/neuroscope.h +++ b/src/neuroscope.h @@ -19,7 +19,7 @@ #define NEUROSCOPE_H - + #include @@ -199,7 +199,7 @@ class NeuroscopeApp : public QMainWindow * @return true if at least one cluster file is loaded, false otherwise. */ inline bool isClusterFilesLoaded()const{return !clusterFileList.isEmpty();} - + /**Tells if there is a position file loaded. * @return true a position file is loaded, false otherwise. */ @@ -322,15 +322,15 @@ public Q_SLOTS: */ void initDisplay(QList* channelsToDisplay,bool autocenterChannels,QList offsets,QList channelGains, QList selectedChannels,QMap& skipStatus,int rasterHeight=-1,long duration = 1000,long startTime = 0,QString tabLabel = QString()); - + /** * queryClose is called by closeEvent */ bool queryClose(); - + void customEvent (QEvent* event); void closeEvent(QCloseEvent *event); - + private Q_SLOTS: void slotAbout(); @@ -346,15 +346,21 @@ private Q_SLOTS: /**Loads one or multiple cluster files.*/ void slotLoadClusterFiles(); + /** Updates view, because a new cluster file was loaded. */ + void slotClusterFileLoaded(const QString& fileID); + /**Closes the cluster file corresponding to the currently selected cluster group.*/ void slotCloseClusterFile(); - + /**Loads one or multiple event files.*/ void slotLoadEventFiles(); /**Creates an empty event file.*/ void slotCreateEventFile(); - + + /** Updates view, because a new event file was loaded or created. */ + void slotEventFileLoaded(const QString& fileID); + /**Closes the event file corresponding to the currently selected event group.*/ void slotCloseEventFile(); @@ -363,7 +369,7 @@ private Q_SLOTS: /**Closes the position file.*/ void slotClosePositionFile(); - + /**Opens a file from the recent files menu. */ void slotFileOpenRecent(const QString& url); @@ -371,7 +377,7 @@ private Q_SLOTS: * (number of channels, sampling rate of the dat file and eeg file). */ void slotFileProperties(); - + /**If need it, warns the user that the spike groups have been modified, then closes the actual file and displayss.*/ void slotFileClose(); @@ -399,7 +405,7 @@ private Q_SLOTS: * have the same amplification. */ void slotShowCalibration(); - + /**Changes the statusbar contents for the standard label permanently, used to indicate current actions. * @param text the text that is displayed in the statusbar. */ @@ -409,7 +415,7 @@ private Q_SLOTS: /*Slots for the tools menu.*/ /**Chooses the tool to select channels, enabling the user to select traces in order to move them.*/ void slotSelect(); - + /**Chooses the zoom tool, enabling the user to zoom.*/ void slotZoom(); @@ -420,7 +426,7 @@ private Q_SLOTS: /**Chooses the selection time tool, enabling the user to select a time frame (subset of the currently shown) * for which the traces are going to be displayed.*/ void slotSelectTime(); - + /**Chooses the tool to select an event, enabling the user to select an event in order to move or delete it.*/ void slotSelectEvent(); @@ -509,13 +515,13 @@ private Q_SLOTS: /**Selects all the clusters of the current palette except the clusters of artefact and noise * (clusters 0 and 1 respectively).*/ void slotSelectAllWO01(); - + /**Sets the mode of presentation in the current display, single or multiple columns.*/ void slotDisplayMode(); /**Displays or hides vertical lines to show the clusters.*/ void slotClustersVerticalLines(); - + /**Displays or hides a raster to show the clusters.*/ void slotClustersRaster(); @@ -527,7 +533,7 @@ private Q_SLOTS: /**Triggers the moves of the selected channels to the discard spike group.*/ void slotDiscardSpikeChannels(); - + /**The selected channels have been moved to the trash group. * @param discarded ids of the channels to move to the trash group. */ @@ -676,7 +682,7 @@ private Q_SLOTS: * @param clustersToSkip new list of clusters to skip while browsing */ void slotUpdateClustersToSkip(const QString &groupName, const QList& clustersToSkip); - + /**Marks the selected channels has keeped.*/ void slotKeepChannels(); @@ -742,7 +748,7 @@ private Q_SLOTS: QAction* addEventToolBarAction; QAction* positionViewToggle; QAction* showEventsInPositionView; - + QAction* mProperties; QAction* mLoadClusterFiles; QAction* mLoadEventFiles; @@ -824,7 +830,7 @@ private Q_SLOTS: * Inititalized in initItemPanel(). */ ChannelPalette* displayChannelPalette; - + /**spikeChannelPalette is the Widget containing the channel list to create the spike groups. * Inititalized in initItemPanel(). */ @@ -868,10 +874,10 @@ private Q_SLOTS: /**Flag to keep track of group modifications. */ bool groupsModified; - + /**Flag to keep track of color modifications. */ bool colorModified; - + /**Flag to keep track of event modifications. */ bool eventsModified; @@ -898,7 +904,7 @@ private Q_SLOTS: /**List storing the identifiers of the opened cluster files.*/ QStringList clusterFileList; - + /**List storing the identifiers of the opened event files.*/ QStringList eventFileList; diff --git a/src/neuroscopedoc.cpp b/src/neuroscopedoc.cpp index bf86f3e..3cf2a67 100644 --- a/src/neuroscopedoc.cpp +++ b/src/neuroscopedoc.cpp @@ -687,7 +687,6 @@ bool NeuroscopeDoc::openStream(CerebusTracesProvider::SamplingGroup group) { QList clusterList = clustersProvider->clusterIdList(); // Add cluster provider to internal structure - lastLoadedProvider = name; providers.insert(name, clustersProvider); providerUrls.insert(name, QString("cerebus.") + name + QString(".nev")); @@ -730,6 +729,7 @@ bool NeuroscopeDoc::openStream(CerebusTracesProvider::SamplingGroup group) { ); } + emit clusterFileLoaded(name); } // Integrate digital and serial event data @@ -767,6 +767,7 @@ bool NeuroscopeDoc::openStream(CerebusTracesProvider::SamplingGroup group) { eventsList, eventsToSkip); } + emit eventFileLoaded(name); return true; } @@ -1690,7 +1691,7 @@ void NeuroscopeDoc::loadSession(NeuroscopeXmlReader reader){ selectedClusters.insert(fileUrl,ids); skippedClusters.insert(fileUrl,skippedIds); } - OpenSaveCreateReturnMessage status = loadClusterFile(fileUrl,itemColors,lastModified,fistClusterFile); + OpenSaveCreateReturnMessage status = loadClusterFileForSession(fileUrl,itemColors,lastModified,fistClusterFile); if(status == OK){ loadedClusterFiles.append(lastLoadedProvider); fistClusterFile = false; @@ -1710,7 +1711,7 @@ void NeuroscopeDoc::loadSession(NeuroscopeXmlReader reader){ selectedEvents.insert(fileUrl,ids); skippedEvents.insert(fileUrl,skippedIds); } - OpenSaveCreateReturnMessage status = loadEventFile(fileUrl,itemColors,lastModified,fistEventFile); + OpenSaveCreateReturnMessage status = loadEventFileForSession(fileUrl,itemColors,lastModified,fistEventFile); if(status == OK){ loadedEventFiles.append(lastLoadedProvider); fistEventFile = false; @@ -2175,7 +2176,6 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadNevClusterFile(con QList clusterList = clustersProvider->clusterIdList(); // Add cluster provider to internal structure - lastLoadedProvider = name; providers.insert(name, clustersProvider); providerUrls.insert(name, clusterUrl); @@ -2214,8 +2214,10 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadNevClusterFile(con clustersToSkip ); } - + emit clusterFileLoaded(name); } + + return OK; } NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadCluClusterFile(const QString &clusterUrl,NeuroscopeView* activeView){ @@ -2252,7 +2254,6 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadCluClusterFile(con return INCORRECT_CONTENT; } - lastLoadedProvider = name; providers.insert(name,clustersProvider); providerUrls.insert(name,clusterUrl); @@ -2285,10 +2286,12 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadCluClusterFile(con else view->setClusterProvider(clustersProvider,name,clusterColors,true,clustersToShow,&displayGroupsClusterFile,&channelsSpikeGroups,peakSampleIndex - 1,nbSamples - peakSampleIndex,clustersToSkip); } + emit clusterFileLoaded(name); + return OK; } -NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadClusterFile(const QString &clusterUrl, QMap& itemColors, const QDateTime &lastModified, bool firstFile){ +NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadClusterFileForSession(const QString &clusterUrl, QMap& itemColors, const QDateTime &lastModified, bool firstFile){ //Check that the selected file is a cluster file (should always be the case as the file has //already be loaded once). QString fileName = clusterUrl; @@ -2393,6 +2396,7 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadClusterFile(const QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); } + // TODO: Use signals for this. if(firstFile) { static_cast(parent)->createClusterPalette(name); } else { @@ -2478,7 +2482,6 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadEventFile(const QS return INCORRECT_CONTENT; } - lastLoadedProvider = name; lastEventProviderGridX = eventsProvider->getDescriptionLength(); providers.insert(name,eventsProvider); providerUrls.insert(name,eventUrl); @@ -2511,10 +2514,12 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadEventFile(const QS else view->setEventProvider(eventsProvider,name,eventColors,true,eventsToShow,eventsToSkip); } + emit eventFileLoaded(name); + return OK; } -NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadEventFile(const QString &eventUrl,QMap& itemColors, const QDateTime& lastModified,bool firstFile){ +NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadEventFileForSession(const QString &eventUrl,QMap& itemColors, const QDateTime& lastModified,bool firstFile){ //Check that the selected file is a event file (should always be the case as the file has //already be loaded once). QString fileName = eventUrl; @@ -2611,6 +2616,7 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::loadEventFile(const QS connect(eventsProvider, SIGNAL(newEventDescriptionCreated(QString,QMap,QMap,QString)),this, SLOT(slotNewEventDescriptionCreated(QString,QMap,QMap,QString))); connect(eventsProvider, SIGNAL(eventDescriptionRemoved(QString,QMap,QMap,int,QString)),this, SLOT(slotEventDescriptionRemoved(QString,QMap,QMap,int,QString))); + // TODO: Use signals for this. if(firstFile) dynamic_cast(parent)->createEventPalette(name); else dynamic_cast(parent)->addEventFile(name); @@ -2945,7 +2951,6 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::createEventFile(const return ALREADY_OPENED; } - lastLoadedProvider = name; eventsProvider->initializeEmptyProvider(); lastEventProviderGridX = eventsProvider->getDescriptionLength(); providers.insert(name,eventsProvider); @@ -2970,6 +2975,8 @@ NeuroscopeDoc::OpenSaveCreateReturnMessage NeuroscopeDoc::createEventFile(const view->setEventProvider(eventsProvider,name,eventColors,true,eventsToShow,eventsToSkip); } + emit eventFileLoaded(name); + return OK; } diff --git a/src/neuroscopedoc.h b/src/neuroscopedoc.h index 4a4e8f4..5d69642 100644 --- a/src/neuroscopedoc.h +++ b/src/neuroscopedoc.h @@ -466,10 +466,6 @@ class NeuroscopeDoc : public QObject */ void showCalibration(bool show,NeuroscopeView* activeView); - /**Returns the name used to identified the last loaded provider. - */ - QString lastLoadedProviderName() const {return lastLoadedProvider;} - /**Returns the item color list for the given provider. * @param fileName name of the file containing the data of the provider. */ @@ -492,7 +488,7 @@ class NeuroscopeDoc : public QObject * @param firstFile true if the file to load if the first one, false otherwise. * @return an OpenSaveCreateReturnMessage enum giving the load status. */ - OpenSaveCreateReturnMessage loadClusterFile(const QString &clusterUrl,QMap& itemColors,const QDateTime &lastModified,bool firstFile); + OpenSaveCreateReturnMessage loadClusterFileForSession(const QString &clusterUrl,QMap& itemColors,const QDateTime &lastModified,bool firstFile); /**Loads the position file and creates the position view in the current display. @@ -529,7 +525,7 @@ class NeuroscopeDoc : public QObject * @param firstFile true if the file to load if the first one, false otherwise. * @return an OpenSaveCreateReturnMessage enum giving the load status. */ - OpenSaveCreateReturnMessage loadEventFile(const QString &eventUrl,QMap& itemColors,const QDateTime &lastModified,bool firstFile); + OpenSaveCreateReturnMessage loadEventFileForSession(const QString &eventUrl,QMap& itemColors,const QDateTime &lastModified,bool firstFile); /**Removes the event provider corresponding to the identifier @p providerName * from the list of providers. @@ -831,6 +827,16 @@ public Q_SLOTS: QList selectedChannels,QMap& skipStatus,long startTime,long duration,QString tabLabel,bool positionView,int rasterHeight, bool showEventsInPositionView); + /** Emitted when cluster file was sucessfully loaded. + * @param fileId id of the file loaded. + */ + void clusterFileLoaded(const QString& fileId); + + /** Emitted when event file was sucessfully loaded. + * @param fileId id of the file loaded. + */ + void eventFileLoaded(const QString& fileId); + private: /** The list of the views currently connected to the document */ QList* viewList; @@ -843,10 +849,10 @@ public Q_SLOTS: /**The url of the session file.*/ QString sessionUrl; - + /**The url of the parameter file.*/ QString parameterUrl; - + /**Reference on the channelPalette used to specify the traces display.*/ ChannelPalette& displayChannelPalette; @@ -924,7 +930,7 @@ public Q_SLOTS: /*Map given the of channels default offsets.*/ QMap channelDefaultOffsets; - + /**Provider of the channels data.*/ TracesProvider* tracesProvider; @@ -942,7 +948,7 @@ public Q_SLOTS: /**Video acquisition sampling rate.*/ double videoSamplingRate; - + /**Number of samples in a spike waveform.*/ int nbSamples; @@ -957,13 +963,13 @@ public Q_SLOTS: /**Length for a spike*/ float waveformLength; - + /**Length corresponding to the index of peak of the spike.*/ float indexLength; - + /**Default length for a spike*/ float waveformLengthDefault; - + /**Default length corresponding to the index of peak of the spike.*/ float indexLengthDefault; @@ -1029,7 +1035,7 @@ public Q_SLOTS: int videoHeightDefault; /**Default background image for the position view.*/ QString backgroundImageDefault; - + /**Default background image for the trace view.*/ QString traceBackgroundImageDefault; @@ -1045,35 +1051,35 @@ public Q_SLOTS: int videoHeight; /**Background image for the position view.*/ QString backgroundImage; - + /**Background image for the trace view.*/ QString traceBackgroundImage; - + /**Angle of rotation of the video records.*/ int rotation; /**Flip orientation of the video records. * 0 stands for none, 1 for vertical flip and 2 for horizontal flip. */ int flip; - + /**Transformed background image for the position view (rotated and or flip if need it).*/ QImage transformedBackground; - + /**True if the all the positions contain in the position file have to be drawn on the background image, false otherwise.*/ bool drawPositionsOnBackground; - + /**Default value for drawPositionsOnBackground.*/ bool drawPositionsOnBackgroundDefault; - + /**True if a position file has been opened at least one during the session (it can have been closed and not reopened), false otherwise.*/ bool positionFileOpenOnce; - + /**Extension of the opened position file.*/ QString positionFileExtension; - + /**Map between the channel and skip status.*/ QMap skipStatus; - + /**Upsampling rate used to create the spike file.*/ double upsamplingRate;