git-svn-id: svn://192.168.0.12/source@183 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2015-09-02 03:47:20 +00:00
parent 1c7888ca48
commit 09e669659d
12 changed files with 3982 additions and 33 deletions

View File

@@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui sql webkitwidgets network webkit
QT += core gui sql network webenginewidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View File

@@ -175,6 +175,8 @@ void MainWindow::createActions()
connect(actTestUpload, SIGNAL(triggered()), this, SLOT(slotTestUpload()));
actShowUpload = new QAction(tr("Show Upload"), this);
connect(actShowUpload, SIGNAL(triggered()), this, SLOT(slotShowUpload()));
actD3ViewTree = new QAction(tr("D3View Tree"), this);
connect(actD3ViewTree, SIGNAL(triggered()), this, SLOT(slotD3ViewTree()));
}
void MainWindow::slotShowUpload()
@@ -189,6 +191,12 @@ void MainWindow::slotD3View()
//qDebug() << "hide the D3View";
}
void MainWindow::slotD3ViewTree()
{
((YMorphereWidget*)(m_ptwResult->currentWidget()))->D3ViewTree();
//qDebug() << "hide the D3View";
}
void MainWindow::createMenus()
{
@@ -225,7 +233,7 @@ void MainWindow::createMenus()
menuD3View = menuBar()->addMenu(tr("D3View"));
menuD3View->addAction(actD3View);
menuD3View->addAction(actD3ViewTree);
}
//! [12]

View File

