JavaScriptããã°ã©ããŒã«ãšã£ãŠæå ±ã¯ããœãªã¥ãŒã·ã§ã³ããã¹ã¯ãããã¢ããªã±ãŒã·ã§ã³ã«ç°¡åã«çµ±åã§ããããšã§ããããã«ãããéçºãããã©ã€ãã©ãªã®ãŠãŒã¶ãŒã®ã¿ãŒã²ãããªãŒãã£ãšã³ã¹ãå¢å ããå¯èœæ§ããããŸãïŒãããã«ãããããã¯Qtã¢ããªã±ãŒã·ã§ã³ã®äžçã«åœãŠã¯ãŸããŸãïŒã
以äžã®ã¹ã¯ãªãŒã³ã·ã§ããã¯ãD3.jsã䜿çšããŠã¬ã³ããªã³ã°ãããããŒã¿ãšè¡šç€ºãQtã䜿çšããŠå¶åŸ¡ãããã Dependency WheelãŠã£ãžã§ããïŒCircle of DependenciesïŒã瀺ããŠããŸãã ãã€ã³ã¿ãŒã察å¿ããå匧ã®äžã«ããå Žåããã®é¢ä¿ã¯ã匷調衚瀺ããããæ®ãã¯åæ¡ã«ãªããŸãã ãã®ãŠã£ãžã§ããã䜿çšããŠãããŸããŸãªçš®é¡ã®äŸåé¢ä¿ïŒã©ã€ãã©ãªãŒãªã©ïŒãèŠèŠåã§ããŸãã
å ã®JSãœãªã¥ãŒã·ã§ã³ãšã¯ç°ãªãããã£ãŒãã¯ãŠã£ãžã§ããã«åãããŠåçã«ãµã€ãºå€æŽãããããŒã¿ã¯JSONãã¡ã€ã«ãããŒãããã®ã§ã¯ãªãQtåŽã§èšå®ãããŸãã
ãã®èšäºã¯ãQtããã°ã©ããŒã«çŠç¹ãåœãŠãŠããŸãããJSããã°ã©ããŒã«ãšã£ãŠãèå³æ·±ããããããŸããã

ãã€ããªããã¢ããªã±ãŒã·ã§ã³ã®ã¢ã€ãã¢
ãã€ããªããã¢ããªã±ãŒã·ã§ã³ã®ã¢ã€ãã¢ã®åºçºç¹ã¯ããã€ãã£ãã¢ããªã±ãŒã·ã§ã³ã«åºæã®å€ãã®å¶éã§ãã
- ã·ã¹ãã ã®ã¯ã©ã€ã¢ã³ãéšåã®å®è£ ãšã¡ã³ããã³ã¹ã®ããã®è¿œå è²»çšã
- äžæã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãèšè¿°ããããšã¯ãç°¡åãªäœæ¥ã§ã¯ãªãå ŽåããããŸãã
- æ¢åã®Webã¢ããªã±ãŒã·ã§ã³ã®APIãåå©çšã§ããªãã
ãã€ããªããã¢ããªã±ãŒã·ã§ã³ã¯ããããã®åé¡ã次ã®æ¹æ³ã§è§£æ±ºããŸãã
- å±éã¯ãWebã¢ããªã±ãŒã·ã§ã³ãšåæ§ã«å®è¡ãããŸãã
- è€éãªã€ã³ã¿ãŒãã§ãŒã¹ã¯ãWebãã¯ãããžãŒïŒHTMLãCSSãSVGãCanvasïŒã䜿çšããŠäœæãããŸãã
- æ¢åã®Webã¢ããªã±ãŒã·ã§ã³ã®APIãåå©çšããŸããã
ãã€ããªããã¢ããªã±ãŒã·ã§ã³ã¢ãŒããã¯ãã£ã¯ã
- Qt-applicationã¯ãã©ãŠã¶ãšããŠæ©èœããŸãã
- ãŠãŒã¶ãŒã€ã³ã¿ã©ã¯ã·ã§ã³ãšã¢ããªã±ãŒã·ã§ã³ããžãã¯ã¯JavaScriptã§ããã°ã©ã ãããŸãã
- è¿œå æ©èœã¯ãã¢ããªã±ãŒã·ã§ã³ã®Qtéšåã®C ++ã§å®è£ ãããŸãã
ãããã£ãŠããã€ããªããã¢ããªã±ãŒã·ã§ã³ã¯ã·ã³ã¯ã©ã€ã¢ã³ãã®æŠå¿µãå®è£ ããŸãã
Qtã®ãã€ããªããã¢ããªã±ãŒã·ã§ã³ã®äžäŸã¯ã WebKit Image Analyzerã§ãã
ãã®èšäºã§æ€èšããäŸã§ã¯ããã€ããªããã¢ããªã±ãŒã·ã§ã³ã¢ãããŒãã®äžéšãã€ãŸãJavaScriptã䜿çšããŠã³ã³ããŒãã³ãã衚瀺ããæ¹æ³ã®ã¿ã䜿çšããŸãã ãã®å ŽåãåŸæ¥ã®StandAloneã¢ããªã±ãŒã·ã§ã³ã®ããã«ãå¿ èŠãªãã¹ãŠã®JSãã¡ã€ã«ã¯ãªãœãŒã¹ã«é 眮ãããŸãïŒã¹ã¿ã³ãã¢ãã³ã§ãããã€ã³ãã©ããã/ã€ã³ã¿ãŒããããããã¯ãŒã¯æ¥ç¶ãå¿ èŠãªãããïŒã
ãããžã§ã¯ãæ§é
ãããžã§ã¯ããã¡ã€ã«ã®äžè¬çãªæ§é ãå³ã«ç€ºããŸãã

