-
Notifications
You must be signed in to change notification settings - Fork 32
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
Showing
8 changed files
with
323 additions
and
9 deletions.
There are no files selected for viewing
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
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 @@ | ||
#include "../../../src/models/etflist.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 @@ | ||
#include "../../../../src/models/mongoobjects/etflistobject.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,158 @@ | ||
#include "abquant/models/etflist.h" | ||
|
||
#include <TreeFrogModel> | ||
|
||
#include "abquant/models/mongoobjects/etflistobject.h" | ||
EtfList::EtfList() : TAbstractModel(), d(new EtfListObject()) | ||
{ | ||
d->volunit = 0; | ||
d->decimal_point = 0; | ||
d->pre_close = 0; | ||
} | ||
|
||
EtfList::EtfList(const EtfList& other) : TAbstractModel(), d(other.d) {} | ||
|
||
EtfList::EtfList(const EtfListObject& object) : TAbstractModel(), d(new EtfListObject(object)) {} | ||
|
||
EtfList::~EtfList() | ||
{ | ||
// If the reference count becomes 0, | ||
// the shared data object 'EtfListObject' is deleted. | ||
} | ||
|
||
QString EtfList::id() const { return d->_id; } | ||
|
||
QString EtfList::code() const { return d->code; } | ||
|
||
void EtfList::setCode(const QString& code) { d->code = code; } | ||
|
||
int EtfList::volunit() const { return d->volunit; } | ||
|
||
void EtfList::setVolunit(int volunit) { d->volunit = volunit; } | ||
|
||
int EtfList::decimalPoint() const { return d->decimal_point; } | ||
|
||
void EtfList::setDecimalPoint(int decimal_point) { d->decimal_point = decimal_point; } | ||
|
||
QString EtfList::name() const { return d->name; } | ||
|
||
void EtfList::setName(const QString& name) { d->name = name; } | ||
|
||
double EtfList::preClose() const { return d->pre_close; } | ||
|
||
void EtfList::setPreClose(double pre_close) { d->pre_close = pre_close; } | ||
|
||
QString EtfList::sse() const { return d->sse; } | ||
|
||
void EtfList::setSse(const QString& sse) { d->sse = sse; } | ||
|
||
QString EtfList::sec() const { return d->sec; } | ||
|
||
void EtfList::setSec(const QString& sec) { d->sec = sec; } | ||
|
||
EtfList& EtfList::operator=(const EtfList& other) | ||
{ | ||
d = other.d; // increments the reference count of the data | ||
return *this; | ||
} | ||
|
||
bool EtfList::upsert(const QVariantMap& criteria) | ||
{ | ||
auto* obj = dynamic_cast<TMongoObject*>(modelData()); | ||
return (obj) ? obj->upsert(criteria) : false; | ||
} | ||
|
||
EtfList EtfList::create(const QString& code, int volunit, int decimal_point, const QString& name, double pre_close, | ||
const QString& sse, const QString& sec) | ||
{ | ||
EtfListObject obj; | ||
obj.code = code; | ||
obj.volunit = volunit; | ||
obj.decimal_point = decimal_point; | ||
obj.name = name; | ||
obj.pre_close = pre_close; | ||
obj.sse = sse; | ||
obj.sec = sec; | ||
if (!obj.create()) { | ||
return EtfList(); | ||
} | ||
return EtfList(obj); | ||
} | ||
|
||
EtfList EtfList::create(const QVariantMap& values) | ||
{ | ||
EtfList model; | ||
model.setProperties(values); | ||
if (!model.d->create()) { | ||
model.d->clear(); | ||
} | ||
return model; | ||
} | ||
|
||
EtfList EtfList::get(const QString& id) | ||
{ | ||
TMongoODMapper<EtfListObject> mapper; | ||
return EtfList(mapper.findByObjectId(id)); | ||
} | ||
|
||
QList<EtfList> EtfList::get_all_securities(double end) | ||
{ | ||
return tfGetModelListByMongoCriteria<EtfList, EtfListObject>(TCriteria()); | ||
} | ||
|
||
QList<EtfList> EtfList::get_all_securities(const QStringList codes, double end) | ||
{ | ||
TMongoODMapper<EtfListObject> mapper; | ||
TCriteria cri; | ||
// QDateTime start_ = QDateTime::fromString(start, Qt::ISODate); | ||
cri.add(EtfListObject::Code, TMongo::In, | ||
codes); // AND add to the end operator | ||
|
||
// QDateTime end_ = QDateTime::fromString(end, Qt::ISODate); | ||
// cri.add(EtfListObject::DateStamp, TMongo::LessEqual, | ||
// end); // AND add to the end operator | ||
return tfGetModelListByMongoCriteria<EtfList, EtfListObject>(cri); | ||
} | ||
|
||
int EtfList::count() | ||
{ | ||
TMongoODMapper<EtfListObject> mapper; | ||
return mapper.findCount(); | ||
} | ||
|
||
QList<EtfList> EtfList::getAll() { return tfGetModelListByMongoCriteria<EtfList, EtfListObject>(TCriteria()); } | ||
|
||
QJsonArray EtfList::getAllJson() | ||
{ | ||
QJsonArray array; | ||
TMongoODMapper<EtfListObject> mapper; | ||
|
||
if (mapper.find()) { | ||
while (mapper.next()) { | ||
array.append(QJsonValue(QJsonObject::fromVariantMap(EtfList(mapper.value()).toVariantMap()))); | ||
} | ||
} | ||
return array; | ||
} | ||
|
||
TModelObject* EtfList::modelData() { return d.data(); } | ||
|
||
const TModelObject* EtfList::modelData() const { return d.data(); } | ||
|
||
QDataStream& operator<<(QDataStream& ds, const EtfList& model) | ||
{ | ||
auto varmap = model.toVariantMap(); | ||
ds << varmap; | ||
return ds; | ||
} | ||
|
||
QDataStream& operator>>(QDataStream& ds, EtfList& model) | ||
{ | ||
QVariantMap varmap; | ||
ds >> varmap; | ||
model.setProperties(varmap); | ||
return ds; | ||
} | ||
|
||
// Don't remove below this line | ||
T_REGISTER_STREAM_OPERATORS(EtfList) |
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,68 @@ | ||
#ifndef ETFLIST_H | ||
#define ETFLIST_H | ||
|
||
#include <QDateTime> | ||
#include <QSharedDataPointer> | ||
#include <QStringList> | ||
#include <QVariant> | ||
#include <TAbstractModel> | ||
#include <TGlobal> | ||
|
||
class TModelObject; | ||
class EtfListObject; | ||
class QJsonArray; | ||
|
||
class T_MODEL_EXPORT EtfList : public TAbstractModel | ||
{ | ||
public: | ||
EtfList(); | ||
EtfList(const EtfList& other); | ||
EtfList(const EtfListObject& object); | ||
~EtfList(); | ||
|
||
QString id() const; | ||
QString code() const; | ||
void setCode(const QString& code); | ||
int volunit() const; | ||
void setVolunit(int volunit); | ||
int decimalPoint() const; | ||
void setDecimalPoint(int decimalPoint); | ||
QString name() const; | ||
void setName(const QString& name); | ||
double preClose() const; | ||
void setPreClose(double preClose); | ||
QString sse() const; | ||
void setSse(const QString& sse); | ||
QString sec() const; | ||
void setSec(const QString& sec); | ||
EtfList& operator=(const EtfList& other); | ||
|
||
bool create() override { return TAbstractModel::create(); } | ||
bool update() override { return TAbstractModel::update(); } | ||
bool upsert(const QVariantMap& criteria); | ||
bool save() override { return TAbstractModel::save(); } | ||
bool remove() override { return TAbstractModel::remove(); } | ||
|
||
static EtfList create(const QString& code, int volunit, int decimalPoint, const QString& name, double preClose, | ||
const QString& sse, const QString& sec); | ||
static EtfList create(const QVariantMap& values); | ||
static EtfList get(const QString& id); | ||
static QList<EtfList> get_all_securities(double end = 0); | ||
static QList<EtfList> get_all_securities(const QStringList codes, double end = 0); | ||
static int count(); | ||
static QList<EtfList> getAll(); | ||
static QJsonArray getAllJson(); | ||
|
||
private: | ||
QSharedDataPointer<EtfListObject> d; | ||
|
||
TModelObject* modelData() override; | ||
const TModelObject* modelData() const override; | ||
friend QDataStream& operator<<(QDataStream& ds, const EtfList& model); | ||
friend QDataStream& operator>>(QDataStream& ds, EtfList& model); | ||
}; | ||
|
||
Q_DECLARE_METATYPE(EtfList) | ||
Q_DECLARE_METATYPE(QList<EtfList>) | ||
|
||
#endif // ETFLIST_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
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,54 @@ | ||
#ifndef ETFLISTOBJECT_H | ||
#define ETFLISTOBJECT_H | ||
|
||
#include <QSharedData> | ||
#include <TMongoObject> | ||
|
||
class T_MODEL_EXPORT EtfListObject : public TMongoObject, public QSharedData | ||
{ | ||
public: | ||
QString _id; | ||
QString code; | ||
int volunit; | ||
int decimal_point; | ||
QString name; | ||
double pre_close; | ||
QString sse; | ||
QString sec; | ||
|
||
enum PropertyEtf { | ||
Id = 0, | ||
Code, | ||
Volunit, | ||
DecimalPoint, | ||
Name, | ||
PreClose, | ||
Sse, | ||
Sec, | ||
}; | ||
|
||
virtual QString collectionName() const override { return QStringLiteral("etf_list"); } | ||
virtual QString objectId() const override { return _id; } | ||
virtual QString& objectId() override { return _id; } | ||
|
||
private: | ||
Q_OBJECT | ||
Q_PROPERTY(QString _id READ get_id WRITE set_id) | ||
T_DEFINE_PROPERTY(QString, _id) | ||
Q_PROPERTY(QString code READ getcode WRITE setcode) | ||
T_DEFINE_PROPERTY(QString, code) | ||
Q_PROPERTY(int volunit READ getvolunit WRITE setvolunit) | ||
T_DEFINE_PROPERTY(int, volunit) | ||
Q_PROPERTY(int decimal_point READ getdecimal_point WRITE setdecimal_point) | ||
T_DEFINE_PROPERTY(int, decimal_point) | ||
Q_PROPERTY(QString name READ getname WRITE setname) | ||
T_DEFINE_PROPERTY(QString, name) | ||
Q_PROPERTY(double pre_close READ getpre_close WRITE setpre_close) | ||
T_DEFINE_PROPERTY(double, pre_close) | ||
Q_PROPERTY(QString sse READ getsse WRITE setsse) | ||
T_DEFINE_PROPERTY(QString, sse) | ||
Q_PROPERTY(QString sec READ getsec WRITE setsec) | ||
T_DEFINE_PROPERTY(QString, sec) | ||
}; | ||
|
||
#endif // ETFLISTOBJECT_H |
Oops, something went wrong.