@@ -84,7 +84,7 @@ private slots:
void slotTestUpload();
void slotD3View();
void slotShowUpload();
void slotD3ViewTree();
protected:
void closeEvent(QCloseEvent *);
@@ -143,6 +143,7 @@ private:
QAction *actD3View;
QAction *actD3ViewTree;
QAction *actShowUpload;
//AnalyzerThread m_pThread[16];
/*

View File

@@ -40,8 +40,6 @@ class YOneDepthMThread:public YMorphereThread
private:
//QString getWeeksInMonth(unsigned int _nDate);
QString userdict;
int m_nTitleBody;
int m_nPeriod;

View File

@@ -18,7 +18,8 @@
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QUrl>
#include <QDir>
#define D_NOT_SELECT -1
#define SAFE_DELETE(x) if(x != NULL) { delete x; x = NULL; }
@@ -657,8 +658,8 @@ void YMOneDepthWidget::D3View()
QString strHtml;
strHtml = "<html>"
"\n<meta charset=\"utf-8\">"
strHtml = "<!DOCTYPE html>"
"\n<meta charset=\"utf8\">"
"\n<style>"
"\n"
"\n.node circle {"
@@ -705,7 +706,7 @@ void YMOneDepthWidget::D3View()
//"\nd3.json(\"graph.json\", function(error, json) {"
//"\n if (error) throw error;"
"\n"
"\nvar jsonparam = '" + strjson + "';"
"\nvar jsonparam = '" + strjson.toUtf8() + "';"
"\n root = JSON.parse(jsonparam);"
"\n update();"
//"\n});"
@@ -714,13 +715,11 @@ void YMOneDepthWidget::D3View()
"\n var nodes = flatten(root),"
"\n links = d3.layout.tree().links(nodes);"
"\n"
"\n // Restart the force layout."
"\n force"
"\n .nodes(nodes)"
"\n .links(links)"
"\n .start();"
"\n"
"\n // Update links."
"\n link = link.data(links, function(d) { return d.target.id; });"
"\n"
"\n link.exit().remove();"
@@ -728,7 +727,6 @@ void YMOneDepthWidget::D3View()
"\n link.enter().insert(\"line\", \".node\")"
"\n .attr(\"class\", \"link\");"
"\n"
"\n // Update nodes."
"\n node = node.data(nodes, function(d) { return d.id; });"
"\n"
"\n node.exit().remove();"
@@ -759,14 +757,13 @@ void YMOneDepthWidget::D3View()
"\n}"
"\n"
"\nfunction color(d) {"
"\n return d._children ? \"#3182bd\" // collapsed package"
"\n : d.children ? \"#c6dbef\" // expanded package"
"\n return d._children ? \"#3182bd\""
"\n : d.children ? \"#c6dbef\" "
"\n : \"#fd8d3c\"; // leaf node"
"\n}"
"\n"
"\n// Toggle children on click."
"\nfunction click(d) {"
"\n if (d3.event.defaultPrevented) return; // ignore drag"
"\n if (d3.event.defaultPrevented) return;"
"\n if (d.children) {"
"\n d._children = d.children;"
"\n d.children = null;"
@@ -777,7 +774,6 @@ void YMOneDepthWidget::D3View()
"\n update();"
"\n}"
"\n"
"\n// Returns a list of all nodes under the root."
"\nfunction flatten(root) {"
"\n var nodes = [], i = 0;"
"\n"
@@ -791,12 +787,14 @@ void YMOneDepthWidget::D3View()
"\n return nodes;"
"\n}"
"\n"
"\n</script>"
"\n</script></body></html>"
"\n";
/*
QRegExp re("\\s{2,}");
qDebug() << strHtml;
QFile file("c:/data/d3test.html");
strHtml = strHtml.replace(re,"");
QFile file("d3onedepth.html");
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
@@ -804,14 +802,273 @@ void YMOneDepthWidget::D3View()
out << strHtml;
file.close();
*/
m_WVD3View.setHtml(strHtml);
m_WVD3View.settings()->setObjectCacheCapacities(0,0,0);
//QUrl url("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/");
//m_WVD3View.settings()->testAttribute( QWebEngineSetting::JavascriptEnabled );
//m_WVD3View.setContent(strHtml.toUtf8(), "text/html; charset=utf-8", url);
//m_WVD3View.setHtml(strHtml, QUrl("file:///"));
//m_WVD3View.settings()->setObjectCacheCapacities(0,0,0);
m_WVD3View.repaint();
m_WVD3View.show();
}
void YMOneDepthWidget::D3ViewTree()
{
QString strCKeyword = getCenterKeyword();
//qDebug() << "executed";
/*
QString strjson = "{\n\t\"name\":\" " + strCKeyword + "\",\n";
strjson += ("\t\"children\": [\n");
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
int nCountIndex = pTable->columnCount() - 1;
int nKeywordIndex = pTable->columnCount() - 2;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strKeyword = pTable->item(i, nKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
strjson += ("\t{\"name\": \"" + strKeyword + "\", \"size\": " + QString::number(nCount) + "},\n");
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "\n\t]\n}";
*/
QString strjson = "{\"name\":\" " + strCKeyword + "\",";
strjson += ("\"children\": [");
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
int nCountIndex = pTable->columnCount() - 1;
int nKeywordIndex = pTable->columnCount() - 2;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strKeyword = pTable->item(i, nKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
strjson += ("{\"name\": \"" + strKeyword + "\", \"size\": " + QString::number(nCount) + "},");
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "]}";
QString strHtml;
strHtml = "<!DOCTYPE html>"
"\n <head>"
"\n <meta charset=\"utf8\">"
"\n"
"\n <title>Tree Example</title>"
"\n"
"\n <style>"
"\n "
"\n .node {"
"\n cursor: pointer;"
"\n }"
"\n"
"\n .node circle {"
"\n fill: #fff;"
"\n stroke: steelblue;"
"\n stroke-width: 2px;"
"\n }"
"\n"
"\n .node text {"
"\n font: 14px sans-serif;"
"\n }"
"\n"
"\n .link {"
"\n fill: none;"
"\n stroke: #ccc;"
"\n stroke-width: 2px;"
"\n }"
"\n "
"\n </style>"
"\n"
"\n </head>"
"\n"
"\n <body>"
"\n"
"\n<!-- load the d3.js library --> "
"\n<script src=\"http://d3js.org/d3.v3.min.js\"></script>"
"\n "
"\n<script>"
"\n"
"\n"
"\n// ************** Generate the tree diagram *****************"
"\nvar margin = {top: 20, right: 120, bottom: 20, left: 120},"
"\n width = 1920 - margin.right - margin.left,"
"\n height = 1080 - margin.top - margin.bottom;"
"\n "
"\nvar i = 0,"
"\n duration = 950,"
"\n root;"
"\n"
"\nvar tree = d3.layout.tree()"
"\n .size([height, width]);"
"\n"
"\nvar diagonal = d3.svg.diagonal()"
"\n .projection(function(d) { return [d.y, d.x]; });"
"\n"
"\nvar svg = d3.select(\"body\").append(\"svg\")"
"\n .attr(\"width\", width + margin.right + margin.left)"
"\n .attr(\"height\", height + margin.top + margin.bottom)"
"\n .append(\"g\")"
"\n .attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");"
"\n"
"\nvar jsonparam = '" + strjson.toUtf8() + "';"
"\n root = JSON.parse(jsonparam);"
"\nroot.x0 = height / 2;"
"\nroot.y0 = 0;"
"\n "
"\nupdate(root);"
"\n"
"\nd3.select(self.frameElement).style(\"height\", \"500px\");"
"\n"
"\nfunction update(source) {"
"\n"
"\n // Compute the new tree layout."
"\n var nodes = tree.nodes(root).reverse(),"
"\n links = tree.links(nodes);"
"\n"
"\n // Normalize for fixed-depth."
"\n nodes.forEach(function(d) { d.y = d.depth * 180; });"
"\n"
"\n var node = svg.selectAll(\"g.node\")"
"\n .data(nodes, function(d) { return d.id || (d.id = ++i); });"
"\n"
"\n // Enter any new nodes at the parent's previous position."
"\n var nodeEnter = node.enter().append(\"g\")"
"\n .attr(\"class\", \"node\")"
"\n .attr(\"transform\", function(d) { return \"translate(\" + source.y0 + \",\" + source.x0 + \")\"; })"
"\n .on(\"click\", click);"
"\n"
"\n nodeEnter.append(\"circle\")"
"\n .attr(\"r\", 1e-6)"
"\n .style(\"fill\", function(d) { return d._children ? \"lightsteelblue\" : \"#fff\"; });"
"\n"
"\n nodeEnter.append(\"text\")"
"\n .attr(\"x\", function(d) { return d.children || d._children ? -13 : 13; })"
"\n .attr(\"dy\", \".35em\")"
"\n .attr(\"text-anchor\", function(d) { return d.children || d._children ? \"end\" : \"start\"; })"
"\n .text(function(d) { return d.name; })"
"\n .style(\"fill-opacity\", 1e-6);"
"\n"
"\n // Transition nodes to their new position."
"\n var nodeUpdate = node.transition()"
"\n .duration(duration)"
"\n .attr(\"transform\", function(d) { return \"translate(\" + d.y + \",\" + d.x + \")\"; });"
"\n"
"\n nodeUpdate.select(\"circle\")"
"\n .attr(\"r\", 10)"
"\n .style(\"fill\", function(d) { return d._children ? \"lightsteelblue\" : \"#fff\"; });"
"\n"
"\n nodeUpdate.select(\"text\")"
"\n .style(\"fill-opacity\", 1);"
"\n"
"\n // Transition exiting nodes to the parent's new position."
"\n var nodeExit = node.exit().transition()"
"\n .duration(duration)"
"\n .attr(\"transform\", function(d) { return \"translate(\" + source.y + \",\" + source.x + \")\"; })"
"\n .remove();"
"\n"
"\n nodeExit.select(\"circle\")"
"\n .attr(\"r\", 1e-6);"
"\n"
"\n nodeExit.select(\"text\")"
"\n .style(\"fill-opacity\", 1e-6);"
"\n"
"\n var link = svg.selectAll(\"path.link\")"
"\n .data(links, function(d) { return d.target.id; });"
"\n"
"\n // Enter any new links at the parent's previous position."
"\n link.enter().insert(\"path\", \"g\")"
"\n .attr(\"class\", \"link\")"
"\n .attr(\"d\", function(d) {"
"\n var o = {x: source.x0, y: source.y0};"
"\n return diagonal({source: o, target: o});"
"\n });"
"\n"
"\n // Transition links to their new position."
"\n link.transition()"
"\n .duration(duration)"
"\n .attr(\"d\", diagonal);"
"\n"
"\n // Transition exiting nodes to the parent's new position."
"\n link.exit().transition()"
"\n .duration(duration)"
"\n .attr(\"d\", function(d) {"
"\n var o = {x: source.x, y: source.y};"
"\n return diagonal({source: o, target: o});"
"\n })"
"\n .remove();"
"\n"
"\n // Stash the old positions for transition."
"\n nodes.forEach(function(d) {"
"\n d.x0 = d.x;"
"\n d.y0 = d.y;"
"\n });"
"\n}"
"\n"
"\n// Toggle children on click."
"\nfunction click(d) {"
"\n if (d.children) {"
"\n d._children = d.children;"
"\n d.children = null;"
"\n } else {"
"\n d.children = d._children;"
"\n d._children = null;"
"\n }"
"\n update(d);"
"\n}"
"\n"
"\n</script>"
"\n "
"\n </body>"
"\n</html>";
qDebug() << strHtml;
QFile file("d3onedepthtree.html");
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
out << strHtml;
file.close();
m_WVD3View.setHtml(strHtml);
//m_WVD3View.settings()->setObjectCacheCapacities(0,0,0);
m_WVD3View.repaint();
m_WVD3View.show();
}
QString YMOneDepthWidget::Json()
{
QString strCKeyword = getCenterKeyword();
//qDebug() << "executed";
QString strjson = "{\n\t\"name\":\" " + strCKeyword + "\",\n";
strjson += ("\t\"children\": [\n");
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
int nCountIndex = pTable->columnCount() - 1;
int nKeywordIndex = pTable->columnCount() - 2;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strKeyword = pTable->item(i, nKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
strjson += ("\t{\"name\": \"" + strKeyword + "\", \"size\": " + QString::number(nCount) + "},\n");
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "\n\t]\n}";
return strjson;
}
bool YMOneDepthWidget::setListMorphere(QStringList& MorphereEN, QStringList& MorphereKO)
{
QFile fHeader("morpherelist.txt");

View File

@@ -46,6 +46,7 @@ public:
QMap<QString, int> getResult();
void TestUpload();
void D3View();
void D3ViewTree();
void setParam(QString strJson);
private:
// Data
@@ -141,7 +142,7 @@ public slots:
QTabWidget* getQTabWidget();
bool isSortMorphereDateChecked();
bool isSortDateMorphereChecked();
QString Json();
};

View File

@@ -67,6 +67,13 @@ void YMorphereWidget::D3View()
}
void YMorphereWidget::D3ViewTree()
{
}
void YMorphereWidget::setParam(QString strJson)
{

View File

@@ -6,18 +6,24 @@
#include "yalgorithm.h"
#include <QTabWidget>
#include "widget.h"
#include <QWebView>
class QWebViewChild:public QWebView
#include <QWebEngineView>
class QWebViewChild:public QWebEngineView
{
Q_OBJECT
public:
QWebViewChild(QWidget *parent = 0):QWebEngineView(parent)
{
}
protected:
void closeEvent(QCloseEvent *event)
{
this->setHtml(QString());
this->settings()->setObjectCacheCapacities(0,0,0);
this->repaint();
}
};
@@ -46,6 +52,7 @@ public:
virtual void SaveFileSimple();
virtual void TestUpload();
virtual void D3View();
virtual void D3ViewTree();
void setTabWidget(QTabWidget* tabWidget);
virtual void setParam(QString strJson);
QString getName();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,163 @@
#ifndef YMPLATFORMWIDGET
#define YMPLATFORMWIDGET
#include "ymorpherewidget.h"
#include <QCalendarWidget>
#include <QDateEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QComboBox>
#include <QLineEdit>
#include <QGroupBox>
#include <QListWidget>
#include <QTabWidget>
#include <QRadioButton>
#include <QButtonGroup>
#include <QTableWidget>
#include <QProgressBar>
#include <QMenuBar>
#include <QSqlDatabase>
#include <QListWidgetItem>
#include "stable.h"
#include <QCloseEvent>
class YMPlatformWidget:public YMorphereWidget
{
Q_OBJECT
public:
YMPlatformWidget(QWidget *parent = 0);
~YMPlatformWidget();
void clearViewResult();
void clearView();
void ViewResult();
QMap<QString, QString> convertToParam();
//Morphere List
int getThread();
unsigned int getDateStart();
unsigned int getDateEnd();
int getPeriod();
QStringList getMorphereList();
bool getDateAll();
QString getUserDictList();
QString getCenterKeyword();
void SaveFile();
void SaveFileSimple();
QMap<QString, int> getResult();
void TestUpload();
void D3View();
void D3ViewTree();
void setParam(QString strJson);
private:
// Data
QListWidget *m_plwData;
// Date
QCalendarWidget *m_pcw;
QDateEdit *m_pdeStart;
QDateEdit *m_pdeEnd;
QLineEdit *m_pleDates;
QComboBox *m_pcbDuring;
//QPushButton *m_ppbInsertCalc;
//QComboBox *m_pcbDateCatalog;
//
QTabWidget *m_ptwData;
//
QProgressBar *m_pProgress;
// Column
QVector <QStringList> m_vecColumn;
// MorphereList
QListWidget *m_plwMorphereList;
QListWidget *m_plwMorphereAdd;
QComboBox *m_pcbDate;
QComboBox *m_pcbPeriod;
QLineEdit *m_pleFilterRankALL;
QLineEdit *m_pleFilterRankSeparated;
QLineEdit *m_pleFilterKeyword;
QLineEdit *m_pleFilterKeywordLength;
QLineEdit *m_pleFilterExtractor;
QLineEdit *m_pleFilterRankALL2;
QLineEdit *m_pleFilterRankSeparated2;
QLineEdit *m_pleFilterKeyword2;
QLineEdit *m_pleFilterKeywordLength2;
QLineEdit *m_pleFilterExtractor2;
QComboBox *m_pcbThread;
QComboBox *m_pcbSort;
QListWidgetItem **m_plwiMorphere;
QStringList m_strlistMorphere;
QStringList m_strlistMorphereko;
QRadioButton *m_rbDateMorphere;
QRadioButton *m_rbMorphereDate;
QButtonGroup *m_bgRadioGroup;
QComboBox *m_pcbDictionary;
QList<STable*> m_lTable;
QList<QTabWidget*> m_lTabWidget;
QTabWidget* m_ptwTable;
QMap<QString, QMap<QString, QMap<int, QString> > > m_mapViewResult;
QMap<QString, QMap<int, QMap<QString, QString> > > m_mapViewResult2;
QString m_strCKeyword;
QLineEdit *m_pleCKeyword;
QComboBox *m_pcbCountMethod;
QWebViewChild m_WVD3View;
QComboBox* m_pcbData;
public:
struct m_mapKey
{
QString strDate;
QString strMorphere;
QString strKeyword;
};
private:
QGroupBox *setMorphereList();
QGroupBox *setDate();
QGroupBox *setFilter();
QGroupBox *setFilter2();
QGroupBox *setOther();
QGroupBox *setSort();
QGroupBox *setDictionary();
QGroupBox *setCenterKeyword();
QGroupBox *setData();
void SortViewResult();
QTableWidget *AddTable(QString _str);
public slots:
void CloseTab(int index);
void DoubleClickTab(int index);
void FileImport();
void FileExport();
void RawFileExport();
void MemClear();
void MorphereListAdd();
void MorphereListDel();
void AddDictionary();
void DelDictionary();
bool setListMorphere(QStringList& MorphereEN, QStringList& MorphereKO);
QTabWidget* getQTabWidget();
bool isSortMorphereDateChecked();
bool isSortDateMorphereChecked();
QString Json();
};
#endif // YMPLATFORMWIDGET

View File

@@ -1241,8 +1241,8 @@ void YMTwoDepthWidget::D3View()
QString strHtml;
strHtml = "<html>"
"\n<meta charset=\"utf-8\">"
strHtml = "<!DOCTYPE html>"
"\n<meta charset=\"utf8\">"
"\n<style>"
"\n"
"\n.node circle {"
@@ -1289,7 +1289,7 @@ void YMTwoDepthWidget::D3View()
//"\nd3.json(\"graph.json\", function(error, json) {"
//"\n if (error) throw error;"
"\n"
"\nvar jsonparam = '" + strjson + "';"
"\nvar jsonparam = '" + strjson.toUtf8() + "';"
"\n root = JSON.parse(jsonparam);"
"\n update();"
//"\n});"
@@ -1375,12 +1375,12 @@ void YMTwoDepthWidget::D3View()
"\n return nodes;"
"\n}"
"\n"
"\n</script>"
"\n</script></body></html>"
"\n";
qDebug() << strHtml;
QFile file("c:/data/d3test.html");
QFile file("d3twodepth.html");
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
@@ -1389,13 +1389,331 @@ void YMTwoDepthWidget::D3View()
file.close();
m_WVD3View.setHtml(strHtml);
m_WVD3View.settings()->setObjectCacheCapacities(0,0,0);
m_WVD3View.setHtml(strHtml.toUtf8());
//m_WVD3View.settings()->setObjectCacheCapacities(0,0,0);
m_WVD3View.repaint();
m_WVD3View.show();
}
void YMTwoDepthWidget::D3ViewTree()
{
QMap<QString, QMap<QString, int> > mapResult;
QString strCKeyword = getCenterKeyword();
//qDebug() << "executed";
{
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
if(pTable->columnCount() < 4)
return;
int nCountIndex = pTable->columnCount() - 1;
int nTDKeywordIndex = pTable->columnCount() - 2;
int nODKeywordIndex = pTable->columnCount() - 4;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strODKeyword = pTable->item(i, nODKeywordIndex)->text().trimmed();
QString strTDKeyword = pTable->item(i, nTDKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
if(mapResult.contains(strODKeyword))
{
mapResult[strODKeyword].insert(strTDKeyword, nCount);
}
else
{
QMap<QString, int> qLast;
qLast.insert(strTDKeyword, nCount);
mapResult.insert(strODKeyword, qLast);
}
}
}
QString strjson = "{\"name\":\" " + strCKeyword + "\",";
strjson += ("\"children\": [");
for(QMap<QString, QMap<QString, int > >::iterator iterPos1 = mapResult.begin(); iterPos1 != mapResult.end(); iterPos1++)
{
int sum = 0;
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
sum += iterPos2.value();
}
strjson += "{";
strjson += ("\"name\":\"" + iterPos1.key() + "\",\"size\":" + QString::number(sum) + ",");
strjson += "\"children\": [";
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
strjson += ("{\"name\": \"" + iterPos2.key() + "\", \"size\": " + QString::number(iterPos2.value()) + "},");
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "]},";
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "]}";
QString strHtml;
strHtml = "<!DOCTYPE html>"
"\n <head>"
"\n <meta charset=\"utf8\">"
"\n"
"\n <title>Tree Example</title>"
"\n"
"\n <style>"
"\n "
"\n .node {"
"\n cursor: pointer;"
"\n }"
"\n"
"\n .node circle {"
"\n fill: #fff;"
"\n stroke: steelblue;"
"\n stroke-width: 2px;"
"\n }"
"\n"
"\n .node text {"
"\n font: 14px sans-serif;"
"\n }"
"\n"
"\n .link {"
"\n fill: none;"
"\n stroke: #ccc;"
"\n stroke-width: 2px;"
"\n }"
"\n "
"\n </style>"
"\n"
"\n </head>"
"\n"
"\n <body>"
"\n"
"\n<!-- load the d3.js library --> "
"\n<script src=\"http://d3js.org/d3.v3.min.js\"></script>"
"\n "
"\n<script>"
"\n"
"\n"
"\n// ************** Generate the tree diagram *****************"
"\nvar margin = {top: 20, right: 120, bottom: 20, left: 120},"
"\n width = 1920 - margin.right - margin.left,"
"\n height = 1080 - margin.top - margin.bottom;"
"\n "
"\nvar i = 0,"
"\n duration = 950,"
"\n root;"
"\n"
"\nvar tree = d3.layout.tree()"
"\n .size([height, width]);"
"\n"
"\nvar diagonal = d3.svg.diagonal()"
"\n .projection(function(d) { return [d.y, d.x]; });"
"\n"
"\nvar svg = d3.select(\"body\").append(\"svg\")"
"\n .attr(\"width\", width + margin.right + margin.left)"
"\n .attr(\"height\", height + margin.top + margin.bottom)"
"\n .append(\"g\")"
"\n .attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");"
"\n"
"\nvar jsonparam = '" + strjson.toUtf8() + "';"
"\n root = JSON.parse(jsonparam);"
"\nroot.x0 = height / 2;"
"\nroot.y0 = 0;"
"\n "
"\nupdate(root);"
"\n"
"\nd3.select(self.frameElement).style(\"height\", \"500px\");"
"\n"
"\nfunction update(source) {"
"\n"
"\n // Compute the new tree layout."
"\n var nodes = tree.nodes(root).reverse(),"
"\n links = tree.links(nodes);"
"\n"
"\n // Normalize for fixed-depth."
"\n nodes.forEach(function(d) { d.y = d.depth * 180; });"
"\n"
"\n var node = svg.selectAll(\"g.node\")"
"\n .data(nodes, function(d) { return d.id || (d.id = ++i); });"
"\n"
"\n // Enter any new nodes at the parent's previous position."
"\n var nodeEnter = node.enter().append(\"g\")"
"\n .attr(\"class\", \"node\")"
"\n .attr(\"transform\", function(d) { return \"translate(\" + source.y0 + \",\" + source.x0 + \")\"; })"
"\n .on(\"click\", click);"
"\n"
"\n nodeEnter.append(\"circle\")"
"\n .attr(\"r\", 1e-6)"
"\n .style(\"fill\", function(d) { return d._children ? \"lightsteelblue\" : \"#fff\"; });"
"\n"
"\n nodeEnter.append(\"text\")"
"\n .attr(\"x\", function(d) { return d.children || d._children ? -13 : 13; })"
"\n .attr(\"dy\", \".35em\")"
"\n .attr(\"text-anchor\", function(d) { return d.children || d._children ? \"end\" : \"start\"; })"
"\n .text(function(d) { return d.name; })"
"\n .style(\"fill-opacity\", 1e-6);"
"\n"
"\n // Transition nodes to their new position."
"\n var nodeUpdate = node.transition()"
"\n .duration(duration)"
"\n .attr(\"transform\", function(d) { return \"translate(\" + d.y + \",\" + d.x + \")\"; });"
"\n"
"\n nodeUpdate.select(\"circle\")"
"\n .attr(\"r\", 10)"
"\n .style(\"fill\", function(d) { return d._children ? \"lightsteelblue\" : \"#fff\"; });"
"\n"
"\n nodeUpdate.select(\"text\")"
"\n .style(\"fill-opacity\", 1);"
"\n"
"\n // Transition exiting nodes to the parent's new position."
"\n var nodeExit = node.exit().transition()"
"\n .duration(duration)"
"\n .attr(\"transform\", function(d) { return \"translate(\" + source.y + \",\" + source.x + \")\"; })"
"\n .remove();"
"\n"
"\n nodeExit.select(\"circle\")"
"\n .attr(\"r\", 1e-6);"
"\n"
"\n nodeExit.select(\"text\")"
"\n .style(\"fill-opacity\", 1e-6);"
"\n"
"\n var link = svg.selectAll(\"path.link\")"
"\n .data(links, function(d) { return d.target.id; });"
"\n"
"\n // Enter any new links at the parent's previous position."
"\n link.enter().insert(\"path\", \"g\")"
"\n .attr(\"class\", \"link\")"
"\n .attr(\"d\", function(d) {"
"\n var o = {x: source.x0, y: source.y0};"
"\n return diagonal({source: o, target: o});"
"\n });"
"\n"
"\n // Transition links to their new position."
"\n link.transition()"
"\n .duration(duration)"
"\n .attr(\"d\", diagonal);"
"\n"
"\n // Transition exiting nodes to the parent's new position."
"\n link.exit().transition()"
"\n .duration(duration)"
"\n .attr(\"d\", function(d) {"
"\n var o = {x: source.x, y: source.y};"
"\n return diagonal({source: o, target: o});"
"\n })"
"\n .remove();"
"\n"
"\n // Stash the old positions for transition."
"\n nodes.forEach(function(d) {"
"\n d.x0 = d.x;"
"\n d.y0 = d.y;"
"\n });"
"\n}"
"\n"
"\n// Toggle children on click."
"\nfunction click(d) {"
"\n if (d.children) {"
"\n d._children = d.children;"
"\n d.children = null;"
"\n } else {"
"\n d.children = d._children;"
"\n d._children = null;"
"\n }"
"\n update(d);"
"\n}"
"\n"
"\n</script>"
"\n "
"\n </body>"
"\n</html>";
qDebug() << strHtml;
QFile file("d3twodepthtree.html");
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
out << strHtml;
file.close();
m_WVD3View.setHtml(strHtml.toUtf8());
//m_WVD3View.settings()->setObjectCacheCapacities(0,0,0);
m_WVD3View.repaint();
m_WVD3View.show();
}
QString YMTwoDepthWidget::Json()
{
QMap<QString, QMap<QString, int> > mapResult;
QString strCKeyword = getCenterKeyword();
//qDebug() << "executed";
{
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
if(pTable->columnCount() < 4)
return QString();
int nCountIndex = pTable->columnCount() - 1;
int nTDKeywordIndex = pTable->columnCount() - 2;
int nODKeywordIndex = pTable->columnCount() - 4;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strODKeyword = pTable->item(i, nODKeywordIndex)->text().trimmed();
QString strTDKeyword = pTable->item(i, nTDKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
if(mapResult.contains(strODKeyword))
{
mapResult[strODKeyword].insert(strTDKeyword, nCount);
}
else
{
QMap<QString, int> qLast;
qLast.insert(strTDKeyword, nCount);
mapResult.insert(strODKeyword, qLast);
}
}
}
QString strjson = "{\n\t\"name\":\" " + strCKeyword + "\",\n";
strjson += ("\t\"children\": [\n");
for(QMap<QString, QMap<QString, int > >::iterator iterPos1 = mapResult.begin(); iterPos1 != mapResult.end(); iterPos1++)
{
int sum = 0;
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
sum += iterPos2.value();
}
strjson += "\t{\n";
strjson += ("\t\t\"name\":\"" + iterPos1.key() + "\",\"size\":" + QString::number(sum) + ",\n");
strjson += "\t\t\"children\": [\n";
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
strjson += ("\t\t\t{\"name\": \"" + iterPos2.key() + "\", \"size\": " + QString::number(iterPos2.value()) + "},\n");
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "\n\t\t]\n\t},\n";
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "\n\t]\n}";
mapResult.clear();
return strjson;
}
void YMTwoDepthWidget::TestUpload()
{

View File

@@ -48,7 +48,9 @@ public:
QMap<QString, int> getResult();
void TestUpload();
void D3View();
void D3ViewTree();
void setParam(QString strJson);
private:
// Data
QListWidget *m_plwData;
@@ -155,6 +157,7 @@ public slots:
bool isSortMorphereDateChecked();
bool isSortDateMorphereChecked();
QString Json();
};