åºæ¬ãã£ã¬ã¯ããªã«ã¯ä»¥äžãå«ãŸããŸãã
- d3viewer.hããã³d3viewer.cpp- QWidgetããç¶æ¿ããã QWebViewãšã®çžäºäœçšãã«ãã»ã«åããããŒã¹ãã¥ãŒã¯ã©ã¹D3Viewerã®å®çŸ©ãšå®è£ ã
- d3webpage.hããã³d3webpage.cpp-D3WebPageã®å®çŸ©ãšå®è£ -QWebPageã®åå«ïŒ QWebPage :: javaScriptConsoleMessageã®ãšã©ãŒã¡ãã»ãŒãžãšãããã°æ å ±ã®åºåããµããŒãããããïŒã
charts / pieãã£ã¬ã¯ããªã§ïŒ
- dependencywheelwidget.hããã³dependencywheelwidget.cpp- QWidgetããç¶æ¿ããã QWebViewãšã®çžäºäœçšãã«ãã»ã«åããããŒã¹ãã¥ãŒã¯ã©ã¹ã®å®çŸ©ãšå®è£ ã
ãªãœãŒã¹ãã£ã¬ã¯ããªã¯ãjsãšhtmlã®2ã€ã«åãããŠããŸãã htmlã«ã¯ããŠã£ãžã§ããã«ããŒããããããŒãžãšãQtãšã®ãã¹ãŠã®å¯Ÿè©±ã³ãŒããå«ãŸããããŒãžãå«ãŸããŸããjsã«ã¯ãDependencyWheelãæ©èœããããã«å¿ èŠãªjsãã¡ã€ã«ãå«ãŸããŸãã jsã
ã¯ã©ã¹å³
VisualParadigmããŒã«ã䜿çšããŠèšäºã®ããªã¥ãŒã ãæžããããã«ãç°¡åãªå³ãäœæãããŸããã説æãããæè¡ã«çŽæ¥é¢ä¿ããªãã¯ã©ã¹ã®å±æ§ãšã¡ãœããã¯çç¥ãããŸããã å®è£ ã®è©³çŽ°ã«ã€ããŠã¯ããœãŒã¹ãã芧ãã ããããªã³ã¯ã¯èšäºã®æåŸã«ãããŸãã

