• R/O
  • SSH
  • HTTPS

nicograph: Commit


Commit MetaInfo

Revision4 (tree)
Time2009-10-05 02:22:58
Authorfourier

Log Message

表示文字をvideo idから動画タイトルに変更
関連動画を得たときにすべての情報を保持するように変更

Change Summary

Incremental Difference

--- branch/nico_node.h (revision 3)
+++ branch/nico_node.h (revision 4)
@@ -29,10 +29,10 @@
2929 public:
3030 virtual ~NicoNode();
3131
32- const NicoThumbInfo *getThumbInfo() const
33- { return thumbinfo; }
32+ const NicoThumbInfo& getThumbInfo() const
33+ { return *thumbinfo; }
3434
35- void setNicoThumbInfo(NicoThumbInfo *nico_thumbinfo);
35+ void setNicoThumbInfo(const NicoThumbInfo& nico_thumbinfo);
3636
3737 protected:
3838 NicoNode(GraphWidget *widget,QString video_id);
--- branch/graph_widget.cpp (revision 3)
+++ branch/graph_widget.cpp (revision 4)
@@ -31,7 +31,7 @@
3131 setViewportUpdateMode(BoundingRectViewportUpdate);
3232 setRenderHint(QPainter::Antialiasing);
3333
34- timerId = startTimer(200);
34+ timerId = startTimer(50);
3535 }
3636
3737 void GraphWidget::nodeUpdate()
--- branch/node.cpp (revision 3)
+++ branch/node.cpp (revision 4)
@@ -26,7 +26,7 @@
2626 #include <QStyleOption>
2727
2828 Node::Node(GraphWidget *widget) :
29- graphwidget(widget), node_factory(0), fixed(false)
29+ graphwidget(widget), node_factory(0), paint_scale(1),fixed(false)
3030 {
3131 setFlag(ItemIsMovable);
3232 setCacheMode(DeviceCoordinateCache);
@@ -129,6 +129,13 @@
129129 node_factory = factory;
130130 }
131131
132+void Node::setPaintScale(const float scale)
133+{
134+ this->scale(1.0/paint_scale,1.0/paint_scale);
135+ paint_scale = scale;
136+ this->scale(paint_scale,paint_scale);
137+}
138+
132139 QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
133140 {
134141 if(change==ItemPositionHasChanged)
--- branch/nico_nodefactory.cpp (revision 3)
+++ branch/nico_nodefactory.cpp (revision 4)
@@ -80,16 +80,54 @@
8080
8181 // related videoをXMLデータから抽出
8282 QList<QString> related_video_id;
83- getRelatedVideo(related_video_id, xml);
83+ QList<NicoThumbInfo> video_infos = getRelatedVideoInfo(xml);
8484
8585 // related videoのノードを新たに作る
86- createRelatedNode(related_video_id);
86+ createRelatedNode(video_infos);
8787 }
8888
89-void NicoNodeFactory::getRelatedVideo(QList<QString>& related_video_id, QString& xml)
89+ void NicoNodeFactory::getRelatedVideo(QList<QString>& related_video_id, QString& xml)
90+ {
91+ if(xml.isEmpty())
92+ return;
93+
94+ QDomDocument document("related_video");
95+ QString errorMsg;
96+ int errorLine, errorColumn;
97+ if(!document.setContent(xml, &errorMsg, &errorLine, &errorColumn))
98+ {
99+ qDebug() << errorMsg;
100+ return;
101+ }
102+
103+ QDomElement related_video = document.elementsByTagName("related_video")
104+ .item(0)
105+ .toElement();
106+ if(related_video.attribute("status")!="ok")
107+ {
108+ qDebug() << tr("xml status error");
109+ return;
110+ }
111+
112+ QDomNodeList videos = related_video.elementsByTagName("video");
113+ if(videos.size()==0)
114+ {
115+ qDebug() << tr("ハズレ");
116+ }
117+
118+ related_video_id.clear();
119+ for(int i=0;i<videos.size();++i)
120+ {
121+ const QDomNode& dom_node = videos.item(i);
122+ QUrl url(dom_node.firstChildElement("url").text());
123+ QString video_id = UrlToId(url);
124+ related_video_id.push_back(video_id);
125+ }
126+ }
127+QList<NicoThumbInfo> NicoNodeFactory::getRelatedVideoInfo(const QString& xml)
90128 {
91129 if(xml.isEmpty())
92- return;
130+ return QList<NicoThumbInfo>();
93131
94132 QDomDocument document("related_video");
95133 QString errorMsg;
@@ -97,7 +135,7 @@
97135 if(!document.setContent(xml, &errorMsg, &errorLine, &errorColumn))
98136 {
99137 qDebug() << errorMsg;
100- return;
138+ return QList<NicoThumbInfo>();
101139 }
102140
103141 QDomElement related_video = document.elementsByTagName("related_video")
@@ -106,7 +144,7 @@
106144 if(related_video.attribute("status")!="ok")
107145 {
108146 qDebug() << tr("xml status error");
109- return;
147+ return QList<NicoThumbInfo>();
110148 }
111149
112150 QDomNodeList videos = related_video.elementsByTagName("video");
@@ -115,28 +153,40 @@
115153 qDebug() << tr("ハズレ");
116154 }
117155
118- related_video_id.clear();
156+ QList<NicoThumbInfo> infos;
119157 for(int i=0;i<videos.size();++i)
120158 {
159+ NicoThumbInfo info;
121160 const QDomNode& dom_node = videos.item(i);
122- QUrl url(dom_node.firstChildElement("url").text());
123- QString video_id = UrlToId(url);
124- related_video_id.push_back(video_id);
161+ info.video_id = UrlToId(QUrl(dom_node.firstChildElement("url").text()));
162+ info.title = dom_node.firstChildElement("title").text();
163+ info.description = tr("untaken");
164+ info.thumbnail_url = QUrl(dom_node.firstChildElement("thumbnail").text());
165+ info.mylist_counter = dom_node.firstChildElement("time").text().toInt();
166+ info.length = dom_node.firstChildElement("length").text();
167+ info.view_counter = dom_node.firstChildElement("view").text().toInt();
168+ info.comment_num = dom_node.firstChildElement("comment").text().toInt();
169+ info.mylist_counter = dom_node.firstChildElement("mylist").text().toInt();
170+ info.watch_url = QUrl(dom_node.firstChildElement("url").text());
171+ info.thumb_type = tr("untaken");
172+ // info.tags = QList<QString>();
173+ infos.push_back(info);
125174 }
175+ return infos;
126176 }
127177
128-void NicoNodeFactory::createRelatedNode(QList<QString>& related_video_id)
178+void NicoNodeFactory::createRelatedNode(QList<NicoThumbInfo>& infos)
129179 {
130- if(related_video_id.isEmpty())
180+ if(infos.isEmpty())
131181 return;
132182
133183 const int append_max_node = 15; // 追加最大数
134184
135- int node_num = qMin(append_max_node, related_video_id.size());
185+ int node_num = qMin(append_max_node, infos.size());
136186
137187 for(int i=0;i<node_num;++i)
138188 {
139- QString& video_id = related_video_id[i];
189+ QString& video_id = infos[i].video_id;
140190
141191 // このvideo_idがすでにNodeになっていないか調べる
142192 // すでにNodeがあればEdgeを作る
@@ -155,6 +205,9 @@
155205 {
156206 graph()->scene()->addItem(new Edge(source_node,dest));
157207 edge=true;
208+
209+ // Nodeの情報を更新する
210+ dest->setNicoThumbInfo(infos[i]);
158211 break;
159212 }
160213 }
@@ -163,6 +216,7 @@
163216
164217 // 新しくNodeを作る
165218 NicoNode *new_node = new NicoNode(graph(), video_id);
219+ new_node->setNicoThumbInfo(infos[i]);
166220 QPointF pos(source_node->pos().x()+rand()%50-100,
167221 source_node->pos().y()+rand()%50-100);
168222 new_node->setPos(pos);
--- branch/nico_nodefactory.h (revision 3)
+++ branch/nico_nodefactory.h (revision 4)
@@ -19,6 +19,7 @@
1919
2020 #include "node_factory.h"
2121 #include "nico_videoid.h"
22+#include "nico_thumbinfo.h"
2223 #include <QNetworkAccessManager>
2324 #include <QPointF>
2425
@@ -37,7 +38,8 @@
3738 QNetworkAccessManager network_manager;
3839
3940 void getRelatedVideo(QList<QString>& related, QString& xml);
40- void createRelatedNode(QList<QString>& related);
41+ QList<NicoThumbInfo> getRelatedVideoInfo(const QString& xml);
42+ void createRelatedNode(QList<NicoThumbInfo>& infos);
4143
4244 public slots:
4345 void downloadFinished(QNetworkReply *reply);
--- branch/node.h (revision 3)
+++ branch/node.h (revision 4)
@@ -54,6 +54,8 @@
5454
5555 void setNodeFactory(NodeFactory *factory);
5656
57+ void setPaintScale(const float scale);
58+
5759 protected:
5860 QVariant itemChange(GraphicsItemChange change, const QVariant &value);
5961 void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -74,6 +76,7 @@
7476 QList<Edge *> edgeList;
7577 GraphWidget *graphwidget;
7678 NodeFactory *node_factory;
79+ float paint_scale;
7780 bool fixed;
7881 };
7982
--- branch/nico_node.cpp (revision 3)
+++ branch/nico_node.cpp (revision 4)
@@ -20,6 +20,7 @@
2020
2121 #include <QDebug>
2222 #include <QString>
23+#include <cmath>
2324
2425 NicoNode::NicoNode(GraphWidget *widget, QString video_id) :
2526 Node(widget)
@@ -41,22 +42,14 @@
4142 delete node_factory;
4243 }
4344
44-void NicoNode::setNicoThumbInfo(NicoThumbInfo *nico_thumbinfo)
45+void NicoNode::setNicoThumbInfo(const NicoThumbInfo& nico_thumbinfo)
4546 {
46- if(nico_thumbinfo==0)
47- {
48- qDebug() << "NicoNode::setNicoThumbInfo warning #1";
49- return;
50- }
47+ *thumbinfo = nico_thumbinfo;
48+ setName(thumbinfo->title);
5149
52- if(nico_thumbinfo==thumbinfo)
53- {
54- qDebug() << "NicoNode::setNicoThumbInfo warning #2";
55- return;
56- }
57-
58- delete thumbinfo;
59- thumbinfo = nico_thumbinfo;
50+ float scale = (2.0-3e5/(thumbinfo->comment_num+3e5));
51+ setPaintScale(scale);
52+ qDebug() << "scale: " << scale ;
6053 }
6154
6255 void NicoNode::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Show on old repository browser