Skip to content

Commit

Permalink
Code Refactor and Deleting Redundant Headers
Browse files Browse the repository at this point in the history
1. Added setEventTypeColors() function in file_signal_reader.cpp, which
is inherited by both xdf_reader.cpp and biosig_reader.cpp
2. Deleted redundant headers
  • Loading branch information
Yida-Lin committed Jun 11, 2017
1 parent 8891684 commit cf787fd
Show file tree
Hide file tree
Showing 31 changed files with 100 additions and 268 deletions.
10 changes: 2 additions & 8 deletions src/application_context_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
#define APPLICATION_CONTEXT_IMPL_H

#include "base/application_states.h"
#include "gui/color_manager.h"
#include "gui/main_window_model.h"
#include "gui/application_context.h"
#include "file_context.h"
#include "file_handling_impl/xdf_reader.h"
#include "file_handling_impl/biosig_reader.h"

#include <QObject>
#include <QSharedPointer>
Expand All @@ -28,8 +23,6 @@ namespace sigviewer
class ApplicationContextImpl : public QObject, public ApplicationContext
{
Q_OBJECT
friend class XDFReader;
friend class BioSigReader;
public:
//-------------------------------------------------------------------------
static QSharedPointer<ApplicationContextImpl> getInstance (bool cleanup = false);
Expand Down Expand Up @@ -70,6 +63,8 @@ class ApplicationContextImpl : public QObject, public ApplicationContext
//-------------------------------------------------------------------------
virtual QSharedPointer<ColorManager> getEventColorManager ();

QSharedPointer<ColorManager> color_manager_;

signals:
void stateChanged (ApplicationState state);
void currentFileStateChanged (FileState state);
Expand All @@ -79,7 +74,6 @@ class ApplicationContextImpl : public QObject, public ApplicationContext
private:
void setState (ApplicationState state);
std::set<ApplicationMode> activated_modes_;
QSharedPointer<ColorManager> color_manager_;
QSharedPointer<MainWindowModel> main_window_model_;
QSharedPointer<FileContext> current_file_context_;
QSharedPointer<TabContext> current_tab_context_;
Expand Down
4 changes: 0 additions & 4 deletions src/base/data_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

#include "sigviewer_user_types.h"

#include <list>
#include <vector>
#include <string>

#include <QSharedPointer>
#include <QMap>

Expand Down
3 changes: 0 additions & 3 deletions src/commands/open_file_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
#include "open_file_command.h"

#include "file_handling/file_signal_reader_factory.h"
#include "file_handling/channel_manager.h"
#include "file_handling_impl/channel_manager_impl.h"
#include "file_handling_impl/event_manager_impl.h"
#include "file_context.h"

#include <QDir>
#include <QSettings>

namespace sigviewer
{
Expand Down
1 change: 0 additions & 1 deletion src/commands/open_file_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "gui/application_context.h"

#include <QString>

namespace sigviewer
{
Expand Down
1 change: 0 additions & 1 deletion src/file_handling/basic_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "base/signal_channel.h"

#include <QString>
#include <QList>
#include <QDateTime>
#include <QMap>
Expand Down
3 changes: 0 additions & 3 deletions src/file_handling/channel_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
#ifndef CHANNEL_MANAGER_INTERFACE_H
#define CHANNEL_MANAGER_INTERFACE_H

#include "base/sigviewer_user_types.h"
#include "base/data_block.h"

#include <QSharedPointer>
#include <set>
#include <map>

namespace sigviewer
{
Expand Down
3 changes: 2 additions & 1 deletion src/file_handling/file_handling.pri
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ SOURCES += \
$$PWD/basic_header.cpp \
$$PWD/channel_manager.cpp \
$$PWD/file_signal_reader_factory.cpp \
$$PWD/file_signal_writer_factory.cpp
$$PWD/file_signal_writer_factory.cpp \
$$PWD/file_signal_reader.cpp
91 changes: 91 additions & 0 deletions src/file_handling/file_signal_reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) 2016 The SigViewer Development Team
// Licensed under the GNU General Public License (GPL)
// https://www.gnu.org/licenses/gpl


#include "file_signal_reader.h"
#include <QSettings>


namespace sigviewer {

int FileSignalReader::setEventTypeColors()
{
// Display each event type in a distinct color
QSharedPointer<ColorManager> colorPicker = ApplicationContextImpl::getInstance()->color_manager_;

//set event colors
srand (time(NULL)); /* initialize random seed: */

QVector<QColor> eventColorList = {"#0055ff", "#00aa00", "#aa00ff", "#ff0000", "#00557f",
"#5555ff", "#ff55ff", "#00aaff", "#00aa7f", "#ff5500"};

int colorChoice = 5; //Set the first event color to be pink

QSettings settings;
settings.beginGroup("ColorManager");
int size = settings.beginReadArray("event");

for (int type = 0; type < 254; type++)
{
QColor color;
if (type < size)
{
settings.setArrayIndex(type);
color = settings.value("color").toString();
color.setAlpha(settings.value("alpha").toInt());
}

/* if the user has specified color setting for the current event type previously
* in QSettings, we want to use it.
* If the color setting is #0000ff (default), we assume the user
* hasn't specified color for the current event type yet. Below is our algorithm
* to pick some good colors for event types. */

if (color.name().compare("#0000ff", Qt::CaseInsensitive) == 0)
{
// generate random number first:
int red = rand() % 41 + (-20);
int green = rand() % 41 + (-20);
int blue = rand() % 41 + (-20);

colorChoice++;
if (colorChoice == 10) //we only have 10 basic colors
colorChoice = 0;

color = eventColorList[colorChoice];

red += color.red();
green += color.green();
blue += color.blue();

if (red < 0)
red = 0;
if (red > 255)
red = 255;
if (green < 0)
green = 0;
if (green > 255)
green = 255;
if (blue < 0)
blue = 0;
if (blue > 255)
blue = 255;


color.setRgb(red, green, blue);
color.setAlpha(120);
}
colorPicker->setEventColor(type, color); //QColor(0, 85, 255, 80)
eventColorList[colorChoice] = color;
}

settings.endArray();
settings.endGroup();

colorPicker->saveSettings();

return 0;
}

}
3 changes: 3 additions & 0 deletions src/file_handling/file_signal_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "basic_header.h"
#include "base/signal_event.h"
#include "base/data_block.h"
#include "application_context_impl.h"

#include <QVector>
#include <QPointer>
Expand Down Expand Up @@ -42,6 +43,8 @@ class FileSignalReader

virtual QSharedPointer<BasicHeader const> getBasicHeader () const = 0;

int setEventTypeColors(); /*!< Set a distinct color for each event type. */

protected:
FileSignalReader () {}

Expand Down
92 changes: 2 additions & 90 deletions src/file_handling_impl/biosig_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@
#include "file_handler_factory_registrator.h"
#include "gui/progress_bar.h"
#include "base/fixed_data_block.h"
#include "application_context_impl.h"

#include "biosig.h"

#include <QTextStream>
#include <QTranslator>
#include <QMutexLocker>
#include <QDebug>
#include <QTime>
#include <QMessageBox>
#include <QSettings>

#include <cmath>
#include <algorithm>



using namespace std;

Expand Down Expand Up @@ -214,86 +206,6 @@ int BioSigReader::setChannelColors()
return 0;
}

//-----------------------------------------------------------------------------
int BioSigReader::setEventTypeColors()
{
// Display each event type in a distinct color
QSharedPointer<ColorManager> colorPicker = ApplicationContextImpl::getInstance()->color_manager_;

//set event colors
srand (time(NULL)); /* initialize random seed: */

QVector<QColor> eventColorList = {"#0055ff", "#00aa00", "#aa00ff", "#ff0000", "#00557f",
"#5555ff", "#ff55ff", "#00aaff", "#00aa7f", "#ff5500"};

int colorChoice = 5; //Set the first event color to be pink

QSettings settings;
settings.beginGroup("ColorManager");
int size = settings.beginReadArray("event");

for (int type = 0; type < 254; type++)
{
QColor color;
if (type < size)
{
settings.setArrayIndex(type);
color = settings.value("color").toString();
color.setAlpha(settings.value("alpha").toInt());
}

/* if the user has specified color setting for the current event type previously
* in QSettings, we want to use it.
* If the color setting is #0000ff (default), we assume the user
* hasn't specified color for the current event type yet. Below is our algorithm
* to pick some good colors for event types. */

if (color.name().compare("#0000ff", Qt::CaseInsensitive) == 0)
{
// generate random number first:
int red = rand() % 41 + (-20);
int green = rand() % 41 + (-20);
int blue = rand() % 41 + (-20);

colorChoice++;
if (colorChoice == 10) //we only have 10 basic colors
colorChoice = 0;

color = eventColorList[colorChoice];

red += color.red();
green += color.green();
blue += color.blue();

if (red < 0)
red = 0;
if (red > 255)
red = 255;
if (green < 0)
green = 0;
if (green > 255)
green = 255;
if (blue < 0)
blue = 0;
if (blue > 255)
blue = 255;


color.setRgb(red, green, blue);
color.setAlpha(120);
}
colorPicker->setEventColor(type, color); //QColor(0, 85, 255, 80)
eventColorList[colorChoice] = color;
}

settings.endArray();
settings.endGroup();

colorPicker->saveSettings();

return 0;
}

//-----------------------------------------------------------------------------
void BioSigReader::bufferAllChannels () const
{
Expand Down
7 changes: 0 additions & 7 deletions src/file_handling_impl/biosig_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
#define BIOSIG_READER_H_

#include "file_handling/file_signal_reader.h"
#include "biosig.h"

#include <QFile>
#include <QMutex>
#include <QMap>

namespace sigviewer
{
Expand Down Expand Up @@ -43,9 +39,6 @@ class BioSigReader : public FileSignalReader
//-------------------------------------------------------------------------
int setChannelColors(); /*!< Set colors for all channels. */

//-------------------------------------------------------------------------
int setEventTypeColors(); /*!< Set the colors for events. */

private:
//-------------------------------------------------------------------------
QString open (QString const& file_name);
Expand Down
4 changes: 0 additions & 4 deletions src/file_handling_impl/biosig_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "biosig_writer.h"
#include "file_handler_factory_registrator.h"

#include <QFile>
#include <QMutexLocker>
#include <QMessageBox>
#include <QDebug>

namespace sigviewer
{
Expand Down
3 changes: 0 additions & 3 deletions src/file_handling_impl/biosig_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

#include <biosig.h>

#include <QString>
#include <QMutex>
#include <set>

namespace sigviewer
{
Expand Down
1 change: 0 additions & 1 deletion src/file_handling_impl/channel_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "channel_manager_impl.h"

#include <cmath>

namespace sigviewer
{
Expand Down
4 changes: 0 additions & 4 deletions src/file_handling_impl/event_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@


#include "event_manager_impl.h"
#include "file_handling/file_signal_reader.h"
#include "base/exception.h"
#include "gui/gui_action_command.h"

#include <QMutexLocker>
#include <QDebug>

namespace sigviewer
Expand Down
5 changes: 0 additions & 5 deletions src/file_handling_impl/event_table_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#include "event_table_file_reader.h"

#include <QFile>
#include <QTextStream>
#include <QRegExp>
#include <QTextStream>
#include <QSettings>

namespace sigviewer
{
Expand Down
Loading

0 comments on commit cf787fd

Please sign in to comment.