在新的Scope设计中,有一个新的Comment-input PreviewWidget.这个可以帮我用来列举我们收到评论,比如在点评中,对一个餐馆的评论文字.

在上面的显示中,我们显示了Author,时间,及Comments.在今天的实验中,我们将介绍如何实现这样的功能.

我们首先还是从我们以前做过的练习中来讲述.下载我们的代码:

$ git clone https://github.com/liu-xiao-guo/scopetemplates_rating_input

在我们的代码中,我们添加如下的东西:

query.cpp

void Query::pushResult(sc::SearchReplyProxy const& reply,const string renderer, int i) {stringstream ss;ss << i;string str = ss.str();auto cat = reply->register_category( "id" + str, "Template " + str ,"", sc::CategoryRenderer(renderer) );sc::CategorisedResult r(cat);r.set_uri( URI.toStdString() );r.set_art( images_[0].toStdString() );
//    r.set_art("http://api.map.baidu.com/images/weather/night/leizhenyu.png");r["subtitle"] = "Subtitle " + str;r.set_title("Title " + str);r["summary"] = "Summary: " + str;r["fulldesc"] = "fulldesc: " + str;r["mascot"] = icons_[0].toStdString();r["emblem"] = icons_[1].toStdString();r["background"] = background_.toStdString();r["overlay-color"] = "#FF0000";r["comment_icon"] = icons_[3].toStdString();QString likes = QString("%1 %2").arg(qstr(u8"\u261d "), "100");QString views = QString("%1 %2").arg(qstr(u8"   \u261f "), "99");std::string both = qstr("%1 %2").arg(likes,views).toStdString();sc::VariantBuilder builder;builder.add_tuple({{"value", Variant(both)}});builder.add_tuple({{"value", Variant("")}});r["attributes"] = builder.end();r["musicSource"] = "http://qqmp3.djwma.com/mp3/魔音神据极品私货这锯子拉的耳膜都要碎了.mp3";r["videoSource"] = "http://techslides.com/demos/sample-videos/small.mp4";r["screenshot"] = icons_[2].toStdString();// add an array to show the gallary of itsc::VariantArray arr;for(const auto &datum : icons_) {arr.push_back(Variant(datum.toStdString()));}r["array"] = sc::Variant(arr);if (!reply->push(r))return;
}

在上面,我们加入了:

    r["comment_icon"] = icons_[3].toStdString();

这是我们需要显示Comment时最左边的图标.

preview.cpp

