Qt K线图添加通达信标记文字

Qt K线图添加通达信标记文字,通达信标记文字存储文件为 C:\ctp_shhtqh\T0002\mark.dat 。

void MainWindow::getTipLst()
{
    QFile file("C:\\ctp_shhtqh\\T0002\\mark.dat");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        return;
    }

    QTextStream in(&file);
    in.setCodec("GB2312");

    bool tip = false;
    QStringList tipLst;
    while (!in.atEnd())
    {
        QString str = in.readLine();

        if (str == "[TIP]")
        {
            tip = true;
            continue;
        }

        if (str == "[TIPWORD]")
        {
            break;
        }

        if (tip)
        {
            tipLst.append(str);
        }
    }

    file.close();

    mTipLst.clear();
    foreach (QString tip, tipLst)
    {
        QString word = tip.split("=")[1];
        if (!word.isEmpty())
        {
            mTipLst.append(tip);
        }
    }
}
    QString tipStr;
    foreach (QString tip, mTipLst)
    {

        if (tip.contains(code))
        {
            tipStr = tip;
        }
    }

    QMap<QString, QString> tipMap;
    if (!tipStr.isEmpty())
    {
        QStringList tipLst = tipStr.split("=")[1].split("#$");
        foreach (QString tip, tipLst)
        {
            QString date = tip.split(" ")[0];
            QString data = tip.split(" ")[1];
            if (dateLst.contains(date))
            {
                tipMap.insert(date,data);
            }
        }
    }

    bool tipFlag = false;
    for (int i = size - 1; i >= 0; --i)
    {
        StockData data = mStockDataLst.at(i);
        double high = data.High;
        double low = data.Low;

        QStringList tmpLst = data.Date.split("/");
        QString tipDate = QDate::fromString(QStringLiteral("%1-%2-%3").arg(tmpLst[0]).arg(tmpLst[1]).arg(tmpLst[2]), "yyyy-MM-dd").toString("M.d");

        pen.setColor(QColor("red"));
        painter.setPen(pen);
        if (tipFlag)
        {
            painter.drawText(offsetX - (klineWidth / 2.0), (max - high) * offsetY + topBottomMargin, tipMap.value(tipDate));
        }
        else
        {
            painter.drawText(offsetX - (klineWidth / 2.0), (max - low) * offsetY + topBottomMargin + painter.fontMetrics().height(), tipMap.value(tipDate));
        }

        tipFlag = !tipFlag;
        offsetX += offsetX2;
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值