From 6c68684bcdc55572de4084d7b4bc97ed20ffc68c Mon Sep 17 00:00:00 2001 From: wumu <mayi@mayi.com> Date: 星期三, 08 一月 2025 22:49:23 +0800 Subject: [PATCH] 251008 --- leadingcompany.ui | 117 ++++ main.cpp | 11 leadingcompany.cpp | 46 + getstocklist.h | 85 +++ stockpolicy.ui | 24 + stock_plan.pro | 46 + stockpolicy.cpp | 95 +++ README.md | 2 showinfomessage.ui | 37 + clientmainwindow.h | 34 + showinfomessage.h | 24 + clientmainwindow.cpp | 44 + clientmainwindow.ui | 60 ++ getstocklist.cpp | 635 ++++++++++++++++++++++++++ leadingcompany.h | 29 + showinfomessage.cpp | 19 stockpolicy.h | 41 + getstocklist.ui | 62 ++ 18 files changed, 1,410 insertions(+), 1 deletions(-) diff --git a/README.md b/README.md index 1dfb014..648083f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ ## stock_plan -閲忓寲 +鑲$エ鐩稿叧鐨勭埇鍙栥�佸垎鏋愩�佺瓥鐣ョ瓑 2023-07-07 diff --git a/clientmainwindow.cpp b/clientmainwindow.cpp new file mode 100644 index 0000000..3c4e54b --- /dev/null +++ b/clientmainwindow.cpp @@ -0,0 +1,44 @@ +锘�#include "clientmainwindow.h" +#include "ui_clientmainwindow.h" + + +ClientMainWindow::ClientMainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::ClientMainWindow) +{ + ui->setupUi(this); + // 鍚姩鐣岄潰鍒濆鍖栫殑鍑芥暟 + initUi(); + +} + +ClientMainWindow::~ClientMainWindow() +{ + delete ui; +} + +void ClientMainWindow::initUi() +{ + ui->tabWidget->clear(); // 娓呴櫎鏃犵敤鐨勫墠2涓猼ab椤甸潰 + + // 瀹炰緥鍖栬幏鍙栬偂绁ㄥ垪琛ㄧ殑鐣岄潰瀵硅薄 + m_getStockList = new GetStockList(this); + // 灏嗚偂绁ㄧ晫闈㈠璞℃斁鍒颁富鐣岄潰鐨則ab閫夐」鍗¢噷闈㈡潵 + ui->tabWidget->addTab(m_getStockList,"鑾峰彇淇℃伅"); + + m_stockPolicy = new StockPolicy(this); + ui->tabWidget->addTab(m_stockPolicy,"鑲$エ绛栫暐"); + + m_leadingCom = new LeadingCompany(this); + ui->tabWidget->addTab(m_leadingCom,"榫欏ご鍏徃"); + + m_showInfoMess = new ShowInfoMessage(this); + ui->tabWidget->addTab(m_showInfoMess,"淇℃伅鎻愮ず"); + + // 鍏宠仈涓�涓�2涓晫闈㈢殑淇″彿鍜屾Ы锛岀敤鏉ヤ紶閫掑浘琛ㄦ墍闇�鐨勬暟鎹強灞曠ず + connect(m_getStockList,SIGNAL(sendChartData(QLineSeries*)),m_stockPolicy,SLOT(showNewStockData(QLineSeries*))); + connect(m_getStockList,SIGNAL(sendChartData(QSplineSeries*)),m_stockPolicy,SLOT(showNewStockData(QSplineSeries*))); + + connect(m_getStockList,SIGNAL(sendInfoMess(QString)),m_showInfoMess,SLOT(showInfo(QString))); + +} diff --git a/clientmainwindow.h b/clientmainwindow.h new file mode 100644 index 0000000..dbd9395 --- /dev/null +++ b/clientmainwindow.h @@ -0,0 +1,34 @@ +锘�#ifndef CLIENTMAINWINDOW_H +#define CLIENTMAINWINDOW_H + +#include <QMainWindow> +#include "getstocklist.h" +#include "stockpolicy.h" +#include "leadingcompany.h" +#include "showinfomessage.h" + +namespace Ui { +class ClientMainWindow; +} + +class ClientMainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit ClientMainWindow(QWidget *parent = 0); + ~ClientMainWindow(); + + void initUi(); + +private: + Ui::ClientMainWindow *ui; + GetStockList *m_getStockList; + StockPolicy *m_stockPolicy; + LeadingCompany *m_leadingCom; // 榫欏ご鍏徃 + ShowInfoMessage *m_showInfoMess; // 鏄剧ず淇℃伅鎻愮ず + + +}; + +#endif // CLIENTMAINWINDOW_H diff --git a/clientmainwindow.ui b/clientmainwindow.ui new file mode 100644 index 0000000..9600480 --- /dev/null +++ b/clientmainwindow.ui @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ClientMainWindow</class> + <widget class="QMainWindow" name="ClientMainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>900</width> + <height>591</height> + </rect> + </property> + <property name="windowTitle"> + <string>ClientMainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>Tab 1</string> + </attribute> + </widget> + <widget class="QWidget" name="tab_2"> + <attribute name="title"> + <string>Tab 2</string> + </attribute> + </widget> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>900</width> + <height>26</height> + </rect> + </property> + </widget> + <widget class="QToolBar" name="mainToolBar"> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + </widget> + <widget class="QStatusBar" name="statusBar"/> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> diff --git a/getstocklist.cpp b/getstocklist.cpp new file mode 100644 index 0000000..d9f0fa0 --- /dev/null +++ b/getstocklist.cpp @@ -0,0 +1,635 @@ +锘�#include "getstocklist.h" +#include "ui_getstocklist.h" +#include <QDebug> +#include <QFile> +#include <QNetworkCookieJar> +#include <QJsonDocument> +#include <QJsonObject> +#include <QJsonArray> +#include <QLibrary> // 鐢ㄤ簬鍔犺浇dll鍔ㄦ�佸簱鐨勭被 + +GetStockList::GetStockList(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::GetStockList) +{ + ui->setupUi(this); + ui->pushButton_get->hide(); + ui->statusbar->hide(); + + // 鏂规2: + // 濡傛灉https 璁块棶鐨勬椂鍊欙紝杩樻槸鐖彇澶辫触锛屽彲浠ヤ唬鐮佸姞杞藉姩鎬佸簱鏉ユ敮鎸� + // 鍓嶆彁鏉′欢鏄妸2涓猟ll鍔ㄦ�佸簱鎷疯礉鐨勭敓鎴愮洰褰曚腑:libeay32.dll 鍜� ssleay32.dll + // 鎷疯礉鍒扮敓鎴愮洰褰曪紝灏卞彲浠ョ洿鎺ュ姞杞� + QLibrary lb("libeay32.dll"); + if(lb.load()){ + qDebug()<<"load libeay32.dll 鎴愬姛"; + } + + QLibrary lb2("ssleay32.dll"); + if(lb2.load()){ + qDebug()<<"load ssleay32.dll 鎴愬姛"; + } + + // 鎸囧畾褰撳墠鏃ユ湡绫诲瀷涓� week + m_dateType = "week"; + // 鍒濆鍖栧洖娴嬫暟閲忎负100 + m_maTestNum = 100; + + // 妯″瀷鍙婅〃鏍艰鍥� + m_model = new QStandardItemModel(this); + m_model->setColumnCount(10); // 璁剧疆10鍒� + QStringList labels; + labels<<"鑲$エ鍚嶅瓧"<<"鑲$エ浠e彿"<<"鎬诲競鍊�(浜�)"<<"娴侀�氬競鍊�(浜�)"<<"娑ㄨ穼骞�(%)"<<"鏀剁洏浠�"<<"鎴愪氦棰�(浜�)"<<"鎴愪氦閲�(鎵�)"<<"鎹㈡墜鐜�(%)"<<"甯傜泩鐜�"; + m_model->setHorizontalHeaderLabels(labels); // 璁剧疆妯″瀷鐨勫垪鏍囩鍚� + ui->tableView->setModel(m_model); // 灏嗘ā鍨嬪拰瑙嗗浘鍏宠仈 + ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); // 璁剧疆鍐呭鑷�傚簲锛屾媺浼� + + // 缁欒〃鏍艰鍥炬坊鍔犲彸鍑昏嚜瀹氫箟鑿滃崟 + ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); // 璁剧疆涓婁笅鏂囪彍鍗曠瓥鐣ヤ负鑷畾涔夎彍鍗� + connect(ui->tableView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(showMenu())); + + m_menu = new QMenu(this); + + QMenu *dateMenu = new QMenu("璁剧疆鍛ㄦ湡"); + QAction *weekAction = dateMenu->addAction("璁剧疆涓哄懆"); + QAction *monthAction = dateMenu->addAction("璁剧疆涓烘湀"); + QAction *yearAction = dateMenu->addAction("璁剧疆涓哄勾"); + m_menu->addMenu(dateMenu); + + connect(weekAction,&QAction::triggered,this,[&]{ m_dateType = "week";}); // 淇敼鏃ユ湡绫诲瀷 + connect(monthAction,&QAction::triggered,this,[&]{ m_dateType = "month";}); + connect(yearAction,&QAction::triggered,this,[&]{ m_dateType = "year";}); + + + QMenu *testMenu = new QMenu("璁剧疆鍥炴祴鑲$エ鏁伴噺"); + QAction *pre100Action = testMenu->addAction("璁剧疆涓哄墠100"); + QAction *pre300Action = testMenu->addAction("璁剧疆涓哄墠300"); + QAction *pre500Action = testMenu->addAction("璁剧疆涓哄墠500"); + QAction *pre1000Action = testMenu->addAction("璁剧疆涓哄墠1000"); + QAction *pre5000Action = testMenu->addAction("璁剧疆涓哄墠5000"); + + m_menu->addMenu(testMenu); + + connect(pre100Action,&QAction::triggered,this,[&]{ m_maTestNum = 100;}); // 淇敼鍥炴祴鏁伴噺绫诲瀷 + connect(pre300Action,&QAction::triggered,this,[&]{ m_maTestNum = 300;}); + connect(pre500Action,&QAction::triggered,this,[&]{ m_maTestNum = 500;}); + connect(pre1000Action,&QAction::triggered,this,[&]{ m_maTestNum = 1000;}); + connect(pre5000Action,&QAction::triggered,this,[&]{ m_maTestNum = 5000;}); + + QAction *policy = m_menu->addAction("绛栫暐鍒嗘瀽"); + QAction *price = m_menu->addAction("鏈�鏂颁环鏍�"); + QAction *maPolicy = m_menu->addAction("MA绛栫暐"); + QAction *macdPolicy = m_menu->addAction("MACD绛栫暐"); + QAction *maTest100 = m_menu->addAction("MA绛栫暐-鍥炴祴"); + + + + connect(policy,SIGNAL(triggered(bool)),this,SLOT(policySlot())); // 褰撶偣鍑昏彍鍗曠瓥鐣ュ垎鏋愪箣鍚庯紝灏变細鍑哄彂妲� policySlot 鍑芥暟 + connect(price,SIGNAL(triggered(bool)),this,SLOT(priceSlot())); + connect(maPolicy,SIGNAL(triggered(bool)),this,SLOT(maPolicySlot())); // MA鍧囩嚎绛栫暐 + connect(macdPolicy,SIGNAL(triggered(bool)),this,SLOT(macdPolicySlot())); // MA鍧囩嚎绛栫暐 + connect(maTest100,SIGNAL(triggered(bool)),this,SLOT(maTest100Slot())); // MA鍥炴祴鍓�100鍚� + + + + // 澶勭悊鏁版嵁鐖彇鐨勬搷浣� + // 妯℃嫙娴忚鍣ㄧ殑鍙傛暟 + QString userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"; + m_cookie = "__utma=1.731742638.1647403301.1699341909.1700229030.32; device_id=196eef62baf016c7d95a22752d9bdbab; smidV2=20240414233939e95389ecf7ecd2f4d08524ce770aacd500753aa68e9640320; s=c611de27gr; cookiesu=651726298794778; xq_a_token=220b0abef0fac476d076c9f7a3938b7edac35f48; xqat=220b0abef0fac476d076c9f7a3938b7edac35f48; xq_r_token=1d46f0ed628506486164e5055a4993f9b54b2f4c; xq_id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOi0xLCJpc3MiOiJ1YyIsImV4cCI6MTcyOTIxMjc4NCwiY3RtIjoxNzI3NDkwOTU3MjA0LCJjaWQiOiJkOWQwbjRBWnVwIn0.C_GmKEhTaaioDMLWkgZyMXDl4duYEVmsdJHsTi7gbcNz0Tohc-uxHsaw0yBT5k-qmbrJ_RaLMCSxy06v14-R3dwL-MsiKRHxHa5qvQZN4BjEgvPRkqqvPgE_fkPLte8qQOEgd5iVkhr-4mjip0-9WCeXYiH7DygxFOBXGlgoPtpPzAtOTm5TWJmXh0ipDsIZxfNOl8jipXYaIdkv_kqLul5gqiBi5qqnwONDa24Zx-Kvpm8ySWiPFBLzZBqTuRBs4oKAMpSdOiYGLVL7dcSDDZyWqAexmrN4f19hkmd6gBHL4dCczRMDGYc1e98sQtlbZ5lgeEuuM24jjcuwCxsxXQ; u=651726298794778; Hm_lvt_1db88642e346389874251b5a1eded6e3=1727099939,1727251802,1727488707,1727491020; HMACCOUNT=1628106D67895387; acw_tc=2760828017275244258732552e9880f861be6db0c40facbdd5f223490decc2; acw_sc__v2=66f7ee8290dc3f63112948801ef331b8c97ccb35; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1727524485; .thumbcache_f24b8bbe5a5934237bbc0eda20c1b6e7=t00N841S/BEpxTGOoJrbm0blWik12om0ew/whcq/V2DNtyEA8um7J+yzeGOli+6iP/TrvrH0YKH2kHlsmDb5EQ%3D%3D; ssxmod_itna=YqAOBKYve+x0ODfxBcDB4DKM7RtAA4454DkDIEC+GAqGNK3DZDiqAPGhDC8RzeL4Ko7+e2aeQvSeopd5pYDk0Ge5TB0PIjaIDB3DEx06TCCQxiiSDCeDIDWeDiDG4Gm4qGtDpxG=DjDytZ9TtDm4GWGqDmDGYBWqDgDYQDGwIXD7QDIqtW07tQDDNQKpAKDiYeHlL5uMRMtOrK7DtDjdTD/3+kZCbCcPwVFeFO=nPcDB6wxBjZRq00Un+g4mNqLYf4IDAxQuYKtgheYYoAfDhTKhhLSGx4tGY4+GDKSiMS2DDAIvdKeD; ssxmod_itna2=YqAOBKYve+x0ODfxBcDB4DKM7RtAA4454DkDIEC+GDA69mqD/YttDFhxMltFKApT7bCMH+bytp7GQQyCbBWukeAF3+jxeN2wLjbQAFcdwbeNeoohjQ4qtEnLg4TKyX2LqVL=CGaV=GqZZqbDby8DFnFbgWiZEH8zoBzBCbzqWeqwoPq7/TpL=gIRY8sVhEpnWWHQU8sz+S8=+8oRerHq0wtQnSzyQDK7Dmvr3a+VY7fezRmxKF=bDeqexYUbuuzw2eR3In9evW6tzHbQY6vp=AIOUc9l6vc0vOl9plD6D07zGGQ41uxpii2Y5s7KvYQDWGYExD7=DYKKeD=="; + QByteArray cookieByte = m_cookie.toUtf8(); + QList<QNetworkCookie> list; + list.push_back(QNetworkCookie(cookieByte)); + + QVariant var; + var.setValue(list); + // 璁剧疆瑕佽闂殑缃戝潃 + m_request.setUrl(QUrl("https://xueqiu.com/?md5__1038=QqGxcDnDyiitnD05o4%2Br%3Di%3De0KDtYqCDRWOoD")); + // 璁剧疆璇锋眰澶达紝鐢ㄦ埛浠g悊锛岀敤鏉ユā鎷熸祻瑙堝櫒 + m_request.setHeader(QNetworkRequest::UserAgentHeader,userAgent); + // 璁剧疆cookie + //m_request.setHeader(QNetworkRequest::CookieHeader, var); + + // 鏌ョ湅manager閮芥敮鎸佸摢浜涘崗璁� + qDebug()<<"鏀寔鐨勫崗璁�:"<<m_manager.supportedSchemes(); + // 鍏宠仈淇″彿妲斤紝褰撹姹傜鐞嗗璞″畬鍏ㄦ墦寮�缃戦〉涔嬪悗锛屼細灏嗘暟鎹粰妲藉嚱鏁板鐞� + connect(&m_manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(showAplyData(QNetworkReply*))); + on_pushButton_get_clicked(); + + // 琛ㄦ牸鍒楁帓搴� + ui->tableView->setSortingEnabled(false); + ui->tableView->horizontalHeader()->setSortIndicatorShown(false); + connect(ui->tableView->horizontalHeader(),&QHeaderView::sortIndicatorChanged,this,[=](int index,Qt::SortOrder order){ + qDebug()<<"sort:"<<index<<order; + m_model->sort(index,order); + ui->tableView->horizontalHeader()->setSortIndicatorShown(true); + + }); + + // 瀹氭椂鑾峰彇鑲$エ浠e彿鐨勫畾鏃跺櫒鐩稿叧 + m_getCodeTimer = new QTimer(this); + connect(m_getCodeTimer,SIGNAL(timeout()),this,SLOT(getCodeSlot())); + +} + +GetStockList::~GetStockList() +{ + delete ui; +} + +/* + * 瑕佸鐞嗙殑澶ф鏍煎紡濡備笅 + * + * {"data":{"count":5000,"list":[{"symbol":"SZ300817","net_profit_cagr":-17.50317062659299,"north_net_inflow":null, + * "ps":4.4809,"type":11,"percent":20.03,"has_follow":false,"tick_size":0.01,"pb_ttm":3.2607,"float_shares":99366912, + * "current":18.04,"amplitude":24.02,"pcf":21.3128,"current_year_percent":28.25,"float_market_capital":1.792579092E9, + * "north_net_inflow_time":null,"market_capital":3.1504802E9,"dividend_yield":1.153,"lot_size":100,"roe_ttm":5.6761589850147, + * "total_percent":78.15,"percent5m":0.0,"income_cagr":2.235799161377394,"amount":3.5973639118E8,"chg":3.01, + * "issue_date_ts":1581955200000,"eps":0.32,"main_net_inflows":6078207.0,"volume":21355714,"volume_ratio":4.35,"pb":3.143, + * "followers":6931,"turnover_rate":21.49,"first_percent":43.98,"name":"鍙岄鑲′唤","pe_ttm":56.123,"total_shares":174638592, + * "limitup_days":1}]}} + */ + +// 鑾峰彇鎵�鏈夋勃娣辫偂绁ㄧ殑淇℃伅 +void GetStockList::getStockAllCode(QByteArray &buffer) +{ + // 浣跨敤JSON杩涜鏁版嵁澶勭悊 + QJsonDocument jd = QJsonDocument::fromJson(buffer); + if(jd.isArray()){ + qDebug()<<"js array"; + + }else if(jd.isObject()){ + qDebug()<<"js object"; + QJsonObject jobject = jd.object(); + QStringList jlist = jobject.keys(); + qDebug()<<"jlist:"<<jlist; // 杈撳嚭涓�涓嬩竴绾ч敭鐨勬儏鍐� + // 閫氳繃閿�煎鐨勬柟寮忔彁鍙栨暟鎹� + int count = jobject["data"].toObject()["count"].toInt(); + qDebug()<<"count:"<<count; + QJsonArray listData = jobject["data"].toObject()["list"].toArray(); + count = listData.size(); // 閫傚簲鏂扮増鐨勫鐞� + for(int i=0;i<count;++i){ + QString symbol = listData.at(i).toObject().value("symbol").toString(); // 鑲$エ浠e彿 + QString name = listData.at(i).toObject().value("name").toString(); // 鑲$エ鍚嶅瓧 + double market_capital = listData.at(i).toObject().value("market_capital").toDouble()/100000000; // 鎬诲競鍊� 鍗曚綅 浜� + double float_market_capital = listData.at(i).toObject().value("float_market_capital").toDouble()/100000000; // 娴侀�氬競鍊� 鍗曚綅 浜� + double percent = listData.at(i).toObject().value("percent").toDouble(); // 娑ㄨ穼骞� 鐧惧垎姣旓紝澶т簬0涓婃定锛屽皬浜�0涓嬭穼 + double current = listData.at(i).toObject().value("current").toDouble(); // 鏀剁洏浠� + double amount = listData.at(i).toObject().value("amount").toDouble()/100000000; // 鎴愪氦棰� 鍗曚綅 浜� + double volume = listData.at(i).toObject().value("volume").toInt(); // 鎴愪氦閲� 鍗曚綅 鎵� + double turnover_rate = listData.at(i).toObject().value("turnover_rate").toDouble(); // 鎹㈡墜鐜� 鐧惧垎姣� + double pe_ttm = listData.at(i).toObject().value("pe_ttm").toDouble(); // PE鍊� 甯傜泩鐜� 鐧惧垎姣� + //qDebug()<<name<<symbol<<market_capital; + + m_codeNames[symbol] = name; // 娣诲姞鎴栬鐩栭敭鍊煎锛屼繚瀛樿偂绁ㄤ唬鍙峰拰鑲$エ鍚嶅瓧鍒癿ap涓� + + // 娣诲姞妯″瀷琛岀殑鏁版嵁:鑲$エ鍚嶅瓧銆佽偂绁ㄤ唬鍙� 鎬诲競鍊� 娴侀�氬競鍊� 娑ㄨ穼骞� 鏀剁洏浠� 鎴愪氦棰� 鎴愪氦閲� 鎹㈡墜鐜� 甯傜泩鐜� + QList<QStandardItem*> rowItems; + rowItems.append(new QStandardItem(name)); + rowItems.append(new QStandardItem(symbol)); + rowItems.append(new QStandardItem(QString::number(market_capital,'f',2))); + rowItems.append(new QStandardItem(QString::number(float_market_capital))); + QStandardItem *percentItem = new QStandardItem(QString::number(percent)); + if(percent > 0){ + percentItem->setData(QColor("red"),Qt::DecorationRole); // 娣诲姞涓�涓楗扮殑棰滆壊涓虹孩鑹� + percentItem->setData(QColor("red"),Qt::TextColorRole); // 灏嗗瓧浣撻鑹茶缃负绾㈣壊 + rowItems.at(0)->setData(QColor("red"),Qt::TextColorRole); // 灏嗚偂绁ㄥ悕瀛楄缃负绾㈣壊 + } + else if(percent < 0){ + percentItem->setData(QColor("green"),Qt::BackgroundColorRole); + rowItems.at(0)->setData(QColor("green"),Qt::TextColorRole); + } + rowItems.append(percentItem); + rowItems.append(new QStandardItem(QString::number(current))); + rowItems.append(new QStandardItem(QString::number(amount))); + rowItems.append(new QStandardItem(QString::number(volume))); + rowItems.append(new QStandardItem(QString::number(turnover_rate))); + if(pe_ttm > 0){ + rowItems.append(new QStandardItem(QString::number(pe_ttm))); + } + else{ + rowItems.append(new QStandardItem("浜忔崯")); + } + // 娣诲姞涓�琛屾暟鎹」鍒版ā鍨嬩腑 + m_model->appendRow(rowItems); + } + } +} + + +/* 瑕佸鐞嗙殑鍗曚釜鑲$エ鐨勬牸寮忓涓� +{"data":{" ":"SH601127","column":["timestamp","volume","open","high","low","close","chg","percent","turnoverrate","amount","volume_post","amount_post"], +"item":[[1680192000000,592214010,37.57,41.56,35.63,37.85,0.2,0.53,50.63,2.3075281252E10,0,0.0], +[1682611200000,355174985,36.6,36.6,28.61,29.52,-8.33,-22.01,27.0,1.1568002446E10,0,0.0], +[1685462400000,345031667,29.51,30.1,25.27,25.78,-3.74,-12.67,23.04,9.442101926E9,0,0.0], +[1688054400000,1217980960,25.6,42.19,24.75,36.77,10.99,42.63,81.24,4.2515733378E10,0,0.0], +[1688572800000,427585117,37.5,47.3,37.06,46.62,9.85,26.79,28.37,1.8368604411E10,0,0.0]]},"error_code":0,"error_description":""} + +*/ +// 鍗曚釜鑲$エ鐨� JSON鏍煎紡澶勭悊 +void GetStockList::getStockOne(QByteArray &buffer) +{ + QJsonDocument jd = QJsonDocument::fromJson(buffer); + if(jd.isObject()){ + QJsonObject jObject = jd.object(); + QJsonArray jArr = jObject.value("data").toObject().value("item").toArray(); // 閫氳繃閿�煎鍙栧�� + int cnt = jArr.count(); + qDebug()<<"鏁扮粍size:"<<cnt; + QString symbol = jObject.value("data").toObject().value("symbol").toString(); + QString code = symbol; // 鑲$エ浠e彿 + QLineSeries *series = new QLineSeries; // QLineSeries 鎶樼嚎鐨勭被锛孮SplineSeries 涓哄渾婊戞洸绾跨被 + series->setName(symbol); // 璁剧疆鎶樼嚎鍚嶅瓧 + //series->setColor(QColor(255,0,0)); // 璁剧疆棰滆壊 r,g,b 绾㈢豢钃濅笁鍘熻壊锛岄殢鎰忕粍鍚� + QSplineSeries *sp = new QSplineSeries; + sp->setName(symbol); + QSplineSeries *spVolume = new QSplineSeries; + spVolume->setName(symbol.append("--volume")); + QSplineSeries *spAmount = new QSplineSeries; + spVolume->setName(symbol.append("--amount")); + + int ma10_20_flag = 0; // 鏍囪MA閲戝弶銆佹鍙夌殑鎯呭喌 0:鍒濆鍊硷紝1锛氶噾鍙夛紝-1锛氭鍙� + long long oldVolume = 0; // MACD: 鑰佺殑鎴愪氦閲� + int macd_buy = 0; // 涔板叆鏍囧織 + double buy_price = 0; // 涔板叆浠锋牸 + double rate_all = 0; // 鏀剁泭鐧惧垎姣� + for(int i=0;i<cnt;++i){ + qint64 timestamp = jArr.at(i).toArray().at(0).toVariant().toLongLong(); + double close = jArr.at(i).toArray().at(5).toVariant().toDouble(); + long long volume = jArr.at(i).toArray().at(1).toVariant().toLongLong()/100; + + long long amount = jArr.at(i).toArray().at(9).toVariant().toLongLong()/100000000; + QString curDateTime = QDateTime::fromMSecsSinceEpoch(timestamp).toString("yyyy-MM-dd"); + //qDebug()<<curDateTime<<close<<volume<<amount; + series->append(timestamp,close); // 鎶樼嚎鏁版嵁娣诲姞 + sp->append(timestamp,close); // 鏇茬嚎鏁版嵁娣诲姞 + spVolume->append(timestamp,volume); + spAmount->append(timestamp,amount); + if(m_menuIndex == 2){ + // MA ma10浜a20 閲戝弶锛宮a10浜a60 姝诲弶 + double ma5 = jArr.at(i).toArray().at(12).toVariant().toDouble(); + double ma10 = jArr.at(i).toArray().at(13).toVariant().toDouble(); + double ma20 = jArr.at(i).toArray().at(14).toVariant().toDouble(); + double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); + //qDebug()<<"MA5-10-20-30"<<ma5<<ma10<<ma20<<ma30; + if(i>0){ + double ma5_old = jArr.at(i-1).toArray().at(12).toVariant().toDouble(); + double ma10_old = jArr.at(i-1).toArray().at(13).toVariant().toDouble(); + double ma20_old = jArr.at(i-1).toArray().at(14).toVariant().toDouble(); + double ma30_old = jArr.at(i-1).toArray().at(15).toVariant().toDouble(); + +// if(ma5_old > ma20_old && ma5 <= ma20){ +// // 姝诲弶 +// qDebug()<<"MA5-20姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close; +// }else if(ma5_old < ma20_old && ma5 >= ma20){ +// // 閲戝弶 +// qDebug()<<"MA5-20閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close; +// } + + if(ma10_old > ma20_old && ma10 <= ma20){ + // 姝诲弶 + qDebug()<<"MA10-20姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close; + if(buy_price == 0) buy_price = close; + double tmp_rate = (close-buy_price)/buy_price; + rate_all += tmp_rate; + + QString info = QString("<font size=8 color=green> %3 %6 MA10-20姝诲弶:%1 浠锋牸:%2 鐩堝埄姣�:%4 鎬荤泩鍒�:%5</font>").arg(curDateTime).arg(close).arg(code) + .arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)).arg(m_codeNames[code]); + emit sendInfoMess(info); + //buy_price = close; // 姝诲弶涔板叆鐨勬儏鍐� + }else if(ma10_old < ma20_old && ma10 >= ma20){ + // 閲戝弶 + buy_price = close; // 閲戝弶涔板叆鐨勬儏鍐� + + qDebug()<<"MA10-20閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close; +// if(buy_price == 0) buy_price = close; +// double tmp_rate = (close-buy_price)/buy_price; +// rate_all += tmp_rate; + QString info = QString("<font size=8 color=red> %3 %4 MA10-20閲戝弶:%1 浠锋牸:%2 </font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]); + //.arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)); + emit sendInfoMess(info); + + } + } + }else if(m_menuIndex == 3){ + // MACD绛栫暐 缁撳悎鎴愪氦閲忔潵鍒ゆ柇浼氭洿濂�:涔板叆鐐规垚浜ら噺缁х画鏀惧ぇ鍒欐寔鏈夛紝缂╁皬鍒欑鍦� + double dea = jArr.at(i).toArray().at(12).toVariant().toDouble(); + double dif = jArr.at(i).toArray().at(13).toVariant().toDouble(); + double macd = jArr.at(i).toArray().at(14).toVariant().toDouble(); + + if(macd_buy == 1 && oldVolume > volume){ + QString info = QString("<font size=8 color=green> %4 MACD 鎴愪氦閲忓垵娆¤椤� 绂诲満1:%1 浠锋牸:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + emit sendInfoMess(info); + macd_buy = 0; + oldVolume = 0; + + } + if(i > 0){ + double dea_old = jArr.at(i-1).toArray().at(12).toVariant().toDouble(); + double dif_old = jArr.at(i-1).toArray().at(13).toVariant().toDouble(); + double macd_old = jArr.at(i-1).toArray().at(14).toVariant().toDouble(); + + if(dif_old > dea_old && dif <= dea){ + // 姝诲弶 + qDebug()<<"MACD姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close <<"MACD="<<macd ; + QString info=QString("<font size=8 color=green> %4 MACD姝诲弶:%1 浠锋牸:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + emit sendInfoMess(info); + }else if(dif_old < dea_old && dif >= dea){ + // 閲戝弶 + qDebug()<<"MACD閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close <<"MACD="<<macd <<"寤鸿璁板綍褰撳墠閲戝弶MACD鐨勫�硷紝鑻ュ悗闈㈡湁浣庝簬姝ゅ�硷紝鍏虫敞绂诲満鎻愮ず"; + QString info=QString("<font size=9 color=red> %4 MACD閲戝弶:%1 浠锋牸:%2 MACD=%3 寤鸿璁板綍褰撳墠閲戝弶MACD鐨勫�硷紝鑻ュ悗闈㈡湁浣庝簬姝ゅ�硷紝鍏虫敞绂诲満鎻愮ず </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + emit sendInfoMess(info); + + macd_buy = 1; + oldVolume = volume; + } + } + } + + + } + if(m_menuIndex == 0){ + // 绛栫暐鍒嗘瀽 鍙兘閫変竴绉嶇嚎褰㈡暟鎹� + //emit sendChartData(series); // 鍙戦�佹姌绾挎暟鎹� + emit sendChartData(sp); // 鍙戦�佹洸绾挎暟鎹� 鏀剁洏浠� + emit sendChartData(spVolume); // 鍙戦�佷氦鏄撻噺鏇茬嚎 + emit sendChartData(spAmount); // 浜ゆ槗棰濇洸绾� + }else if(m_menuIndex == 1){ + // 鏈�鏂颁环鏍� + }else if(m_menuIndex == 2){ + // MA绛栫暐 + }else if(m_menuIndex == 3){ + // MACD绛栫暐 + } + } +} + + +/* 鑾峰彇琛屼笟淇℃伅 + * + * {"data":{"industries":[{"encode":"S1101","name":"绉嶆涓�","pinyin":"zzy"}, + * {"encode":"S1102","name":"娓斾笟","pinyin":"yy"},{"encode":"S1103","name":"鏋椾笟","pinyin":"ly"}, + * {"encode":"S1104","name":"楗叉枡","pinyin":"sl"},{"encode":"S1105","name":"鍐滀骇鍝佸姞宸�","pinyin":"ncpjg"}, + * {"encode":"S1107","name":"鍏绘畺涓�","pinyin":"yzy"},{"encode":"S1108","name":"鍔ㄧ墿淇濆仴","pinyin":"dwbj"}, + * {"encode":"S1109","name":"鍐滀笟缁煎悎","pinyin":"nyzh"},{"encode":"S2202","name":"鍖栧鍘熸枡","pinyin":"hxyl"}, + * {"encode":"S2203","name":"鍖栧鍒跺搧","pinyin":"hxzp"},{"encode":"S2204","name":"鍖栧绾ょ淮","pinyin":"hxxw" + * */ + +void GetStockList::getIndustryInfo(QByteArray &buffer) +{ + + QJsonDocument jd = QJsonDocument::fromJson(buffer); + if(jd.isObject()){ + QJsonObject jObject = jd.object(); + QJsonArray jArr = jObject.value("data").toObject().value("industries").toArray(); // 閫氳繃閿�煎鍙栧�� + int cnt = jArr.count(); + for(int i=0;i<cnt;++i){ + QJsonObject tmpObj = jArr[i].toObject(); + QString encode = tmpObj.value("encode").toString(); + QString name = tmpObj.value("name").toString(); + qDebug()<<encode<<name; + m_industryInfo[encode] = name; // 娣诲姞鍒拌涓歮ap閲岄潰鍘讳繚瀛� + + // 鎺ョ潃閬嶅巻鎵�鏈夎涓氭嫢鏈夌殑瀵瑰簲鑲$エ + m_curIndustry = encode; // 璁剧疆褰撳墠琛屼笟 + QString url = QString("https://stock.xueqiu.com/v5/stock/screener/quote/list.json?page=1&size=100&order=desc&order_by=percent&market=CN&ind_code=%1").arg(encode); + m_request.setUrl(url); + m_manager.get(m_request); + } + + } +} + + +/* + +{"data":{"count":21,"list":[{"symbol":"SZ000995","net_profit_cagr":92.61556393554986, +"north_net_inflow":null,"ps":19.4318,"type":11,"percent":1.86,"has_follow":false, +"tick_size":0.01,"pb_ttm":20.688,"float_shares":177408000,"current":16.95, +"amplitude":8.65,"pcf":534.2042,"current_year_percent":2.73,"float_market_capital":3.0070656E9, +"north_net_inflow_time":null,"market_capital":3.0070656E9,"dividend_yield":null,"lot_size":100, +"roe_ttm":2.8913250918407045,"total_percent":90.46,"percent5m":0.53,"income_cagr":19.383233238212405, +"amount":5.4679898205E8,"chg":0.31,"issue_date_ts":965577600000,"eps":0.02,"main_net_inflows":-9917325.0, +"volume":32611719,"volume_ratio":1.31,"pb":20.688,"followers":46602,"turnover_rate":18.38,"mapping_quote_current":null, +"first_percent":99.74,"name":"鐨囧彴閰掍笟","pe_ttm":731.576,"dual_counter_mapping_symbol":null,"total_shares":177408000,"limitup_days":0}, + +*/ +void GetStockList::getStockByIndustry(QByteArray &buffer,QString industryCode) +{ + // 閫氳繃琛屼笟鑾峰彇鑲$エ淇℃伅 + static int sAllCnt = 0; + QJsonDocument jd = QJsonDocument::fromJson(buffer); + if(jd.isObject()){ + QJsonObject jObject = jd.object(); + QJsonArray jArr = jObject.value("data").toObject().value("list").toArray(); // 閫氳繃閿�煎鍙栧�� + int allCnt = jObject.value("data").toObject().value("count").toInt(); + sAllCnt += allCnt; + int cnt = jArr.count(); + qDebug()<<"琛屼笟:"<<industryCode<<m_industryInfo[industryCode]<<"allCnt:"<<allCnt<<"pageCnt:"<<cnt; + for(int i=0;i<cnt;++i){ + QString symbol = jArr[i].toObject().value("symbol").toString(); + QString name = jArr[i].toObject().value("name").toString(); + m_codeAndIndustry[symbol].append(m_industryInfo[industryCode]); // 娣诲姞琛屼笟鍒板搴攎ap + qDebug()<<"鑲$エ:"<<symbol<<name<<industryCode; + } + } + qDebug()<<"琛屼笟缁熻鍒扮殑鑲$エsAllCnt"<<sAllCnt; +} + +void GetStockList::on_pushButton_get_clicked() +{ + qDebug()<<"寮�濮嬭姹�"; + m_manager.get(m_request); + qDebug()<<"璇锋眰涓�..."; +} + +void GetStockList::showAplyData(QNetworkReply *reply) +{ + qDebug()<<"鏀跺埌鍝嶅簲"; + // 灏嗗搷搴旂殑鏁版嵁锛屼竴鎶婅鍙栧畬锛屾斁鍒板瓧鑺傛暟缁勯噷闈㈡潵澶勭悊 + QByteArray buffer = reply->readAll(); + + // 灏嗘暟鎹啓鍒版枃浠朵腑锛屾柟渚胯瀵熸暟鎹唴瀹� + QFile file("data.txt"); + file.open(QIODevice::ReadWrite | QIODevice::Text); + QTextStream out(&file); + out << buffer << endl; + file.close(); + + // 涓嬮潰浣跨敤JSON杩涜鏁版嵁澶勭悊 + if(reply->url() == QUrl("https://xueqiu.com/")){ + qDebug()<<"鍙戠幇棣栭〉url"; + qDebug()<<buffer; + + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/chart/kline.json") != -1){ + qDebug()<<"鏌ョ湅涓偂鎯呭喌:"; + getStockOne(buffer); + + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/screener/quote/list.json?page=1&size=100&order=desc&order_by=percent&market=CN&ind_code") != -1){ + qDebug()<<"鏍规嵁琛屼笟鑾峰彇鑲$エ淇℃伅"<<reply->url(); + QString industryCode = reply->url().toString().split("=").back(); + qDebug()<<"琛屼笟淇℃伅:"<<industryCode; + getStockByIndustry(buffer,industryCode); + + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/screener/quote/list.json") != -1){ + qDebug()<<"鑾峰彇鎵�鏈夋勃娣辫偂绁� 鍙互骞叉椿浜�"; + getStockAllCode(buffer); + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/screener/industries.json") != -1){ + qDebug()<<"鑾峰彇琛屼笟淇℃伅"; + getIndustryInfo(buffer); + } + + reply->deleteLater(); +} + +void GetStockList::on_pushButton_get_2_clicked() +{ + + m_model->setRowCount(0); // 娓呴櫎褰撳墠妯″瀷涓殑鍐呭 + + // 鏈�濂借緭鍑轰竴涓嬫墍鏈夎偂绁ㄥ強琛屼笟淇℃伅 + qDebug()<<"涓�鎶婅兘鐪嬪埌鐨勮偂绁ㄦ暟閲�"<<m_codeAndIndustry.size(); + for(auto it = m_codeAndIndustry.begin();it != m_codeAndIndustry.end();++it){ + qDebug()<<it.key()<<"鎵�灞炶涓氭暟閲�:"<<it.value().size(); + for(auto e:it.value()){ + qDebug()<<e; + } + } + +// // 璁剧疆瑕佺埇鍙栫殑鏍稿績缃戝潃 +// m_request.setUrl(QUrl("https://stock.xueqiu.com/v5/stock/screener/quote/list.json?page=1&size=5000&order=desc&orderby=amount&order_by=amount&market=CN&type=sh_sz")); +// // 鎵цget璇锋眰锛屽幓鎷跨綉鍧�瀵瑰簲鐨勬暟鎹� +// m_manager.get(m_request); +// qDebug()<<"req ok"; + + // 2024-9-21 淇敼鏂扮増锛屽畼鏂瑰仛浜嗘暟閲忛檺鍒讹紝鍙互鍗曢〉100鏉★紝浣嗘槸涓嶈兘涓�鎶婂彇鎵�鏈変簡 + //m_request.setHeader(QNetworkRequest::CookieHeader,m_cookie); + //m_request.setHeader(QNetworkRequest::SetCookieHeader,m_cookie); + + int allCnt = 6000; + int singlePageCnt = 90; // 鍗曢〉鑲$エ鐨勮偂绁ㄦ暟閲� + int pages = allCnt/singlePageCnt; + + qDebug()<<"璇锋眰鑲$エ浠e彿:"<<QTime::currentTime(); + for(int i=1;i<=pages;++i){ + QString url = QString("https://stock.xueqiu.com/v5/stock/screener/quote/list.json?page=%1&size=%2&order=desc&orderby=amount&order_by=amount&market=CN&type=sh_sz").arg(i).arg(singlePageCnt); + m_request.setUrl(QUrl(url)); + m_manager.get(m_request); + } + qDebug()<<"OK--瀹屾垚璇锋眰鑲$エ浠e彿:"<<QTime::currentTime(); + + // 浣跨敤瀹氭椂鍣ㄦ潵瀹氭椂鑾峰彇 +// m_getCodeTimer->start(10); + +} + +void GetStockList::showMenu() +{ + qDebug()<<"鍙冲嚮鑿滃崟"; + m_menu->popup(QCursor::pos()); // 鍦ㄩ紶鏍囧厜鏍囩殑浣嶇疆寮瑰嚭鑿滃崟 +} + +void GetStockList::policySlot() +{ + qDebug()<<"绛栫暐鏌ョ湅"; + if(m_model->rowCount() == 0)return; // 闃叉寮傚父 + + int row = ui->tableView->currentIndex().row(); // 鍙栧嚭鑿滃崟鎵�鍦ㄧ殑琛屽彿 + QString symbol = m_model->item(row,1)->text(); // 鍙栧綋鍓嶈鎵�鍦ㄧ殑鑲$エ浠e彿 + qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 鍙栧綋鍓嶆椂闂存埑 + m_numsCnt = 30; // 杩欓噷鏄缃幏鍙栧崟涓偂绁ㄧ殑鏁版嵁閲� + QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=week&type=before&count=-%3&indicator=kline").arg(symbol).arg(begin).arg(m_numsCnt); + qDebug()<<urlStr; + qDebug()<<"褰撳墠鑲$エ:"<<symbol<<m_model->item(row,0)->text(); + // 涓嬩竴姝ュ氨鏄牴鎹畊rl璇锋眰鍒扮殑鏁版嵁锛岃繘琛屽垎鏋� + m_menuIndex = 0; // 绗竴涓彍鍗� + m_request.setUrl(QUrl(urlStr)); // 璁剧疆鏂扮殑缃戝潃 + m_manager.get(m_request); // 鎵撳紑缃戝潃锛屾嬁鏁版嵁 +} + +void GetStockList::priceSlot() +{ + qDebug()<<"鏈�鏂颁环鏍�"; + if(m_model->rowCount() == 0)return; + int row = ui->tableView->currentIndex().row(); + QString symbol = m_model->item(row,1)->text(); // 鍙栧綋鍓嶈鎵�鍦ㄧ殑鑲$エ浠e彿 + qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 鍙栧綋鍓嶆椂闂存埑 + int numsCnt = 20; + QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=day&type=before&count=-%3&indicator=kline").arg(symbol).arg(begin).arg(numsCnt); + qDebug()<<urlStr; + // 涓嬩竴姝ュ氨鏄牴鎹畊rl璇锋眰鍒扮殑鏁版嵁锛岃繘琛屽垎鏋� + m_menuIndex = 1; // 绗簩涓彍鍗曢」 + m_request.setUrl(QUrl(urlStr)); + m_manager.get(m_request); + +} + +void GetStockList::maPolicySlot() +{ + qDebug()<<"鎵цMA绛栫暐"; + emit sendInfoMess("<font size=12 color=pink>鎵цMA绛栫暐 </font>"); + int curRow = ui->tableView->currentIndex().row(); + QString symbol = m_model->item(curRow,1)->text(); + qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 鍙栧綋鍓嶆椂闂存埑 + int numsCnt = 300; + QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,ma").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); + qDebug()<<urlStr; + qDebug()<<"褰撳墠鑲$エ:"<<symbol<<m_model->item(curRow,0)->text(); + // 涓嬩竴姝ュ氨鏄牴鎹畊rl璇锋眰鍒扮殑鏁版嵁锛岃繘琛屽垎鏋� + m_menuIndex = 2; // 绗笁涓彍鍗曢」 + m_request.setUrl(QUrl(urlStr)); + m_manager.get(m_request); + +} + +void GetStockList::maTest100Slot() +{ + for(int i=0;i<m_model->rowCount() && i < m_maTestNum;++i){ + ui->tableView->setCurrentIndex(m_model->index(i,0)); // 璁剧疆褰撳墠琛ㄦ牸绱㈠紩锛屼富瑕佹槸涓轰簡璁剧疆琛� + maPolicySlot(); // 璋冪敤MA绛栫暐鍘诲洖娴� + } +} + +void GetStockList::macdPolicySlot() +{ + qDebug()<<"鎵цMACD绛栫暐"; + emit sendInfoMess("<font size=12 color=pink>鎵цMACD绛栫暐 </font>"); + int curRow = ui->tableView->currentIndex().row(); + QString symbol = m_model->item(curRow,1)->text(); + qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 鍙栧綋鍓嶆椂闂存埑 + int numsCnt = 300; + QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=week&type=before&count=-%3&indicator=kline,macd").arg(symbol).arg(begin).arg(numsCnt); + qDebug()<<urlStr; + qDebug()<<"褰撳墠鑲$エ:"<<symbol<<m_model->item(curRow,0)->text(); + // 涓嬩竴姝ュ氨鏄牴鎹畊rl璇锋眰鍒扮殑鏁版嵁锛岃繘琛屽垎鏋� + m_menuIndex = 3; // 绗洓涓彍鍗曢」 + m_request.setUrl(QUrl(urlStr)); + m_manager.get(m_request); + +} + +void GetStockList::getCodeSlot() +{ + // 2024-9-21 淇敼鏂扮増锛屽畼鏂瑰仛浜嗘暟閲忛檺鍒讹紝鍙互鍗曢〉100鏉★紝浣嗘槸涓嶈兘涓�鎶婂彇鎵�鏈変簡 + static int allCnt = 6000; + static int pages = allCnt/100; + static int i=1; + + QString url = QString("https://stock.xueqiu.com/v5/stock/screener/quote/list.json?page=%1&size=100&order=desc&orderby=amount&order_by=amount&market=CN&type=sh_sz").arg(i); + m_request.setUrl(QUrl(url)); + m_manager.get(m_request); + + ++i; + if(i > pages){ + i=1; + m_getCodeTimer->stop(); // 鍋滄帀瀹氭椂鍣� + } + +} + +void GetStockList::on_pushButton_industry_clicked() +{ + // 鑾峰彇琛屼笟淇℃伅锛岃兘鎷垮埌 琛屼笟浠g爜鍜屽悕瀛楋紝绠�鍐欑瓑 + QString url = "https://stock.xueqiu.com/v5/stock/screener/industries.json?category=cn"; + m_request.setUrl(QUrl(url)); + m_manager.get(m_request); + +} diff --git a/getstocklist.h b/getstocklist.h new file mode 100644 index 0000000..8499a1d --- /dev/null +++ b/getstocklist.h @@ -0,0 +1,85 @@ +锘�#ifndef GETSTOCKLIST_H +#define GETSTOCKLIST_H + +#include <QMainWindow> +#include <QNetworkAccessManager> +#include <QNetworkCookie> +#include <QNetworkRequest> +#include <QNetworkReply> +#include <QStandardItemModel> +#include <QMenu> +#include <QLineSeries> // 鎶樼嚎绫� +#include <QSplineSeries> // 鏇茬嚎绫� +#include <QTimer> + +QT_CHARTS_USE_NAMESPACE // 鍛藉悕绌洪棿寰椾娇鐢ㄨ捣鏉ワ紝瑕佷笉鐒剁被浼氭嬁涓嶅埌 + + +/* + * 鍏充簬SSL鐨勫鐞嗭紝鐢变簬瑕佽姹� https鐨勯摼鎺ワ紝闇�瑕佸皢缂栬瘧鍣ㄧ洰褰曚笅鐨勪袱涓猟ll鍔ㄦ�佸簱鎷疯礉鍒板搴旂紪璇戝櫒鐨刡in鐩綍涓� + * 灏唋ibeay32.dll 鍜� ssleay32.dll 涓や釜鏂囦欢澶嶅埗鍒板搴旂殑鍖哄煙 + * 渚嬪浠庣紪璇戝櫒鐨刼pt\bin鍘熷鐩綍锛�...\Qt5.9.4\Tools\mingw530_32\opt\bin 鎵句釜杩�2涓猟ll + * 鎷疯礉鍒扮紪璇戝櫒鐨刡in鐩綍涓�: ...\Qt5.9.4\Tools\mingw530_32\bin + */ +namespace Ui { +class GetStockList; +} + +class GetStockList : public QMainWindow +{ + Q_OBJECT + +public: + explicit GetStockList(QWidget *parent = 0); + ~GetStockList(); + void getStockAllCode(QByteArray &buffer); // 鑾峰彇鎵�鏈夋勃娣辫偂绁ㄧ殑淇℃伅 + void getStockOne(QByteArray &buffer); // 鑾峰彇鍗曞彧鑲$エ鐨勫鐞� + void getIndustryInfo(QByteArray &buffer); // 鑾峰彇琛屼笟淇℃伅 + void getStockByIndustry(QByteArray &buffer,QString industryCode); // 閫氳繃琛屼笟鑾峰彇鑲$エ + +signals: + void sendChartData(QLineSeries*); // 鎶樼嚎 + void sendChartData(QSplineSeries*); // 鏇茬嚎 + void sendInfoMess(QString); // 鍙戦�佹秷鎭彁绀� + +private slots: + void on_pushButton_get_clicked(); + void showAplyData(QNetworkReply *reply); // 鐢ㄦ潵鍝嶅簲璇锋眰鐨勫洖浼犳暟鎹殑妲藉嚱鏁� + + void on_pushButton_get_2_clicked(); // 鑾峰彇娌繁鑲″競鏁版嵁鐨勬寜閽Ы鍑芥暟 + void showMenu(); + void policySlot(); + void priceSlot(); + void maPolicySlot(); // MA绛栫暐妲� + void maTest100Slot(); // MA绛栫暐鍥炴祴鍓�100鍚嶆Ы + void macdPolicySlot(); // MACD绛栫暐妲� + + void getCodeSlot(); // 鑾峰彇鑲$エ浠e彿鐨勫畾鏃跺櫒鐨勬Ы + + void on_pushButton_industry_clicked(); + +private: + Ui::GetStockList *ui; + // 杩�2涓敤浜庣埇鍙栨暟鎹殑 + QNetworkRequest m_request; // 鐢ㄤ簬绠$悊璇锋眰澶寸殑 + QString m_cookie; // 缂撳瓨 + QNetworkAccessManager m_manager; // 鐢ㄤ簬绠$悊http璇锋眰鍙婂搷搴旂殑 + + // 涓嬮潰杩欏嚑涓敤浜庢樉寮忕埇鍒扮殑鑲$エ鏁版嵁 + QStandardItemModel *m_model; // 鏍囧噯椤规ā鍨嬶紝鐢ㄦ潵瀛樺偍鏁版嵁鐨勶紝灏嗘ā鍨嬪拰瑙嗗浘杩涜浜嗗垎绂� + QMenu *m_menu; // 鑿滃崟鎸囬拡锛岀敤鏉ュ鐞嗗彸鍑昏彍鍗曠殑 + int m_numsCnt; // 鍗曚釜鑲$エ鐨勬暟鎹鏁� + int m_menuIndex; // 閽堝鍗曚釜鑲$エ闇�瑕佸垽鏂槸鍝釜鎿嶄綔锛岀敤鏉ヨ褰曚笅鏍囩殑 + + QTimer *m_getCodeTimer; // 鑾峰彇鑲$エ浠e彿鐨勫畾鏃跺櫒 + QMap<QString,QString> m_codeNames; // 鑲$エ浠e彿鍜屽悕瀛� + + QMap<QString,QString> m_industryInfo; // 琛屼笟浠g爜鍜岃涓氬悕瀛� + QMap<QString,QVector<QString>> m_codeAndIndustry; // 鑲$エ浠e彿鍙婂搴旂殑琛屼笟浠g爜 + QString m_curIndustry; // 褰撳墠琛屼笟 + QString m_dateType; // 鏃ユ湡绫诲瀷锛歞ay week month year + int m_maTestNum; // ma绛栫暐鍥炴祴鏁伴噺 + +}; + +#endif // GETSTOCKLIST_H diff --git a/getstocklist.ui b/getstocklist.ui new file mode 100644 index 0000000..cec3bef --- /dev/null +++ b/getstocklist.ui @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>GetStockList</class> + <widget class="QMainWindow" name="GetStockList"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="pushButton_get"> + <property name="text"> + <string>鑾峰彇棣栭〉</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_industry"> + <property name="text"> + <string>鑾峰彇琛屼笟瀵瑰簲鑲$エ</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_get_2"> + <property name="text"> + <string>鑾峰彇娌繁鑲″競鑲$エ浠e彿</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0"> + <widget class="QTableView" name="tableView"/> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>26</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/leadingcompany.cpp b/leadingcompany.cpp new file mode 100644 index 0000000..c3b148f --- /dev/null +++ b/leadingcompany.cpp @@ -0,0 +1,46 @@ +锘�#include "leadingcompany.h" +#include "ui_leadingcompany.h" + +LeadingCompany::LeadingCompany(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::LeadingCompany) +{ + ui->setupUi(this); + ui->menubar->hide(); + ui->statusbar->hide(); + + m_industryLeaderModel = new QStandardItemModel(this); + m_industryLeaderModel->setColumnCount(6); + + m_trendLeaderModel = new QStandardItemModel(this); + m_trendLeaderModel->setColumnCount(7); + + ui->tableView_industry->setModel(m_industryLeaderModel); + ui->tableView_trend->setModel(m_trendLeaderModel); + + QStringList industryLabels; + industryLabels<<"鍚嶅瓧"<<"浠e彿"<<"琛屼笟"<<"绛夌骇"<<"甯傚��"<<"鏀剁洏浠�"; + m_industryLeaderModel->setHorizontalHeaderLabels(industryLabels); + + QStringList trendLabels; + trendLabels<<"鍚嶅瓧"<<"浠e彿"<<"瓒嬪娍鏂瑰悜"<<"琛屼笟"<<"绛夌骇"<<"甯傚��"<<"鏀剁洏浠�"; + m_trendLeaderModel->setHorizontalHeaderLabels(trendLabels); + +} + +LeadingCompany::~LeadingCompany() +{ + delete ui; +} + +void LeadingCompany::on_pushButton_add_clicked() +{ + QString name = ui->lineEdit_stockName->text(); + QString code = ui->lineEdit_stockCode->text(); + QString type = ui->comboBox->currentText(); + + // 娣诲姞鍒版暟鎹簱 + + // 娣诲姞鍒版枃鏈祻瑙堝櫒鏉ユ彁绀烘秷鎭� + ui->textBrowser->append(QString("%1 %2 %3").arg(type).arg(name).arg(code)); +} diff --git a/leadingcompany.h b/leadingcompany.h new file mode 100644 index 0000000..15eb8b5 --- /dev/null +++ b/leadingcompany.h @@ -0,0 +1,29 @@ +锘�#ifndef LEADINGCOMPANY_H +#define LEADINGCOMPANY_H + +#include <QMainWindow> +#include <QStandardItemModel> + +namespace Ui { +class LeadingCompany; +} + +class LeadingCompany : public QMainWindow +{ + Q_OBJECT + +public: + explicit LeadingCompany(QWidget *parent = 0); + ~LeadingCompany(); + +private slots: + void on_pushButton_add_clicked(); + +private: + Ui::LeadingCompany *ui; + + QStandardItemModel *m_industryLeaderModel; // 琛屼笟榫欏ご + QStandardItemModel *m_trendLeaderModel; // 瓒嬪娍榫欏ご +}; + +#endif // LEADINGCOMPANY_H diff --git a/leadingcompany.ui b/leadingcompany.ui new file mode 100644 index 0000000..10a6ea8 --- /dev/null +++ b/leadingcompany.ui @@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>LeadingCompany</class> + <widget class="QMainWindow" name="LeadingCompany"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>840</width> + <height>668</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>2</number> + </property> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>琛屼笟榫欏ご</string> + </attribute> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QTableView" name="tableView_industry"/> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_2"> + <attribute name="title"> + <string>瓒嬪娍榫欏ご</string> + </attribute> + <layout class="QGridLayout" name="gridLayout_3"> + <item row="0" column="0"> + <widget class="QTableView" name="tableView_trend"/> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_3"> + <attribute name="title"> + <string>娣诲姞榫欏ご</string> + </attribute> + <layout class="QGridLayout" name="gridLayout_4"> + <item row="0" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>榫欏ご绫诲瀷</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="comboBox"> + <item> + <property name="text"> + <string>琛屼笟榫欏ご</string> + </property> + </item> + <item> + <property name="text"> + <string>瓒嬪娍榫欏ご</string> + </property> + </item> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEdit_stockName"> + <property name="placeholderText"> + <string>杈撳叆鑲$エ鍚嶅瓧</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEdit_stockCode"> + <property name="placeholderText"> + <string>杈撳叆鑲$エ浠e彿</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_add"> + <property name="text"> + <string>娣诲姞</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0"> + <widget class="QTextBrowser" name="textBrowser"/> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>840</width> + <height>26</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..10f11bd --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "clientmainwindow.h" +#include <QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ClientMainWindow w; + w.show(); + + return a.exec(); +} diff --git a/showinfomessage.cpp b/showinfomessage.cpp new file mode 100644 index 0000000..5b7f01c --- /dev/null +++ b/showinfomessage.cpp @@ -0,0 +1,19 @@ +锘�#include "showinfomessage.h" +#include "ui_showinfomessage.h" + +ShowInfoMessage::ShowInfoMessage(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::ShowInfoMessage) +{ + ui->setupUi(this); +} + +ShowInfoMessage::~ShowInfoMessage() +{ + delete ui; +} + +void ShowInfoMessage::showInfo(QString info) +{ + ui->textBrowser->append(info); +} diff --git a/showinfomessage.h b/showinfomessage.h new file mode 100644 index 0000000..36cdf58 --- /dev/null +++ b/showinfomessage.h @@ -0,0 +1,24 @@ +锘�#ifndef SHOWINFOMESSAGE_H +#define SHOWINFOMESSAGE_H + +#include <QMainWindow> + +namespace Ui { +class ShowInfoMessage; +} + +class ShowInfoMessage : public QMainWindow +{ + Q_OBJECT + +public: + explicit ShowInfoMessage(QWidget *parent = 0); + ~ShowInfoMessage(); + +public slots: + void showInfo(QString info); +private: + Ui::ShowInfoMessage *ui; +}; + +#endif // SHOWINFOMESSAGE_H diff --git a/showinfomessage.ui b/showinfomessage.ui new file mode 100644 index 0000000..d2b3ca9 --- /dev/null +++ b/showinfomessage.ui @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ShowInfoMessage</class> + <widget class="QMainWindow" name="ShowInfoMessage"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QTextBrowser" name="textBrowser"/> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>26</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/stock_plan.pro b/stock_plan.pro new file mode 100644 index 0000000..339ec9f --- /dev/null +++ b/stock_plan.pro @@ -0,0 +1,46 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2023-07-06T21:17:32 +# +#------------------------------------------------- + +QT += core gui network charts + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = stock_plan +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + clientmainwindow.cpp \ + getstocklist.cpp \ + stockpolicy.cpp \ + leadingcompany.cpp \ + showinfomessage.cpp + +HEADERS += \ + clientmainwindow.h \ + getstocklist.h \ + stockpolicy.h \ + leadingcompany.h \ + showinfomessage.h + +FORMS += \ + clientmainwindow.ui \ + getstocklist.ui \ + stockpolicy.ui \ + leadingcompany.ui \ + showinfomessage.ui diff --git a/stockpolicy.cpp b/stockpolicy.cpp new file mode 100644 index 0000000..b84e4f4 --- /dev/null +++ b/stockpolicy.cpp @@ -0,0 +1,95 @@ +#include "stockpolicy.h" +#include "ui_stockpolicy.h" +#include <QDebug> +#include <QLegendMarker> + + + + +StockPolicy::StockPolicy(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::StockPolicy) +{ + ui->setupUi(this); + initUi(); +} + +StockPolicy::~StockPolicy() +{ + delete ui; +} + +void StockPolicy::initUi() +{ + + m_chart = new QChart; + m_chart->setTitle("瓒嬪娍鏌ョ湅"); + m_chart->setBackgroundBrush(QColor(255,255,255)); // 鐢ㄤ簬璁剧疆鑳屾櫙鑹茬殑 QColor(10,10,10) r,g,b 绾㈢豢钃�3鍘熻壊 + QLineSeries *series = new QLineSeries; // 鐢ㄤ簬瀛樻斁鏁版嵁鐨勭郴鍒楋紝鐩稿綋浜庡瓨浜哫Y瀵瑰簲鏁版嵁鐨勫鍣� + series->setName("绀轰緥鍥�"); + + series->append(1686240000000,17.63); // X Y鐨勫�� + series->append(1686844800000,19.31); + series->append(1687276800000,30.11); + series->append(1688054400000,19.31); + series->append(1688659200000,50.81); + m_chart->addSeries(series); + + m_dtAx = new QDateTimeAxis; // X杞达紝鏃堕棿杞� + m_dtAx->setFormat("yyyy-MM-dd"); // 璁剧疆鏃堕棿鏍煎紡 + m_dtAx->setTitleText("鏃堕棿"); + m_dtAx->setTickCount(10); // 璁剧疆缃戞牸鏁� + m_chart->setAxisX(m_dtAx,series); // 璁剧疆 X杞翠负鏃堕棿杞淬�佹暟鎹� + + m_axisY = new QValueAxis; // Y杞� + m_axisY->setTickCount(10); // 璁剧疆鏍兼暟 + m_axisY->setRange(0,1500); // 璁剧疆Y鍊肩殑鑼冨洿 + m_chart->setAxisY(m_axisY,series); // 璁剧疆 Y杞翠负鏁版嵁杞淬�佹暟鎹� + + setLastMarkerShowAndAlpha(); // 璁剧疆褰撳墠鏈�鍚庝竴涓爣璁版洸绾垮拰鏍囩鐨勬樉绀哄強閫忔槑搴︽儏鍐� + + m_chartView = new QChartView(m_chart); + // 妗嗛�夋斁澶э紝鍙抽敭缂╁皬 + m_chartView->setRubberBand(QChartView::HorizontalRubberBand); // 璁剧疆榧犳爣宸﹀嚮妗嗛�夋斁澶э紝鍙冲嚮缂╁皬 + m_chartView->setRenderHint(QPainter::Antialiasing,true); + this->setCentralWidget(m_chartView); // 灏嗚〃瑙嗗浘鏀惧埌涓績閮ㄤ欢鏉ユ樉绀猴紝鍙互鍋氬埌鑷�傚簲澶у皬 +} + +// 璁剧疆褰撳墠鏈�鍚庝竴涓爣璁版洸绾垮拰鏍囩鐨勬樉绀哄強閫忔槑搴︽儏鍐� +void StockPolicy::setLastMarkerShowAndAlpha() +{ + QLegendMarker* marker = m_chart->legend()->markers().back(); + connect(marker,QOverload<>::of(&QLegendMarker::clicked),this,[=]{ + marker->series()->setVisible(!marker->series()->isVisible()); // 鍙栧弽锛屽彲瑙佹椂涓嶅彲瑙侊紝涓嶅彲瑙佹椂鍙樺彲瑙� + marker->setVisible(true); // 鎶婂浘渚嬫爣棰樻樉绀哄鐞� + + qreal alpha = 1.0; // 閫忔槑搴︼紝瀹屽叏涓嶉�忔槑 + if(!marker->series()->isVisible()) alpha = 0.5; // 涓嶅彲瑙佹椂閫忔槑搴� 50% + // 璁剧疆閫忔槑搴︾浉鍏筹紝涓昏鏄缃浘渚嬫爣绛剧殑閫忔槑搴� + QBrush brush = marker->labelBrush(); + QColor color = brush.color(); + color.setAlphaF(alpha); + brush.setColor(color); + marker->setLabelBrush(brush); + }); +} + +void StockPolicy::showNewStockData(QLineSeries *series) +{ + + m_chart->addSeries(series); // 娣诲姞鏁版嵁鍒板浘琛� + m_chart->setAxisX(m_dtAx,series); // 璁剧疆 X杞翠负鏃堕棿杞淬�佹暟鎹� + m_chart->setAxisY(m_axisY,series); // 璁剧疆 Y杞翠负鏁版嵁杞淬�佹暟鎹� + setLastMarkerShowAndAlpha(); // 璁剧疆褰撳墠鏈�鍚庝竴涓爣璁版洸绾垮拰鏍囩鐨勬樉绀哄強閫忔槑搴︽儏鍐� +} + +void StockPolicy::showNewStockData(QSplineSeries *series) +{ + m_chart->addSeries(series); // 娣诲姞鏁版嵁鍒板浘琛� + m_chart->setAxisX(m_dtAx,series); // 璁剧疆 X杞翠负鏃堕棿杞淬�佹暟鎹� + m_chart->setAxisY(m_axisY,series); // 璁剧疆 Y杞翠负鏁版嵁杞淬�佹暟鎹� + setLastMarkerShowAndAlpha(); // 璁剧疆褰撳墠鏈�鍚庝竴涓爣璁版洸绾垮拰鏍囩鐨勬樉绀哄強閫忔槑搴︽儏鍐� +} + + + diff --git a/stockpolicy.h b/stockpolicy.h new file mode 100644 index 0000000..5671e13 --- /dev/null +++ b/stockpolicy.h @@ -0,0 +1,41 @@ +#ifndef STOCKPOLICY_H +#define STOCKPOLICY_H + +#include <QMainWindow> +#include <QChartView> +#include <QDateTimeAxis> +#include <QValueAxis> +#include <QChart> +#include <QGraphicsSimpleTextItem> +#include <QLineSeries> // 鎶樼嚎 +#include <QSplineSeries> // 鏇茬嚎 + +QT_CHARTS_USE_NAMESPACE // 鍛藉悕绌洪棿寰椾娇鐢ㄨ捣鏉ワ紝瑕佷笉鐒剁被浼氭嬁涓嶅埌 + +namespace Ui { +class StockPolicy; +} + +class StockPolicy : public QMainWindow +{ + Q_OBJECT + +public: + explicit StockPolicy(QWidget *parent = 0); + ~StockPolicy(); + void initUi(); + void setLastMarkerShowAndAlpha(); // 璁剧疆褰撳墠鏈�鍚庝竴涓爣璁扮殑鏄剧ず鎯呭喌鍙婇�忔槑搴� +public slots: + void showNewStockData(QLineSeries *series); // 鐢ㄤ簬鍒锋柊鎶樼嚎琛ㄦ牸鏁版嵁鐨� + void showNewStockData(QSplineSeries *series); // 鐢ㄤ簬鍒锋柊鏇茬嚎琛ㄦ牸鏁版嵁鐨� +private: + Ui::StockPolicy *ui; + + QChart *m_chart; + QDateTimeAxis *m_dtAx; + QValueAxis *m_axisY; + QChartView *m_chartView; + +}; + +#endif // STOCKPOLICY_H diff --git a/stockpolicy.ui b/stockpolicy.ui new file mode 100644 index 0000000..64a683c --- /dev/null +++ b/stockpolicy.ui @@ -0,0 +1,24 @@ +<ui version="4.0"> + <author/> + <comment/> + <exportmacro/> + <class>StockPolicy</class> + <widget name="StockPolicy" class="QMainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget name="menubar" class="QMenuBar"/> + <widget name="centralwidget" class="QWidget"/> + <widget name="statusbar" class="QStatusBar"/> + </widget> + <pixmapfunction/> + <connections/> +</ui> -- Gitblit v1.8.0