This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7ea142
commit 40c7ed0
Showing
43 changed files
with
4,004 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "CandleStick.h" | ||
|
||
CandleStick::CandleStick(QString nome, QStringList x, double min_Y, double max_Y, QColor col){ | ||
minY = min_Y; | ||
maxY = max_Y; | ||
nomeGrafico = nome; | ||
grafico->setTitle(nomeGrafico); | ||
grafico->createDefaultAxes(); | ||
|
||
if(!x.isEmpty()){ | ||
axisX = new QBarCategoryAxis(); | ||
axisX->append(x); | ||
axisX->setLinePenColor(col); | ||
grafico->addAxis(axisX, Qt::AlignBottom); | ||
} | ||
else{ | ||
axisX = new QBarCategoryAxis(); | ||
axisX->setLinePenColor(col); | ||
grafico->addAxis(axisX, Qt::AlignBottom); | ||
} | ||
axisX->setTitleText("Asse X"); | ||
|
||
axisY = new QValueAxis(); | ||
axisY->setTitleText("Asse Y"); | ||
axisY->setRange(minY, maxY); | ||
axisY->setLinePenColor(col); | ||
grafico->addAxis(axisY, Qt::AlignLeft); | ||
|
||
series = new QCandlestickSeries(); | ||
series->setName(nome); | ||
series->setIncreasingColor(QColor(Qt::green)); | ||
series->setDecreasingColor(QColor(Qt::red)); | ||
} | ||
|
||
void CandleStick::insert(QString l, QStringList v){ | ||
labels.append(l); | ||
values.append(l); | ||
values.append(v); | ||
|
||
QCandlestickSet *candlestickSet = new QCandlestickSet(); | ||
candlestickSet->setOpen(v[0].toDouble()); | ||
candlestickSet->setHigh(v[1].toDouble()); | ||
candlestickSet->setLow(v[2].toDouble()); | ||
candlestickSet->setClose(v[3].toDouble()); | ||
|
||
series->append(candlestickSet); | ||
finalizza(); | ||
} | ||
|
||
void CandleStick::setNomeSerie(QString s){ | ||
series->setName(s); | ||
nomeSerie = s; | ||
} | ||
|
||
void CandleStick::reloadGrafico(){ | ||
grafico->removeSeries(series); | ||
series = new QCandlestickSeries(); | ||
series->setName(nomeSerie); | ||
series->setIncreasingColor(QColor(Qt::green)); | ||
series->setDecreasingColor(QColor(Qt::red)); | ||
serie.clear(); | ||
|
||
for(int i=0; i<labels.size(); i++){ | ||
QCandlestickSet *candlestickSet = new QCandlestickSet(); | ||
candlestickSet->setOpen(values[(i*5)+1].toDouble()); | ||
candlestickSet->setHigh(values[(i*5)+2].toDouble()); | ||
candlestickSet->setLow(values[(i*5)+3].toDouble()); | ||
candlestickSet->setClose(values[(i*5)+4].toDouble()); | ||
series->append(candlestickSet); | ||
} | ||
finalizza(); | ||
} | ||
|
||
void CandleStick::finalizza(){ | ||
if(!grafico->series().isEmpty()){ | ||
grafico->removeSeries(series); | ||
} | ||
grafico->addSeries(series); | ||
serie.push_back(series); | ||
|
||
grafico->createDefaultAxes(); | ||
|
||
axisX = qobject_cast<QBarCategoryAxis *>(grafico->axes(Qt::Horizontal).at(0)); | ||
axisX->setCategories(labels); | ||
|
||
axisY = qobject_cast<QValueAxis *>(grafico->axes(Qt::Vertical).at(0)); | ||
axisY->setMax(maxY); | ||
axisY->setMin(minY); | ||
|
||
salvaGrafico(this); | ||
} | ||
|
||
void CandleStick::setAxis(QStringList x, double min_Y, double max_Y, QColor col){ | ||
axisX = new QBarCategoryAxis(); | ||
axisX->setTitleText("Asse X"); | ||
axisX->append(x); | ||
axisX->setLinePenColor(col); | ||
|
||
axisY = new QValueAxis(); | ||
axisY->setTitleText("Asse Y"); | ||
axisY->setMin(min_Y); | ||
axisY->setMax(max_Y); | ||
axisY->setLinePenColor(col); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef CANDLESTICK_H | ||
#define CANDLESTICK_H | ||
|
||
#include "chart.h" | ||
|
||
class CandleStick : public Chart{ | ||
private: | ||
QCandlestickSeries *series=nullptr; | ||
QString nomeSerie=""; | ||
public: | ||
explicit CandleStick(QString="", QStringList = {}, double = 0, double = 20, QColor="black"); | ||
virtual void finalizza(); | ||
virtual void insert(QString, QStringList={"0", "0", "0", "0"}); | ||
virtual void reloadGrafico(); | ||
void updateAxisX(); | ||
void setNomeSerie(QString); | ||
void setAxis(QStringList, double, double, QColor); | ||
CandleStick* clone() const{return new CandleStick(*this);} | ||
}; | ||
|
||
#endif // CANDLESTICK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
#include "mapper.h" | ||
|
||
Mapper::Mapper(Chart *c, QObject *parent) : QAbstractTableModel(parent), grafico(c){ | ||
if(m_columnCount < -1 || m_rowCount < -1) throw graphical_exceptions("Mapper"); | ||
|
||
if(dynamic_cast<bar*>(grafico) || dynamic_cast<CandleStick*>(grafico)){ | ||
int div=0; | ||
m_columnCount = c->getLabels().size(); | ||
|
||
if(c->getValues().size()>0 && c->getLabels().size()>0){ | ||
m_rowCount = c->getValues().size(); | ||
div = m_rowCount/m_columnCount; | ||
} | ||
else{ | ||
m_rowCount=0; | ||
} | ||
|
||
for (int i = 0; i < div; i++) { | ||
QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount); | ||
for (int k = 0; k < dataVec->size(); k++) { | ||
dataVec->replace(k, c->getValues().at(i+(k*div)).toDouble()); | ||
} | ||
m_data.append(dataVec); | ||
} | ||
} | ||
if(dynamic_cast<pie*>(grafico)){ | ||
m_columnCount = c->getValues().size(); | ||
QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount); | ||
for (int k = 0; k < dataVec->size(); k++) { | ||
dataVec->replace(k, c->getValues().at(k).toDouble()); | ||
} | ||
m_data.append(dataVec); | ||
} | ||
if(dynamic_cast<line*>(grafico)){ | ||
int cont = 0, cont2 = 0; | ||
m_columnCount = c->getLabels().size()*2; | ||
if(c->getValues().size()>0) | ||
m_rowCount = c->getValues().size()/c->getLabels().size(); | ||
else | ||
m_rowCount=0; | ||
|
||
for (int i = 0; i < m_rowCount; i++) { | ||
QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount); | ||
for (int k = 0; k < dataVec->size(); k++) { | ||
if(k % 2 == 0){ | ||
dataVec->replace(k, cont); | ||
} | ||
else{ | ||
dataVec->replace(k, c->getValues().at(i+cont2).toDouble()); | ||
cont2+=(m_rowCount); | ||
} | ||
} | ||
cont++; | ||
cont2=0; | ||
m_data.append(dataVec); | ||
} | ||
} | ||
} | ||
|
||
int Mapper::rowCount(const QModelIndex &parent) const{ | ||
Q_UNUSED(parent) | ||
return parent.isValid() ? 0 : m_data.count(); | ||
} | ||
|
||
int Mapper::columnCount(const QModelIndex &parent) const{ | ||
Q_UNUSED(parent) | ||
return parent.isValid() ? 0 : m_columnCount; | ||
} | ||
|
||
QVariant Mapper::headerData(int section, Qt::Orientation orientation, int role) const{ | ||
if (role != Qt::DisplayRole) | ||
return QVariant(); | ||
if(dynamic_cast<CandleStick*>(grafico)){ | ||
if (orientation == Qt::Vertical) { | ||
if (section % 5 == 0){ | ||
return "time"; | ||
} | ||
else if(section % 5 == 1){ | ||
return "open"; | ||
} | ||
else if(section % 5 == 2){ | ||
return "high"; | ||
} | ||
else if(section % 5 == 3){ | ||
return "low"; | ||
} | ||
else if(section % 5 == 4){ | ||
return "close"; | ||
} | ||
} else { | ||
if(section < grafico->getLabels().size()){ | ||
return grafico->getLabels().at(section); | ||
} | ||
} | ||
} | ||
if(!dynamic_cast<line*>(grafico)){ | ||
return QString("%1").arg(section + 1); | ||
} | ||
else{ | ||
if (orientation == Qt::Horizontal) { | ||
if (section % 2 == 0) | ||
return "x"; | ||
else | ||
return "y"; | ||
} else { | ||
return QString("%1").arg(section + 1); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
QVariant Mapper::data(const QModelIndex &index, int role) const{ | ||
if (role == Qt::DisplayRole) { | ||
return m_data[index.row()]->at(index.column()); | ||
} else if (role == Qt::EditRole) { | ||
return m_data[index.row()]->at(index.column()); | ||
} else if (role == Qt::BackgroundRole) { | ||
for (const QRect &rect : m_mapping) { | ||
if (rect.contains(index.column(), index.row())){ | ||
return QColor(m_mapping.key(rect)); | ||
} | ||
} | ||
return QColor(Qt::white); | ||
} | ||
return QVariant(); | ||
} | ||
|
||
bool Mapper::setData(const QModelIndex &index, const QVariant &value, int role){ | ||
if (index.isValid() && role == Qt::EditRole) { | ||
m_data[index.row()]->replace(index.column(), value.toDouble()); | ||
if(dynamic_cast<line*>(grafico)){ | ||
if(index.column() % 2 == 1 && index.column() > 0){ | ||
Chart::setValues((index.column()/2)*(grafico->getValues().size()/grafico->getLabels().size())+index.row(), value.toString()); | ||
} | ||
} | ||
if(dynamic_cast<bar*>(grafico) || dynamic_cast<pie*>(grafico)){ | ||
Chart::setValues((index.column()*(grafico->getValues().size()/grafico->getLabels().size()))+index.row(), value.toString()); | ||
} | ||
if(dynamic_cast<CandleStick*>(grafico)){ | ||
if(index.row() == 0){ | ||
Chart::setLabel(index.column(), value.toString()); | ||
grafico->finalizza(); | ||
} | ||
else{ | ||
Chart::setValues((index.column()*(grafico->getValues().size()/grafico->getLabels().size()))+index.row(), value.toString()); | ||
} | ||
} | ||
emit dataChanged(index, index); | ||
|
||
Chart::salvaGrafico(grafico); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
Qt::ItemFlags Mapper::flags(const QModelIndex &index) const | ||
{ | ||
if(dynamic_cast<line*>(grafico)){ | ||
if(index.column() % 2 != 0) | ||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; | ||
else | ||
return Qt::ItemIsSelectable; | ||
} | ||
else{ | ||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; | ||
} | ||
} | ||
|
||
void Mapper::addMapping(QString color, QRect area){ | ||
m_mapping.insertMulti(color, area); | ||
} | ||
|
||
bool Mapper::insertRow(int position, int rows, const QModelIndex &parent){ | ||
beginInsertRows(parent, position, position + rows - 1); | ||
m_columnCount = columnCount(); | ||
m_rowCount+=rows; | ||
operation_type = "addrow"; | ||
|
||
QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount); | ||
for (int k = 0; k < dataVec->size(); k++) { | ||
dataVec->replace(k, 0); | ||
} | ||
|
||
m_data.append(dataVec); | ||
endInsertRows(); | ||
return true; | ||
} | ||
|
||
bool Mapper::removeRow(int position, int rows, const QModelIndex &parent){ | ||
if(position < -1) throw graphical_exceptions("Mapper"); | ||
beginRemoveRows(parent, position, position + rows - 1); | ||
operation_type = "removerow"; | ||
m_rowCount-=rows; | ||
endRemoveRows(); | ||
return true; | ||
} | ||
|
||
bool Mapper::insertColumn(int position, int columns, const QModelIndex &parent){ | ||
beginInsertColumns(parent, position, position + columns - 1); | ||
operation_type = "addcol"; | ||
for (int k = 0; k < m_data.count(); k++) { | ||
m_data[k]->insert(columns, 0); | ||
} | ||
m_columnCount+=columns; | ||
endInsertColumns(); | ||
return true; | ||
} | ||
|
||
bool Mapper::removeColumn(int position, int columns, const QModelIndex &parent){ | ||
if(position < -1) throw graphical_exceptions("Mapper"); | ||
beginRemoveColumns(parent, position, position + columns - 1); | ||
operation_type = "removecol"; | ||
endRemoveColumns(); | ||
m_columnCount-=columns; | ||
return true; | ||
} | ||
|
||
QString Mapper::getOperationType() const{ | ||
return operation_type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
QT += core gui | ||
QT += xml | ||
QT += core gui charts | ||
QT += core | ||
QT += gui | ||
QT += charts | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
CONFIG += c++11 | ||
|
||
# You can make your code fail to compile if it uses deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
SOURCES += \ | ||
CandleStick.cpp \ | ||
Mapper.cpp \ | ||
bar.cpp \ | ||
chart.cpp \ | ||
exceptions.cpp \ | ||
line.cpp \ | ||
main.cpp \ | ||
mainwindow.cpp \ | ||
nomiclassi.cpp \ | ||
pie.cpp \ | ||
tablewidget.cpp | ||
|
||
HEADERS += \ | ||
CandleStick.h \ | ||
bar.h \ | ||
chart.h \ | ||
exceptions.h \ | ||
line.h \ | ||
mainwindow.h \ | ||
mapper.h \ | ||
nomiclassi.h \ | ||
pie.h \ | ||
tablewidget.h | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target | ||
|
||
FORMS += \ | ||
mainwindow.ui | ||
|
||
RESOURCES += \ | ||
risorse.qrc |
Oops, something went wrong.