Qt <-> JSã€ã³ã¿ã©ã¯ã·ã§ã³
ãã€ããªããã¢ããªã±ãŒã·ã§ã³ã§ã¯ãç¹å¥ãªãªããžã§ã¯ããJavaScriptã§å®è£ ããããã®ã¡ãœããåŒã³åºãã¯QtåŽã§åŠçãããŸãã
void D3Viewer::addContextObject(const QString &name, QObject *object) { frame()->addToJavaScriptWindowObject( name, object ); //frame() - QWebFrame }
ãã®ã¡ãœããã¯ãããŒãžãããŒããããåã«ãã³ã³ã¹ãã©ã¯ã¿ãŒã®D3Viewer掟çã¯ã©ã¹ã§åŒã³åºãããŸãã
addContextObject("api", this);
ããã«ãQtãšJSã®çžäºäœçšã¯4ã€ã®ã¡ã«ããºã ã«ãã£ãŠå¯èœã§ãã
- ãªããžã§ã¯ãã®ããããã£ã«ã¢ã¯ã»ã¹ããã
ãããè¡ãã«ã¯ããªããžã§ã¯ãã®ããããã£ãå®çŸ©ããå¿ èŠããããŸããããã¯ãJSã®ã³ã³ããã¹ããªããžã§ã¯ãïŒãapiãïŒã§ãã
public: Q_PROPERTY(float padding READ padding WRITE setPadding) public slots: float padding(); //getter void setPadding(const float padding); //setter
ãã®åŸãJSãããããã®ããããã£ã«ã¢ã¯ã»ã¹ã§ããŸãã
var chart = d3.chart.dependencyWheel() .width(api.width) .height(api.height) .margin(api.margin) .padding(api.padding);
- JSã§Qtã·ã°ãã«ãåŠçããã«ã¯ãJSã§ãã®ããã«ã察å¿ããé¢æ°ãã³ãã©ãŒãã·ã°ãã«ã«æ¥ç¶ããå¿
èŠããããŸãã
api.update.connect(redraw);
- ããšãã°ãèŠçŽ ã®ã¯ãªãã¯ãåŠçãããšãã«ãJSã§Qtã¹ããããåŒã³åºãããšã«ããïŒ
g.append("svg:path") .style("fill", fill) .style("stroke", fill) .attr("d", arc) .on("mouseover", fade(0.1)) .on("mouseout", fade(1)) .on('click', function (d) { api.itemClicked(packageNames[d.index]) } ); //
- JSã§ä»ã®Qtã¡ãœãããåŒã³åºãã«ã¯ããã®ããã«ãã¡ãœãã宣èšã®åã«Q_INVOKABLEãã¯ãã眮ãå¿
èŠããããŸãã
Q_INVOKABLE void thisMethodIsInvokableInJavaScript();
- JSã³ãŒãã®çŽæ¥å®è¡ã
void D3Viewer::evaluateScript(const QString &script) { frame()->evaluateJavaScript(script); }
ãã®äŸã§ã¯ãæ¹æ³4ãš5ã¯äœ¿çšãããŠããŸããã
ãã€ããªããã¢ããªã±ãŒã·ã§ã³ã§ã®JavaScriptãããã°
JSã¢ããªã±ãŒã·ã§ã³ããããã°ããã«ã¯ïŒDOMã®è¡šç€ºããããã¯ãŒã¯ã¢ã¯ãã£ããã£ã®è¡šç€ºããªãœãŒã¹ã®èªã¿èŸŒã¿ãªã©ïŒãD3Viewerã³ã³ã¹ãã©ã¯ã¿ãŒã§æ¬¡ã®ããããã£ãèšå®ããå¿ èŠããããŸãã
#ifdef QT_DEBUG // page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); #endif
次ã«ãå®è¡æã«ãã³ã³ããã¹ãã¡ãã¥ãŒã®é ç®ãæ€æ»ããã³ã³ããã¹ãã¡ãã¥ãŒã§äœ¿çšå¯èœã«ãªããŸãïŒQWebViewãå³ã¯ãªãã¯ïŒã

Web-inspector-aã衚瀺ããããŠã£ã³ããŠãéžæããããšã«ããã

ãã®ãŠã£ã³ããŠã®[ã¹ã¯ãªãã]ã¿ãã§ããããã°ãæå¹ã«ã§ããŸãã

ãã¬ãŒã¯ãã€ã³ãã®ã€ã³ã¹ããŒã«ã¯ãå·ŠåŽã®å¯Ÿå¿ããè¡çªå·ãã¯ãªãã¯ããããšã«ããè¡ãããŸãã
PS Qt 4.8.6ã§ã¯ããã¬ãŒã¯ãã€ã³ããã€ã³ã¿ãŒã»ããããããšãã§ããŸããã§ããã 5.3.0ã§ã¯ããã¹ãŠãæ£åžžã«æ©èœããŸãã
çæ
ãããã®ãœãªã¥ãŒã·ã§ã³ã«ãé·æãšçæããããŸãã ãã®å ŽåãD3.jsã¯ãå¯æããã®ä»£äŸ¡ãæ¯æãå¿ èŠããããŸãã
- è¿œå ã®ãªãŒããŒãããïŒäž»ã«ã¡ã¢ãªïŒã
QWebViewãWebkitãããã«ãããæ°ããããã€ããªããããŠã£ãžã§ãããäœæãããšããäºå®ã«å ããŠãããªãéãQWebViewãªããžã§ã¯ããåäœæããŸãã UIå šäœã1ã€ã®QWebViewã«ããŒããããŠããå ŽåïŒãã€ããªããã¢ããªã±ãŒã·ã§ã³ã®å ã®ã¢ã€ãã¢ã§ææ¡ãããŠããããã«ïŒãããã¯ããã»ã©çå®ã§ã¯ãããŸããã
- JSãå€æŽããåŸãWebã§ã®åå©çšãå ã«æ»ããªããªããªã¹ã¯ã Qtã®ããŒãºã«åãããŠãJavaScriptã³ãŒããå€æŽããŠãWebã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšã§ããªããªãããã«ããããšãã§ããŸãã ãããã£ãŠãapi Qtãªããžã§ã¯ããžã®ãã¹ãŠã®åŒã³åºãã1ãæã§åé¢ããããšãæãŸãã-ããšãã°ãhtmlãã¡ã€ã«ã®ã¹ã¯ãªããã»ã¯ã·ã§ã³ã§ã¯ããã®å ŽåãWebã¢ããªã±ãŒã·ã§ã³ãšQtã¢ããªã±ãŒã·ã§ã³ã§ã¯ç°ãªããæ¥ç¶ããããã¡ã€ã«ã®JSã³ãŒãã¯åãã«ãªããŸãã
- Qt 4.8.6ã®WebKitãã°
D3ã§ã¯ãããªãŒæ§é ãç©æ¥µçã«äœ¿çšãããŠããããã®èª¬æã¯JSONãã¡ã€ã«ã«ãããŸãã QtåŽã§ã¯ãåãJSONãªããžã§ã¯ããQVariantMap / QVariantListã®çµã¿åããã«ãã£ãŠåœ¢æãããQVariantã«ãªããŸãã ãã®ãããªãªããžã§ã¯ãã®æ§é ã¯åäžã§ãããšããäºå®ã«ãããããããQt 4.8.6ã§ã¯ãŸã éãããããŸãããã®ãããªãªããžã§ã¯ãã¯çŽæ¥èªèããããJSåŽã®ã¡ã¢ãªã«JSONãªããžã§ã¯ããç¹°ãè¿ããåäœæãããå¿ èŠãããããã§ãã Qt 5.3.0ã§ã¯ããã®ãããªæŸèæã¯äœ¿çšã§ããŸãã-ãã¹ãŠãçŽæ¥æ©èœããŸãã
function recreateJsonObject(obj) { var jsonObj = {}; for(key in obj) { jsonObj[key] = obj[key]; var dependencies = []; for (var i = 0 ; i < obj[key].length ; i++ ) { dependencies.push(obj[key][i]); } jsonObj[key] = dependencies; } return jsonObj; }
Qt 4.8.6ã§ããããŠã£ãžã§ããã®15ã20ç§ã®ãµã€ãºå€æŽåŸãã¢ããªã±ãŒã·ã§ã³ã¯æ£åžžã«åäœãåæ¢ããJSã®ãšã©ãŒã¡ãã»ãŒãžã®ããŒããèœã¡ãŸãã Qt 5.3.0ã§ã¯ããã¹ãŠãé©åã«æ©èœããŸããããã¯ãWebKitèªäœã®å®è£ ã«åé¡ãããããšã瀺åããŠããŸãïŒç§ã¯ééã£ãŠããå¯èœæ§ããããŸãïŒã ãã ããJSåŽã§ã®ã¡ã¢ãªã®å²ãåœãŠãšè§£æŸã®åé¡ã¯åŒãç¶ãéèŠã§ãã
ãœãŒã¹ã³ãŒã
ãµã³ãã«ã®ãœãŒã¹ã³ãŒãã¯ã ããããå ¥æã§ããŸã ã
äŸãæ§ç¯ãããQt 4.8.6ããã³5.3.0ã§å®è¡ãããŸããã