void Preview::run(sc::PreviewReplyProxy const& reply) {// Support three different column layoutsColumnLayout layout1col(1);std::vector<std::string> ids = { "image", "header", "summary", "tracks","videos", "gallery_header", "gallerys", "reviews", "exp","review_input", "rating_input", "inputId" };ColumnLayout layout2col(2);layout2col.add_column(ids);layout2col.add_column({});ColumnLayout layout3col(3);layout3col.add_column(ids);layout3col.add_column({});layout3col.add_column({});// Define the header sectionsc::PreviewWidget header("header", "header");// It has title and a subtitle propertiesheader.add_attribute_mapping("title", "title");header.add_attribute_mapping("subtitle", "subtitle");// Define the image sectionsc::PreviewWidget image("image", "image");// It has a single source property, mapped to the result's art propertyimage.add_attribute_mapping("source", "art");// Define the summary sectionsc::PreviewWidget description("summary", "text");// It has a text property, mapped to the result's description propertydescription.add_attribute_mapping("text", "description");Result result = PreviewQueryBase::result();PreviewWidget listen("tracks", "audio");{VariantBuilder builder;builder.add_tuple({{"title", Variant("This is the song title")},{"source", Variant(result["musicSource"].get_string().c_str())}});listen.add_attribute_value("tracks", builder.end());}PreviewWidget video("videos", "video");video.add_attribute_value("source", Variant(result["videoSource"].get_string().c_str()));video.add_attribute_value("screenshot", Variant(result["screenshot"].get_string().c_str()));sc::PreviewWidget header_gal("gallery_header", "header");header_gal.add_attribute_value("title", Variant("Gallery files are:"));PreviewWidget gallery("gallerys", "gallery");
//    gallery.add_attribute_value("sources", Variant(result["array"]));gallery.add_attribute_mapping("sources", "array");PreviewWidgetList widgets({ image, header, description });if ( result["musicSource"].get_string().length() != 0 ) {widgets.emplace_back(listen);}if( result["videoSource"].get_string().length() != 0 ) {widgets.emplace_back(video);}if( result["array"].get_array().size() != 0 ) {widgets.emplace_back(header_gal);widgets.emplace_back(gallery);}// The following shows the reviewPreviewWidget review("reviews", "reviews");VariantBuilder builder;builder.add_tuple({{"author", Variant("John Doe")},{"review", Variant("very good")},{"rating", Variant(3.5)}});builder.add_tuple({{"author", Variant("Mr. Smith")},{"review", Variant("very poor")},{"rating", Variant(5)}});review.add_attribute_value("reviews", builder.end());widgets.emplace_back(review);// The following shows the expandablePreviewWidget expandable("exp", "expandable");expandable.add_attribute_value("title", Variant("This is an expandable widget"));expandable.add_attribute_value("collapsed-widgets", Variant(1));PreviewWidget w1("w1", "text");w1.add_attribute_value("title", Variant("Subwidget 1"));w1.add_attribute_value("text", Variant("A text"));PreviewWidget w2("w2", "text");w2.add_attribute_value("title", Variant("Subwidget 2"));w2.add_attribute_value("text", Variant("A text"));expandable.add_widget(w1);expandable.add_widget(w2);widgets.emplace_back(expandable);// The following shows a review rating-inputPreviewWidget w_review("review_input", "rating-input");w_review.add_attribute_value("submit-label", Variant("Send"));w_review.add_attribute_value("visible", Variant("review"));w_review.add_attribute_value("required", Variant("review"));std::string reply_label = "Reply";std::string max_chars_label = "140 characters max";w_review.add_attribute_value("review-label", Variant(reply_label + ": " + max_chars_label));widgets.emplace_back(w_review);// The follwing shows a rating rating-inputPreviewWidget w_rating("rating_input", "rating-input");w_rating.add_attribute_value("visible", Variant("rating"));w_rating.add_attribute_value("required", Variant("rating"));w_rating.add_attribute_value("rating-label", Variant("Please rate this"));widgets.emplace_back(w_rating);PreviewWidget w_commentInput("inputId", "comment-input");w_commentInput.add_attribute_value("submit-label", Variant("Post"));widgets.emplace_back(w_commentInput);// In the following, fake some comments dataQList<Comment> comment_list;std::string comment_str = "Comment ";for(int i = 0; i < 3;  i++) {Comment comment;comment.id         = 1.0;comment.publishTime = "2015-3-18";comment.text = comment_str;comment.text += std::to_string(i+1);comment_list.append(comment);}int index = 0;Q_FOREACH(const auto & comment, comment_list) {std::string id = "commentId_" + std::to_string(index++);ids.emplace_back(id);PreviewWidget w_comment(id, "comment");w_comment.add_attribute_value("comment", Variant(comment.text));w_comment.add_attribute_value("author", Variant("Author"));w_comment.add_attribute_value("source", Variant(result["comment_icon"].get_string().c_str()));w_comment.add_attribute_value("subtitle", Variant(comment.publishTime));widgets.emplace_back(w_comment);}layout1col.add_column(ids);reply->register_layout({layout1col, layout2col, layout3col});reply->push( widgets );
}
在上面的函数中,我们加入了如下的代码:
    PreviewWidget w_commentInput("inputId", "comment-input");w_commentInput.add_attribute_value("submit-label", Variant("Post"));widgets.emplace_back(w_commentInput);// In the following, fake some comments dataQList<Comment> comment_list;std::string comment_str = "Comment ";for(int i = 0; i < 3;  i++) {Comment comment;comment.id         = 1.0;comment.publishTime = "2015-3-18";comment.text = comment_str;comment.text += std::to_string(i+1);comment_list.append(comment);}int index = 0;Q_FOREACH(const auto & comment, comment_list) {std::string id = "commentId_" + std::to_string(index++);ids.emplace_back(id);PreviewWidget w_comment(id, "comment");w_comment.add_attribute_value("comment", Variant(comment.text));w_comment.add_attribute_value("author", Variant("Author"));w_comment.add_attribute_value("source", Variant(result["comment_icon"].get_string().c_str()));w_comment.add_attribute_value("subtitle", Variant(comment.publishTime));widgets.emplace_back(w_comment);}layout1col.add_column(ids);

在上面我们创建了一个叫做comment-input的PreviewWidget.同时,我们在显示每项comment时,使用了一个叫做comment的PreviewWidget.由于没有online数据,我们自己创建了一下fake的数据.运行我们的Scope,我们可以看到结果就像我们上面图显示的那样.

注意在上面的实现中,我们必须动态地添加每个创建的comment PreviewWidget,所以,有上面的语句:
layout1col.add_column(ids);

整个项目的源码在:https://github.com/liu-xiao-guo/scopetemplates_comment_input

