{"id":171295,"date":"2013-03-03T22:00:03","date_gmt":"2013-03-03T18:00:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=171295"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=171295","title":{"rendered":"<span class=\"post_title\">\u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0432 C++<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       <img decoding=\"async\" align=\"left\" src=\"http:\/\/habrastorage.org\/storage2\/ebf\/bcd\/b5e\/ebfbcdb5e347d9bb0dc152628ebac79c.png\"\/> QtQuick \u0438 QML \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u044f\u0437\u044b\u043a \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 QML \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b \u0438 \u0443\u0434\u043e\u0431\u043d\u044b. \u0414\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u0435\u043d \u0432 \u0440\u0430\u0431\u043e\u0442\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430 C++? \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c C++.<\/p>\n<p>  <i>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/i> \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u0431\u0430\u0432\u044b, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0438<\/h4>\n<p>  \u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432. \u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u043d\u044f \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u043b \u043a\u043e\u0434 \u0438\u0437 <a href=\"http:\/\/qt-project.org\/doc\/qt-4.8\/propertybinding.html#property-binding\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 QML<\/a>.<\/p>\n<pre><code class=\"cpp\">int calculateArea(int width, int height) {   return (width * height) * 0.5; }  struct rectangle {   property&lt;rectangle*&gt; parent = nullptr;   property&lt;int&gt; width = 150;   property&lt;int&gt; height = 75;   property&lt;int&gt; area = [&]{ return calculateArea(width, height); };    property&lt;std::string&gt; color = [&]{     if (parent() && area &gt; parent()-&gt;area)       return std::string(&quot;blue&quot;);     else       return std::string(&quot;red&quot;);   }; };<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c <code>[&]{ ... }<\/code>, \u0442\u043e \u044d\u0442\u043e <a href=\"http:\/\/stackoverflow.com\/questions\/7627098\/what-is-a-lambda-expression-in-c11\">\u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a>. \u0422\u0430\u043a\u0436\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0432 C++11 \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u043b\u0435\u043d\u044b \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u044f\u043c\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0412 \u043a\u043e\u043d\u0446\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0412 \u043a\u043e\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 C++11, \u043e\u043d \u0431\u044b\u043b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0441 GCC 4.7 \u0438 Clang 3.2.<\/p>\n<h4>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/h4>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f QML \u0438 \u043c\u0435\u0442\u0430-\u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b Qt \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u0432 \u0432\u0438\u0434\u0435 C++ \u043f\u0440\u0438\u0432\u044f\u0437\u043e\u043a.<br \/>  \u0426\u0435\u043b\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u043b\u0438\u0448\u044c \u0432 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 proof of concept. \u041a\u043e\u0434 \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d, \u044f \u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c.<br \/>  \u0418\u0434\u0435\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <code>property<\/code>, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u0432 QML. \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0432\u043e\u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u041f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0432\u0441\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0432 \u043d\u0435\u0451 <code>property<\/code> \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438.<br \/>  <code>property&lt;T&gt;<\/code> \u2014 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u041e\u0431\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0430 \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 <code>property_base<\/code>.<\/p>\n<pre><code class=\"cpp\">class property_base {   \/* \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e      \u041a\u043e\u0433\u0434\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u044b *\/   std::unordered_set&lt;property_base *&gt; subscribers;    \/* \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 *\/   std::unordered_set&lt;property_base *&gt; dependencies;  public:   virtual ~property_base()   { clearSubscribers(); clearDependencies(); }    \/\/ \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e   virtual void evaluate() = 0;       \/\/ [...] protected:   \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0431\u044b\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e     \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0435 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e *\/   virtual void notify() {     auto copy = subscribers;     for (property_base *p : copy) {       p-&gt;evaluate();     }   }    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443      \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 *\/   void accessed() {     if (current && current != this) {       subscribers.insert(current);       current-&gt;dependencies.insert(this);     }   }    void clearSubscribers() {       for (property_base *p : subscribers)           p-&gt;dependencies.erase(this);       subscribers.clear();   }   void clearDependencies() {       for (property_base *p : dependencies)           p-&gt;subscribers.erase(this);       dependencies.clear();   }    \/* \u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 *\/   struct evaluation_scope {     evaluation_scope(property_base *prop) : previous(current) {       current = prop;     }     ~evaluation_scope() { current = previous; }     property_base *previous;   }; private:   friend struct evaluation_scope;   \/* thread_local *\/ static property_base *current; };<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>property<\/code>.<\/p>\n<pre><code class=\"cpp\">template &lt;typename T&gt; struct property : property_base {   typedef std::function&lt;T()&gt; binding_t;    property() = default;   property(const T &t) : value(t) {}   property(const binding_t &b) : binding(b) { evaluate(); }    void operator=(const T &t) {       value = t;       clearDependencies();       notify();   }   void operator=(const binding_t &b) {       binding = b;       evaluate();   }    const T &get() const {     const_cast&lt;property*&gt;(this)-&gt;accessed();     return value;   }    \/\/ \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435   const T &operator()() const { return get();  }   operator const T&() const { return get(); }    void evaluate() override {     if (binding) {       clearDependencies();       evaluation_scope scope(this);       value = binding();     }     notify();   }  protected:   T value;   binding_t binding; };<\/code><\/pre>\n<p>  <\/p>\n<h5>property_hook<\/h5>\n<p>   \u0416\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>update()<\/code>. \u041a\u043b\u0430\u0441\u0441 <a href=\"http:\/\/woboq.com\/blog\/property-bindings-in-cpp\/code\/src\/property.h.html#property_hook\">property_hook<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/p>\n<h4>\u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 Qt<\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 Qt Widgets.<\/p>\n<h5>property_qobject<\/h5>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u044f \u0432\u0432\u043e\u0436\u0443 <a href=\"http:\/\/woboq.com\/blog\/property-bindings-in-cpp\/code\/src\/property_qobject.h.html#property_qobject\">property_qobject<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043e\u0431\u0451\u0440\u0442\u043a\u043e\u0439 <code>property<\/code> \u0432 <code>QObject<\/code>. \u041e\u043d \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 <code>QObject<\/code> \u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c.<br \/>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u0443\u0442\u0451\u043c \u043e\u0431\u043c\u0435\u043d\u0430 <code>QObject<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0421 Qt 5 \u044f \u0431\u044b \u043c\u043e\u0433 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0445\u0430\u043a\u0430, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b Qt 4.8.<\/p>\n<h5>\u041e\u0431\u0451\u0440\u0442\u043a\u0438<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043e\u0431\u0451\u0440\u0442\u043a\u0438 \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>property_qobject<\/code>.<\/p>\n<h4>\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430 \u0447\u0442\u043e \u043c\u044b \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b:<br \/>  \u042d\u0442\u043e\u0442 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 line edit, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u0437\u0430\u0434\u0430\u0442\u044c \u0446\u0432\u0435\u0442, \u0438 \u0434\u0432\u0430 \u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0430, \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0432\u043e\u0440\u043e\u0442 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/191\/9e8\/51e\/1919e851ef6e2b48f23aa04038df11d9.png\"\/><\/p>\n<p>  \u041f\u0443\u0441\u0442\u044c \u043a\u043e\u0434 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0430\u043c \u0437\u0430 \u0441\u0435\u0431\u044f.<\/p>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430\u043c\u0438:<\/p>\n<pre><code class=\"cpp\">struct GraphicsRectObject : QGraphicsWidget {   \/\/ \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 QObject    property_qobject&lt;QRectF&gt; geometry { this, &quot;geometry&quot; };   property_qobject&lt;qreal&gt; opacity { this, &quot;opacity&quot; };   property_qobject&lt;qreal&gt; rotation { this, &quot;rotation&quot; };    \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0446\u0432\u0435\u0442\u0430 \u0441 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u043e\u0439 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f   property_hook&lt;QColor&gt; color { [this]{ this-&gt;update(); } }; private:   void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*) override {     painter-&gt;setBrush(color());     painter-&gt;drawRect(boundingRect());   } }; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u043a\u043d\u0430 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u043e\u0434\u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"cpp\">struct MyWindow : Widget {   LineEdit colorEdit {this};    Slider rotationSlider {Qt::Horizontal, this};   Slider opacitySlider {Qt::Horizontal, this};    QGraphicsScene scene;   GraphicsView view {&scene, this};   GraphicsRectObject rectangle;    ::property&lt;int&gt; margin {10};    MyWindow() {     \/\/ \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u043d\u043e \u043d\u0435 \u0442\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e, \u043a\u0430\u043a \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 Layout, \u0437\u0430\u0442\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438     colorEdit.geometry = [&]{ return QRect(margin, margin,                                              geometry().width() - 2*margin,                                              colorEdit.sizeHint().height()); };     rotationSlider.geometry = [&]{ return QRect(margin,                                                   colorEdit.geometry().bottom() + margin,                                                   geometry().width() - 2*margin,                                                   rotationSlider.sizeHint().height()); };     opacitySlider.geometry = [&]{ return QRect(margin,                                                  rotationSlider.geometry().bottom() + margin,                                                  geometry().width() - 2*margin,                                                  opacitySlider.sizeHint().height()); };     view.geometry = [&]{         int x = opacitySlider.geometry().bottom() + margin;         return QRect(margin, x, width() - 2*margin, geometry().height() - x - margin);      };      \/\/ \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e     colorEdit.text = QString(&quot;blue&quot;);     rotationSlider.minimum = -180;     rotationSlider.maximum = 180;     opacitySlider.minimum = 0;     opacitySlider.maximum = 100;     opacitySlider.value = 100;      scene.addItem(&rectangle);      \/\/ \u0434\u0430\u043b\u044c\u0448\u0435 - \u043d\u0430\u0448\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438     rectangle.color = [&]{ return QColor(colorEdit.text);  };     rectangle.opacity = [&]{ return qreal(opacitySlider.value\/100.); };     rectangle.rotation = [&]{ return rotationSlider.value(); };   } };  int main(int argc, char **argv) {     QApplication app(argc,argv);     MyWindow window;     window.show();     return app.exec(); }<\/code><\/pre>\n<p>  <\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <a href=\"https:\/\/github.com\/woboq\/property_bindings\">\u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a> \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u0441\u0430\u043c\u0438.<br \/>  \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043b\u0438\u0448\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f; \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0434\u043e \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.        \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/171295\/\"> http:\/\/habrahabr.ru\/post\/171295\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       <img decoding=\"async\" align=\"left\" src=\"http:\/\/habrastorage.org\/storage2\/ebf\/bcd\/b5e\/ebfbcdb5e347d9bb0dc152628ebac79c.png\"\/> QtQuick \u0438 QML \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u044f\u0437\u044b\u043a \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 QML \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b \u0438 \u0443\u0434\u043e\u0431\u043d\u044b. \u0414\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u0435\u043d \u0432 \u0440\u0430\u0431\u043e\u0442\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430 C++? \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c C++.<\/p>\n<p>  <i>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/i> \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u0431\u0430\u0432\u044b, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-171295","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/171295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171295"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/171295\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}