标签:
在先前的文章“利用reviews PreviewWidget在Ubuntu Scope中显示评价等级”中,我们展示了如何使用review PreviewWidget来显示评价的数据。在这篇文章中,我们将介绍如何使用rating-input PreviewWidget来对事物进行评价及打分。
参考我们的API介绍,rating-input PreviewWidget分为两种:
// The following shows a review rating-input PreviewWidget 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-input PreviewWidget 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);
#ifndef SCOPE_ACTION_H_ #define SCOPE_ACTION_H_ #include <unity/scopes/ActionMetadata.h> #include <unity/scopes/ActivationQueryBase.h> #include <unity/scopes/ActivationResponse.h> #include <unity/scopes/Result.h> class Action : public unity::scopes::ActivationQueryBase { public: Action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& action_id); ~Action() = default; virtual unity::scopes::ActivationResponse activate() override; private: std::string const action_id_; }; #endif // SCOPE_ACTION_H_
#include <scope/action.h> #include <unity/scopes/ActivationResponse.h> #include <unity/UnityExceptions.h> #include <QString> #include <QDebug> #include <iostream> namespace sc = unity::scopes; using namespace std; QString qstr_(std::string str) { return QString::fromStdString(str); } Action::Action(const unity::scopes::Result &result, const unity::scopes::ActionMetadata &metadata, std::string const& action_id) : sc::ActivationQueryBase(result, metadata), action_id_(action_id) { qDebug() << "action id: " << qstr_(action_id_); } sc::ActivationResponse Action::activate() { QString review = QString("%1").arg(qstr_(action_metadata().scope_data(). get_dict()["review"].get_string())); double rating = action_metadata().scope_data(). get_dict()["rating"].get_double(); qDebug() << "review: " << review; qDebug() << "rating: " << rating; sc::ActivationResponse done(sc::ActivationResponse::ShowDash); cerr << "activate called" << endl; return done; }
sc::ActivationQueryBase::UPtr Scope::perform_action( sc::Result const& result, sc::ActionMetadata const& metadata, string const& widget_id, string const& action_id) { cerr << "perform_action called" << endl; return sc::ActivationQueryBase::UPtr(new Action(result, metadata, action_id)); }
利用rating-input PreviewWidget来对事物进行评价及打分
标签:
原文地址:http://blog.csdn.net/ubuntutouch/article/details/46620525