在Scope中利用Comment-input来列举我们的评论相关推荐

  1. 利用audio PreviewWidget在Scope中来播放音乐

    在我们的Scope PreviewWidget,我们可以利用audio PreviewWidget来播放我们的音乐.这对一些音乐的Scope来说,非常中要.在今天的练习中,我们来利用这个它来在我们的S ...

  2. jax-rs jax-ws_通过JAX-WS Provider在Web服务中利用MOXy

    jax-rs jax-ws 在以前的文章中,我演示了如何将EclipseLink JAXB(MOXy)直接集成到WebLogic(从12.1.1开始)和GlassFish(从3.1.2开始)的JAX- ...

  3. 通过JAX-WS Provider在Web服务中利用MOXy

    在先前的文章中,我演示了如何将EclipseLink JAXB(MOXy)直接集成到WebLogic(从12.1.1开始)和GlassFish(从3.1.2开始)的JAX-WS实现中 . 在本文中,我 ...

  4. laravel ajax ip,怎么在Laravel中利用AJAX动态刷新部分页面

    怎么在Laravel中利用AJAX动态刷新部分页面 发布时间:2021-02-17 13:12:43 来源:亿速云 阅读:119 作者:Leah 怎么在Laravel中利用AJAX动态刷新部分页面?很 ...

  5. linux中利用shell脚本条件执行linux命令

    linux中利用shell脚本条件执行命令 在linux环境中,我们总会有一些命令需要经常用,例如经常跳转到某些目录下或者执行某些命令,输入一连串的命令是很烦的,此时我们可以预先写一些脚本然后根据我们 ...

  6. Vue项目中利用pdf.js实现pdf内容滑选文字展示与搜索功能

    Vue项目中利用pdf.js实现pdf内容滑选文字展示与搜索功能 需求:在pdf中鼠标滑动选中一段文字,将选中文字展示到input框中(pdf在iframe中) 完成效果: 关于pdf的引用:我是直接 ...

  7. Elemet-UI 中利用穿梭框对表格列进行动态设置

    Elemet-UI 中利用穿梭框对表格列进行动态设置 第一步 引入控件 在需要表格设置的文件下引入公共穿梭框控件 import Transfer from '../components/common/ ...

  8. HTML中利用JS调用PHP (以登录为例)

    最近在做 Login 和 Register 的东西,因为需要用到 session 来存储用户的 id 和 用户名,所以需要调用 php 中的 session.由于不会 Ajax, 所以不得不用一些笨办 ...

  9. Java项目中利用Freemarker模板引擎导出--生成Word文档

    应邀写的一篇文章:Java项目中利用Freemarker模板引擎导出--生成Word文档 资源下载:https://download.csdn.net/download/weixin_41367523 ...

最新文章

  1. 比特币黄金(BTG)遭受51%双花攻击?——不亏
  2. 乔氏西去,敬告各位!
  3. git下载指定分支代码到本地
  4. Sparkmllib scala线性回归
  5. 文本分类入门(六)训练Part 3
  6. 50个linux指令,每天学一个 Linux 命令(50):date
  7. leetcode-26-删除排序数组中的重复项
  8. centos7--shell脚本自动实现bond配置-第二版
  9. 昨天mac更新后,网络又出问题了。。。
  10. 独家 | 林元庆告别百度
  11. Unix环境高级编程(十五)高级I/O
  12. 计算机视觉中的数学方法——7. 2 酉空间与酉矩阵
  13. ubuntu 卸载anaconda
  14. windows 强制关闭程序并强制删除文件
  15. Android studio Intent
  16. 深度学习:GAN 对抗网络原理详细解析(零基础必看)
  17. 独轮平衡车c语言源码,双轮平衡车程序 - 源码下载|嵌入式/单片机编程|源代码 - 源码中国...
  18. 使用attrib命令修复隐藏的文件夹
  19. 编程是一场漫长的修行
  20. db2 修改表空间自增长_db2 创建表空间、增大表空间以及增加临时表空间

热门文章

  1. win7计算机没有光驱图标不见了,怎么解决win7光驱图标不见了电脑光驱图标不见了解决方法...
  2. Python基础灬函数(定义,参数)
  3. 建立数据库时连接出错_漫画——你还记得原生的JDBC怎么连接数据库吗?
  4. 集成电路总线(Inter-Integrated Circuit, I2C)
  5. 回归系数t检验公式_两独立样本的秩和检验——Mann-Whitney检验
  6. 安卓 PopupWindow
  7. 2个TDM8功放调试ing
  8. linux中tcp/ip协议实现及嵌入式应用 下载,LINU中TCPIP协议实现及嵌入式应用
  9. 一元二次方程组的输入
  10. win2016开启smb服务器_实用!Win10开启SMB共享的方法,给GPD MicroPc扩展更多存