wumu
2025-02-12 8b717bccb1065ba5a38208fb073045e43fb8ef5e
regularinvestment.cpp
@@ -9,6 +9,9 @@
#include <qnetworkreply.h>
#include <QDebug>
#pragma execution_character_set("utf-8")
RegularInvestment::RegularInvestment(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::RegularInvestment)
@@ -21,6 +24,7 @@
    m_nameCodes["中国神华"]= "SH601088";
    m_nameCodes["中国电信"]= "SH601728";
    m_nameCodes["中国移动"]= "SH600941";
    m_nameCodes["工商银行"]= "SH601398";
    // 处理数据爬取的操作
@@ -48,12 +52,19 @@
    // 去请求首页
    m_manager.get(m_request);
    // 处理模型
    // 处理模型 回测
    m_model = new QStandardItemModel(0,7,this);
    ui->tableView->setModel(m_model);
    QStringList labels;
    labels<<"时间"<<"买入价格"<<"数量(手)"<<"所需金额(元)"<<"最新价格"<<"盈亏比"<<"盈亏金额";
    m_model->setHorizontalHeaderLabels(labels);
    // 定投买入
    m_modelBuy = new QStandardItemModel(0,9,this);
    ui->tableView_buyRecord->setModel(m_modelBuy);
    QStringList buyLabels;
    buyLabels<<"申请时间"<<"申请价格(元)"<<"成交时间"<<"成交价格(元)"<<"购买数量(手)"<<"所需金额(元)"<<"最新价格(元)"<<"盈亏比"<<"盈亏金额(元)";
    m_modelBuy->setHorizontalHeaderLabels(buyLabels);
}
@@ -66,9 +77,14 @@
void RegularInvestment::showClosePrice(QString name, QString closePrice)
{
    qDebug()<<name<<closePrice;
    ui->label_closePrice->setText(closePrice);
    if(ui->comboBox->currentText() == name){
        ui->label_closePrice->setText(closePrice);
        on_lineEdit_2_returnPressed(); // 刷新总价
    }else if(ui->comboBox_3->currentText() == name){
        ui->label_closePrice_2->setText(closePrice);
        on_lineEdit_buyNum_returnPressed(); // 刷新总价
    }
    on_lineEdit_2_returnPressed(); // 刷新总价
}
void RegularInvestment::on_comboBox_currentIndexChanged(const QString &arg1)
@@ -203,3 +219,35 @@
    ui->label_winAll->setText(QString::number(allWin));
    ui->label_allRate->setText(QString::number((allWin/allBuy)*100));
}
void RegularInvestment::on_comboBox_3_currentIndexChanged(const QString &arg1)
{
    qDebug()<<"开始定投当前股票为:"<<arg1;
    emit getClosePriceSignal(arg1);
}
void RegularInvestment::on_lineEdit_buyNum_returnPressed()
{
    qDebug()<<ui->lineEdit_buyNum->text();
    double price = ui->lineEdit_buyNum->text().toInt()* 100 * ui->label_closePrice_2->text().toDouble();
    ui->lineEdit_money->setText(QString::number(price));
}
void RegularInvestment::on_pushButton_buy_clicked()
{
    QString applyTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    QString name = ui->comboBox_3->currentText();
    QString code = m_nameCodes[name];
    QString numStr = ui->lineEdit_buyNum->text();
    QString applyPrice = ui->label_closePrice_2->text();
    double needMoney = numStr.toInt() * applyPrice.toDouble()*100;
    int rowCnt = m_modelBuy->rowCount();
    m_modelBuy->setRowCount(rowCnt+1);
    m_modelBuy->setItem(rowCnt,0,new QStandardItem(applyTime));
    m_modelBuy->setItem(rowCnt,1,new QStandardItem(applyPrice));
    m_modelBuy->setItem(rowCnt,4,new QStandardItem(numStr));
    m_modelBuy->setItem(rowCnt,5,new QStandardItem(QString::number(needMoney)));
}