| | |
| | | |
| | | 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(); |
| | |
| | | } |
| | | m_model->appendRow(items); |
| | | } |
| | | qDebug()<<"历史到信息赋值完成 条数:"<<m_model->rowCount(); |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | } |