getstocklist.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
historydata.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
historydata.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
historydata.ui | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
showinfomessage.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
showinfomessage.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
showinfomessage.ui | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
getstocklist.cpp
@@ -991,56 +991,68 @@ void GetStockList::showHistoryModelData(QVector<QVector<QString>> &model) // 从历史那边将数据发过来 { m_model->setRowCount(model.size()); qDebug()<<QDateTime::currentDateTime(); m_model->setRowCount(0); for(int i=0;i<model.size();++i){ qDebug()<<"i="<<i; //qDebug()<<"i="<<i; QList<QStandardItem*> items; m_codeNames[model[i][1]] = model[i][0]; for(int j=0;j<model.at(0).size();++j){ //QString str = model[i][j]; //qDebug()<<str; m_model->setItem(i,j,new QStandardItem(model[i][j])); if(j<3){ m_model->setItem(i,j,new QStandardItem(model[i][j])); if(j==2){ m_model->setItem(i,j+1,new QStandardItem(model[i][j])); } }else{ items.append(new QStandardItem(model[i][j])); m_model->setItem(i,j+1,new QStandardItem(model[i][j])); if(j==2){ items.append(new QStandardItem(model[i][j])); } if(j==3){ QStandardItem *percentItem = items.back(); if(percentItem->text().toDouble() > 0){ percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 percentItem->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 } else if(percentItem->text().toDouble() < 0){ percentItem->setData(QColor("green"),Qt::BackgroundColorRole); items.at(0)->setData(QColor("green"),Qt::TextColorRole); } } } m_model->appendRow(items); } qDebug()<<"历史到信息赋值完成"; qDebug()<<"历史到信息赋值完成 行数:"<<m_model->rowCount(); qDebug()<<QDateTime::currentDateTime(); } void GetStockList::showHistoryModelData(QStandardItemModel *model) { //ui->tableView->setModel(model); QVector<QVector<QString>> vec; for(int i=0;i<model->rowCount();++i){ QString row; QVector<QString> tmp; // qDebug()<<QDateTime::currentDateTime(); // //ui->tableView->setModel(model); // QVector<QVector<QString>> vec; // for(int i=0;i<model->rowCount();++i){ // //QString row; // QVector<QString> tmp; m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); // m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); for(int j=0;j<model->columnCount();++j){ row+=model->item(i,j)->text()+" "; tmp.append(model->item(i,j)->text()); } qDebug()<<i<<row; vec.append(tmp); } qDebug()<<"vec size:"<<vec.size(); qDebug()<<"历史到信息赋值完成"; // for(int j=0;j<model->columnCount();++j){ // //row+=model->item(i,j)->text()+" "; // tmp.append(model->item(i,j)->text()); // } // //qDebug()<<i<<row; // vec.append(tmp); // } // qDebug()<<"vec size:"<<vec.size(); qDebug()<<QDateTime::currentDateTime(); m_model->setRowCount(0); for(int i=0;i<vec.size();++i){ for(int i=0;i<model->rowCount();++i){ QList<QStandardItem*> items; for(int j=0;j<vec.at(0).size();++j){ items.append(new QStandardItem(vec.at(i).at(j))); m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); for(int j=0;j<model->columnCount();++j){ items.append(new QStandardItem(model->item(i,j)->text())); if(j==2){ items.append(new QStandardItem(vec.at(i).at(j))); items.append(new QStandardItem(model->item(i,j)->text())); } if(j==3){ QStandardItem *percentItem = items.back(); @@ -1057,5 +1069,6 @@ } m_model->appendRow(items); } qDebug()<<"历史到信息赋值完成 条数:"<<m_model->rowCount(); qDebug()<<QDateTime::currentDateTime(); } historydata.cpp
@@ -25,6 +25,8 @@ // ui相关 ui->dateEdit->setDate(QDate::currentDate()); ui->dateEdit_2->setDate(QDate::currentDate()); m_model = new QStandardItemModel(1,9,this); m_customModel = new CustomSortProxyModel; // 可自定义排序的模型 @@ -66,7 +68,19 @@ // 去请求首页 m_manager.get(m_request); // 股票池相关 m_poolModel = new QStandardItemModel(1,9,this); QStringList poolLabel; poolLabel<<"id"<<"股票名字"<<"股票代号"<<"监控记录时间"<<"监控买入价格"<<"当前价格"<<"盈亏百分比"<<"监控卖出价格"<<"监控卖出时间"; m_poolModel->setHorizontalHeaderLabels(poolLabel); ui->tableView_2->setModel(m_poolModel); // 股票池定时刷新 m_poolTimer = new QTimer(this); connect(m_poolTimer,SIGNAL(timeout()),this,SLOT(poolTimerSlot())); m_poolTimer->start(10*1000); } HistoryData::~HistoryData() @@ -110,9 +124,10 @@ { // 把5000支股票挨个获取到,然后进行数据保存,存到表格中 // 更新的时候,默认支持10年的数据查询 if(m_days <= 0) return; QString time_tar=QString::number(QDateTime::currentMSecsSinceEpoch()); QString dayCnt=QString::number(3000); QString dayCnt=QString::number(m_days); QString type = "day"; // day week month for(auto code:m_codeNames.keys()){ QString url = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%3&type=before&count=-%4&indicator=kline,pe,market_capital,ma").arg(code) @@ -123,6 +138,15 @@ m_manager.get(m_request); //break; // 测试用 } // 更新时间 QString curDate = QDate::currentDate().toString("yyyy-MM-dd"); QString sql = QString("insert into days_info (log_time) values ('%1')").arg(curDate); QSqlQuery que(db); if(que.exec(sql)){ qDebug()<<"update log time ok:"<<curDate; }else{ qDebug()<<"update log time fail:"<<curDate; } } @@ -215,9 +239,9 @@ QSqlQuery que(db); if(que.exec(sql)){ qDebug()<<"intsert ok"; qDebug()<<"insert ok"; }else{ qDebug()<<"intsert fail"<<que.lastError().text(); qDebug()<<"insert fail"<<que.lastError().text(); } } @@ -298,3 +322,96 @@ //emit sendHistoryModel(m_modelDatas); // 给信息展示发模型 emit sendHistoryModel(m_model); } void HistoryData::on_pushButton_addStock_clicked() { QString name = ui->lineEdit->text(); QString code = ui->lineEdit_2->text(); QString price = ui->lineEdit_3->text(); QString in_date = ui->dateEdit_2->text(); qDebug()<<name<<code<<price<<in_date; QString sql = QString("insert into stock_pool (name,code,in_price,in_time) values('%1','%2',%3,'%4')").arg(name).arg(code).arg(price).arg(in_date); qDebug()<<"sql:"<<sql; QSqlQuery que(db); if(que.exec(sql)){ qDebug()<<"insert ok"; poolTimerSlot(); // 立马刷新股票池的模型,刷新视图 }else{ qDebug()<<"insert fail"; } } void HistoryData::poolTimerSlot() { QString sql = "select * from stock_pool where state=1"; QSqlQuery que(db); if(que.exec(sql)){ qDebug()<<"select ok:"<<QDateTime::currentDateTime(); m_poolModel->setRowCount(0); while (que.next()) { QList<QStandardItem*> items; for(int i=0;i<9;++i){ QString item = que.value(i).toString(); QStandardItem *it = new QStandardItem(item); if(i==6){ if(item.toDouble() > 0){ it->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 it->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 items.at(1)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 }else if(item.toDouble() < 0){ it->setData(QColor("green"),Qt::BackgroundColorRole); items.at(1)->setData(QColor("green"),Qt::TextColorRole); } } items.append(it); } m_poolModel->appendRow(items); // 整行添加 效率更高 } }else{ qDebug()<<"select fail"; } m_poolTimer->setInterval(60*1000); } void HistoryData::on_checkBox_clicked() { QString dt = "2025-02-10"; QString sql = "select log_time from days_info order by log_time desc"; QSqlQuery que(db); if(que.exec(sql)){ if (que.next()) { dt = que.value(0).toString(); }else{ qDebug()<<"查询结果集为空"; return; } }else{ qDebug()<<"查询失败"; return ; } if(ui->checkBox->isChecked()){ ui->pushButton_update->setEnabled(true); }else{ ui->pushButton_update->setEnabled(false); } QDate d1 = QDate::fromString(dt,"yyyy-MM-dd"); QDate d2 = QDate::currentDate(); int days = 0; // 经过了多少个周内的天数 for(QDate begin = d1.addDays(1);begin <= d2;begin = begin.addDays(1)){ if(begin.dayOfWeek() != Qt::Saturday && begin.dayOfWeek() != Qt::Sunday){ days++; } } qDebug()<<"days:"<<days; m_days = days; // 刷新时间 } historydata.h
@@ -10,6 +10,7 @@ #include <QSqlQuery> #include <QStandardItemModel> #include "customsortproxymodel.h" #include <QTimer> namespace Ui { class HistoryData; @@ -43,6 +44,12 @@ void on_pushButton_2_clicked(); void on_pushButton_addStock_clicked(); void poolTimerSlot(); // 股票池刷新的定时器槽 void on_checkBox_clicked(); private: Ui::HistoryData *ui; @@ -56,8 +63,13 @@ QStandardItemModel *m_model; CustomSortProxyModel *m_customModel; // 用于排序的自定义模型 QStandardItemModel *m_poolModel; // 股票池模型 QVector<QVector<QString>> m_modelDatas; // 行列存储 QTimer *m_poolTimer; // 刷新股票池的定时器 int m_days=0; // 上次更新到现在经过的天数 }; #endif // HISTORYDATA_H historydata.ui
@@ -40,6 +40,13 @@ </property> </widget> </item> <item> <widget class="QCheckBox" name="checkBox"> <property name="text"> <string>更到最新</string> </property> </widget> </item> </layout> </item> <item row="1" column="0"> @@ -127,7 +134,7 @@ </widget> </item> <item> <widget class="QPushButton" name="pushButton_3"> <widget class="QPushButton" name="pushButton_addStock"> <property name="text"> <string>添加</string> </property> showinfomessage.cpp
@@ -1,5 +1,6 @@ #include "showinfomessage.h" #include "ui_showinfomessage.h" #include <QTextCursor> ShowInfoMessage::ShowInfoMessage(QWidget *parent) : QMainWindow(parent), @@ -17,3 +18,9 @@ { ui->textBrowser->append(info); } void ShowInfoMessage::on_pushButton_clicked() { QString text = ui->lineEdit->text(); //ui->textBrowser->moveCursor(); } showinfomessage.h
@@ -17,6 +17,9 @@ public slots: void showInfo(QString info); private slots: void on_pushButton_clicked(); private: Ui::ShowInfoMessage *ui; }; showinfomessage.ui
@@ -16,6 +16,24 @@ <widget class="QWidget" name="centralwidget"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QLineEdit" name="lineEdit"> <property name="placeholderText"> <string>输入要查找的内容</string> </property> </widget> </item> <item> <widget class="QPushButton" name="pushButton"> <property name="text"> <string>查找</string> </property> </widget> </item> </layout> </item> <item row="1" column="0"> <widget class="QTextBrowser" name="textBrowser"/> </item> </layout>