diff --git a/Analyzer/scountdlg.cpp b/Analyzer/scountdlg.cpp index ac478b4..e777438 100644 --- a/Analyzer/scountdlg.cpp +++ b/Analyzer/scountdlg.cpp @@ -26,9 +26,7 @@ void SCountDlg::setWidgets() setWindowTitle("Count"); QVBoxLayout *vlayout = new QVBoxLayout; { - QHBoxLayout *hlayout = new QHBoxLayout; - - + QHBoxLayout *hlayout = new QHBoxLayout; m_pCombo = new QComboBox[C_COMBO_MAX]; for (int i = 0; i < C_COMBO_MAX ; i++) hlayout->addWidget(&m_pCombo[i]); @@ -58,55 +56,192 @@ void SCountDlg::setWidgets() m_pCombo[i].addItem(strList.at(SColumn::E_NAME)); } - m_strGraph = "" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n\r\n" - "\r\n"; + "\r\n"; QRegExp re("\\s{2,}"); m_strGraph = m_strGraph.replace(re,""); m_strGraph = m_strGraph.replace("[!F*i!l*e!]",QApplication::applicationDirPath()+"/graph.tsv"); @@ -187,158 +322,19 @@ void SCountDlg::setWidgets() void SCountDlg::run() { - QTableWidget *pCurrent = (QTableWidget *)GetMainWindow()->m_pDataDlg->GetCurrentWidget(); - int anCatalog[C_COMBO_MAX]; - + int nNone=0; for (int i = 0; i < C_COMBO_MAX ; i++) - anCatalog[i] = m_pCombo[i].currentIndex(); - - QMap > mapCount; - QSet setList; - QDate dateStart(2055,12,31),dateEnd(1900,1,1); - GetMainWindow()->m_progress.setRange(0,pCurrent->rowCount()); - for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) - { - QString astr[C_COMBO_MAX]; - bool bFlag=true; - for (int i = 0; i < C_COMBO_MAX ; i++) - { - if (GetColumn().isDateColumn(anCatalog[i])) - { - QDateTime date; - QDate day = date.fromString(pCurrent->item(nCount,anCatalog[i])->text().trimmed(),"yyyy-MM-dd hh:mm:ss").date(); - astr[i] = day.toString("yyyy-MM-dd").trimmed(); - if(astr[i].isEmpty()) continue; - if (day.year() == 0) continue; - if (day < dateStart) dateStart=day; - if (day > dateEnd) dateEnd=day; - } - else - astr[i] = pCurrent->item(nCount,anCatalog[i])->text().trimmed(); - if (astr[i].isEmpty()) bFlag = false; - } - if (bFlag == false) continue; - if (mapCount.contains(astr[0]) == false) - { - QMap mapSec; - mapCount.insert(astr[0],mapSec); - } - if (mapCount[astr[0]].contains(astr[1]) == false) - mapCount[astr[0]].insert(astr[1],0); - if (setList.contains(astr[1]) == false) - setList.insert(astr[1]); - mapCount[astr[0]][astr[1]]++; - GetMainWindow()->m_progress.setValue(nCount); - GetMainWindow()->m_progress.repaint(); - } - m_pTable->clear(); - QStringList strList; - strList.push_back(m_pCombo[0].currentText()); - for (QSet::iterator i = setList.begin(); i != setList.end(); ++i) - strList.push_back(*i); - m_pTable->SetHeaderList(strList); - int nCount = 0; - m_dTotal = 0.0; - if (GetColumn().isDateColumn(anCatalog[0])) { - qDebug() << dateStart.daysTo(dateEnd); - m_pTable->setRowCount(dateStart.daysTo(dateEnd)); - for (QDate now = dateStart; now < dateEnd ; now=now.addDays(1) ) - { - int nCol = 0; - QString str = now.toString("yyyy-MM-dd").trimmed(); - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(str)); - if (mapCount.contains(str)) - { - for (QSet::iterator j = setList.begin(); j != setList.end(); ++j) - { - if (mapCount[str].contains(*j)) - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(mapCount[str].value(*j)))); - else - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(0))); - } - } - else - { - for (;nCol < strList.size();nCol++) - m_pTable->setItem(nCount,nCol,new QTableWidgetItem(QString::number(0))); - } - nCount++; - } + if (m_pCombo[i].currentIndex() == GetColumn().data().size()) + nNone++; } - else + switch(nNone) { - m_pTable->setRowCount(mapCount.size()); - for (QMap >::iterator i = mapCount.begin(); i != mapCount.end(); ++i) - { - int nCol = 0; - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(i.key())); - for (QSet::iterator j = setList.begin(); j != setList.end(); ++j) - { - if (i->contains(*j)) - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(i->value(*j)))); - else - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(0))); - } - nCount++; - } + case 0:choose_2();break; + case 1:choose_1();break; } } -/* -void SCountDlg::run() -{ - QTableWidget *pCurrent = (QTableWidget *)GetMainWindow()->m_pDataDlg->GetCurrentWidget(); - if (pCurrent == NULL) return; - QMap > mapCount; - QSet setList; - GetMainWindow()->m_progress.setRange(0,pCurrent->rowCount()); - for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) - { - QString astr[2]; - astr[0] = QDateTime::fromString(pCurrent->item(nCount,GetColumn().getDateColumn())->text().trimmed(),"yyyy-MM-dd hh:mm:ss").date().toString("yyyy-MM-dd").trimmed(); - astr[1] = pCurrent->item(nCount,GetColumn().getColumnIndex("platform_name"))->text().trimmed() + "-"; - astr[1] += pCurrent->item(nCount,GetColumn().getColumnIndex("platform_form"))->text().trimmed() + "-"; - astr[1] += pCurrent->item(nCount,GetColumn().getColumnIndex("article_form"))->text().trimmed(); - if (mapCount.contains(astr[0]) == false) - { - QMap mapSec; - mapCount.insert(astr[0],mapSec); - } - if (mapCount[astr[0]].contains(astr[1]) == false) - mapCount[astr[0]].insert(astr[1],0); - if (setList.contains(astr[1]) == false) - setList.insert(astr[1]); - mapCount[astr[0]][astr[1]]++; - GetMainWindow()->m_progress.setValue(nCount); - GetMainWindow()->m_progress.repaint(); - } - m_pTable->clear(); - QStringList strList; - strList.push_back("date"); - //strList.push_back(m_pCombo[0].currentText()); - for (QSet::iterator i = setList.begin(); i != setList.end(); ++i) - strList.push_back(*i); - m_pTable->SetHeaderList(strList); - m_pTable->setRowCount(mapCount.size()); - int nCount = 0; - m_dTotal = 0.0; - for (QMap >::iterator i = mapCount.begin(); i != mapCount.end(); ++i) - { - int nCol = 0; - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(i.key())); - for (QSet::iterator j = setList.begin(); j != setList.end(); ++j) - { - if (i->contains(*j)) - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(i->value(*j)))); - else - m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(0))); - } - nCount++; - } -} -*/ - void SCountDlg::graph() { QFile file(QApplication::applicationDirPath()+"/graph.tsv"); diff --git a/Analyzer/scountdlg.h b/Analyzer/scountdlg.h index 2b244c0..1af3df3 100644 --- a/Analyzer/scountdlg.h +++ b/Analyzer/scountdlg.h @@ -22,6 +22,8 @@ private: QString m_strGraph; double m_dTotal; void setWidgets(); + void choose_1(); + void choose_2(); }; #endif // SCOUNTDLG_H