sms

dragon

sms
Jan 4th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void MainWindow::refresh_template_view() {
  2.     ui->row_box->setDisabled(true);
  3.     ui->save_template->setDisabled(true);
  4.     ui->page_box->setDisabled(true);
  5.     ui->cols_selection->setDisabled(true);
  6.     ui->rows_selection->setDisabled(true);
  7.     ui->section_box->setDisabled(true);
  8.     ui->obj_selection->setDisabled(true);
  9.  
  10.     QGraphicsScene * scene;
  11.     if (ui->graphicsView->scene() != Q_NULLPTR) {
  12.         scene = ui->graphicsView->scene();
  13.         scene->clear();
  14.     }
  15.     else {
  16.         scene = new QGraphicsScene(ui->graphicsView);
  17.         ui->graphicsView->setScene(scene);
  18.     }
  19.  
  20.     if (template_ptr != Q_NULLPTR) {
  21.         ui->vertical_width->setValue(0);
  22.         ui->vertical_width->setMaximum(template_ptr->page_width);
  23.         ui->vertical_width->setValue(template_ptr->page_width);
  24.  
  25.         QRectF sceneRect = QRectF(QPointF(5.0, 5.0), QSizeF(template_ptr->page_width*2.0, template_ptr->page_height*2.0*5));
  26.  
  27.         scene->setSceneRect(sceneRect);
  28.  
  29.         //scene->addRect(sceneRect, QPen(QBrush(QColor(Qt::gray)), 1));
  30.  
  31.         ui->save_template->setEnabled(true);
  32.         ui->page_box->setEnabled(true);
  33.         ui->rows_selection->setEnabled(true);
  34.  
  35.         if (template_ptr->sections.length() < selected_row + 1 && selected_row != -1) {
  36.             select_row(); return;
  37.         }
  38.         if (selected_row >= 0) {
  39.             if (template_ptr->sections.at(selected_row).fields.length() < selected_col + 1 && selected_col != -1) {
  40.                 select_col(); return;
  41.             }
  42.         }
  43.  
  44.         ui->row_4->setDisabled(true);
  45.         ui->row_3->setDisabled(true);
  46.         ui->row_2->setDisabled(true);
  47.         ui->row_1->setDisabled(true);
  48.         ui->row_0->setDisabled(true);
  49.         ui->row_null->setDisabled(true);
  50.  
  51.         ui->col_4->setDisabled(true);
  52.         ui->col_3->setDisabled(true);
  53.         ui->col_2->setDisabled(true);
  54.         ui->col_1->setDisabled(true);
  55.         ui->col_0->setDisabled(true);
  56.         ui->col_null->setDisabled(true);
  57.  
  58.         ui->obj_10->setDisabled(true);
  59.         ui->obj_9->setDisabled(true);
  60.         ui->obj_8->setDisabled(true);
  61.         ui->obj_7->setDisabled(true);
  62.         ui->obj_6->setDisabled(true);
  63.         ui->obj_5->setDisabled(true);
  64.         ui->obj_4->setDisabled(true);
  65.         ui->obj_3->setDisabled(true);
  66.         ui->obj_2->setDisabled(true);
  67.         ui->obj_1->setDisabled(true);
  68.         ui->obj_0->setDisabled(true);
  69.         ui->obj_null->setDisabled(true);
  70.  
  71.         switch (template_ptr->sections.length()) {
  72.         case 5:
  73.             ui->row_4->setEnabled(true);
  74.         case 4:
  75.             ui->row_3->setEnabled(true);
  76.         case 3:
  77.             ui->row_2->setEnabled(true);
  78.         case 2:
  79.             ui->row_1->setEnabled(true);
  80.         case 1:
  81.             ui->row_0->setEnabled(true);
  82.         default:
  83.             ui->row_null->setEnabled(true);
  84.         }
  85.  
  86.         if (selected_row >= 0) {
  87.             ui->row_box->setEnabled(true);
  88.             ui->cols_selection->setEnabled(true);
  89.             switch (template_ptr->sections.at(selected_row).fields.length()) {
  90.             case 5:
  91.                 ui->col_4->setEnabled(true);
  92.             case 4:
  93.                 ui->col_3->setEnabled(true);
  94.             case 3:
  95.                 ui->col_2->setEnabled(true);
  96.             case 2:
  97.                 ui->col_1->setEnabled(true);
  98.             case 1:
  99.                 ui->col_0->setEnabled(true);
  100.             default:
  101.                 ui->col_null->setEnabled(true);
  102.             }
  103.  
  104.             if (selected_col >= 0) {
  105.                 ui->section_box->setEnabled(true);
  106.                 ui->obj_selection->setEnabled(true);
  107.                 switch (template_ptr->sections.at(selected_row).fields.at(selected_col).objects.length()) {
  108.                 case 11:
  109.                     ui->obj_10->setEnabled(true);
  110.                 case 10:
  111.                     ui->obj_9->setEnabled(true);
  112.                 case 9:
  113.                     ui->obj_8->setEnabled(true);
  114.                 case 8:
  115.                     ui->obj_7->setEnabled(true);
  116.                 case 7:
  117.                     ui->obj_6->setEnabled(true);
  118.                 case 6:
  119.                     ui->obj_5->setEnabled(true);
  120.                 case 5:
  121.                     ui->obj_4->setEnabled(true);
  122.                 case 4:
  123.                     ui->obj_3->setEnabled(true);
  124.                 case 3:
  125.                     ui->obj_2->setEnabled(true);
  126.                 case 2:
  127.                     ui->obj_1->setEnabled(true);
  128.                 case 1:
  129.                     ui->obj_0->setEnabled(true);
  130.                 default:
  131.                     ui->obj_null->setEnabled(true);
  132.                 }
  133.             }
  134.         }
  135.  
  136.         qint32 row_h = static_cast<qint32>(static_cast<qreal>(template_ptr->page_height*2)/static_cast<qreal>(template_ptr->sections.length()));
  137.  
  138.         qint32 taken = 0;
  139.         qint32 default_taken = 0;
  140.  
  141.         if (template_ptr->sections.length() == 0) {
  142.             QGraphicsRectItem * item = ui->graphicsView->scene()->addRect(
  143.                         QRectF(QPointF(5.0, 15.0),
  144.                                QSizeF(static_cast<qreal>(template_ptr->page_width*2), static_cast<qreal>(template_ptr->page_height*2))),
  145.                         QPen(QBrush(QColor(Qt::black)), 1.0));
  146.             item->setZValue(1);
  147.         }
  148.  
  149.         for (qint32 i = 0; i != template_ptr->sections.length(); ++i) {
  150.             const HorizontalSection& row = template_ptr->sections.at(i);
  151.             if (i == template_ptr->sections.length() - 1)
  152.                 row_h = template_ptr->page_height*2 - default_taken;
  153.  
  154.             qint32 j_taken = 0;
  155.             qint32 big_h = row_h;
  156.  
  157.             QList<QGraphicsRectItem*> cols;
  158.  
  159.             for (qint32 j = 0; j != row.fields.length(); ++j) {
  160.                 const VerticalField& col = row.fields.at(j);
  161.  
  162.                 qint32 k_taken = 0;
  163.  
  164.                 for (qint32 k = 0; k != col.objects.length(); ++k) {
  165.                     const FieldObject obj = col.objects.at(k);
  166.  
  167.                     QStringList a;
  168.                     if (result != Q_NULLPTR) {
  169.                         for (const ConditionType& condition : obj.get_condition_types()) {
  170.                             a.append(result->get_state(condition));
  171.                         }
  172.                     }
  173.                     else {
  174.                         qDebug() << "NULL result";
  175.                     }
  176.  
  177.                     if (obj.get_object_type() == ObjectType::TEXT) {
  178.                         const QList<TextObject> txts = obj.get_text_objects();
  179.  
  180.                         QString object_text;
  181.                         QFont object_font;
  182.                         QColor object_color = QColor(Qt::black);
  183.  
  184.                         if (txts.length() == 1) {
  185.                             object_text = txts.first().text;
  186.                             object_font = txts.first().font;
  187.                             object_color = txts.first().color;
  188.                         }
  189.                         else {
  190.                             object_text = txts.first().text;
  191.                             bool same_font = true;
  192.                             bool same_color = true;
  193.                             for (const TextObject& a : txts) {
  194.                                 for (const TextObject& b : txts) {
  195.                                     if (a.font != b.font) {
  196.                                         same_font = false;
  197.                                     }
  198.                                     if (a.color != b.color) {
  199.                                         same_color = false;
  200.                                     }
  201.                                 }
  202.                             }
  203.                             if (same_font) {
  204.                                 object_font = txts.first().font;
  205.                             }
  206.                             if (same_color) {
  207.                                 object_color = txts.first().color;
  208.                             }
  209.                         }
  210.  
  211.                         if (result != Q_NULLPTR) {
  212.                             std::sort(a.begin(), a.end());
  213.                             for (const TextObject& txt : txts) {
  214.                                 QStringList b = txt.combined_state;
  215.                                 std::sort(b.begin(), b.end());
  216.                                 if (a == b) {
  217.                                     object_text = txt.text;
  218.  
  219.                                     QRegularExpression re("(~)([0-9]{1,2})");
  220.                                     QRegularExpressionMatch match = re.match(object_text);
  221.                                     while (match.hasMatch()) {
  222.                                         bool conv;
  223.                                         qint32 var = match.captured(2).toInt(&conv);
  224.                                         QString after;
  225.                                         if (conv && var >= 0) {
  226.                                             switch (var + 1) {
  227.                                             case static_cast<qint32>(TextVariable::TOPIC_NAME): {
  228.                                                 after = result->get_raw_topic().topic_name;
  229.                                                 break;
  230.                                             }
  231.                                             case static_cast<qint32>(TextVariable::REGULAR_QUORUM_VALUE): {
  232.                                                 if (result->get_raw_topic().use_regular_quorum)
  233.                                                     after = QString::number(result->get_raw_topic().regular_quorum_value);
  234.                                                 break;
  235.                                             }
  236.                                             case static_cast<qint32>(TextVariable::REGULAR_QUORUM_PERCENTAGE): {
  237.                                                 if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 2)
  238.                                                     after = QString::number(result->get_raw_topic().regular_quorum_percentage);
  239.                                                 break;
  240.                                             }
  241.                                             case static_cast<qint32>(TextVariable::REGULAR_QUORUM_NUMERATOR): {
  242.                                                 if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 3)
  243.                                                     after = QString::number(result->get_raw_topic().regular_quorum_numerator);
  244.                                                 break;
  245.                                             }
  246.                                             case static_cast<qint32>(TextVariable::REGULAR_QUORUM_DENOMINATOR): {
  247.                                                 if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 3)
  248.                                                     after = QString::number(result->get_raw_topic().regular_quorum_denominator);
  249.                                                 break;
  250.                                             }
  251.                                             case static_cast<qint32>(TextVariable::SHARES_QUORUM_VALUE): {
  252.                                                 if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 1)
  253.                                                     after = QString::number(result->get_raw_topic().shares_quorum_value);
  254.                                                 break;
  255.                                             }
  256.                                             case static_cast<qint32>(TextVariable::SHARES_QUORUM_PERCENTAGE): {
  257.                                                 if (result->get_raw_topic().use_shares_quorum && result->get_raw_topic().shares_quorum_type == 2)
  258.                                                     after = QString::number(result->get_raw_topic().shares_quorum_percentage);
  259.                                                 break;
  260.                                             }
  261.                                             case static_cast<qint32>(TextVariable::SHARES_QUORUM_NUMERATOR): {
  262.                                                 if (result->get_raw_topic().use_shares_quorum && result->get_raw_topic().shares_quorum_type == 3)
  263.                                                     after = QString::number(result->get_raw_topic().shares_quorum_numerator);
  264.                                                 break;
  265.                                             }
  266.                                             case static_cast<qint32>(TextVariable::SHARES_QUORUM_DENOMINATOR): {
  267.                                                 if (result->get_raw_topic().use_shares_quorum && result->get_raw_topic().shares_quorum_type == 3)
  268.                                                     after = QString::number(result->get_raw_topic().shares_quorum_denominator);
  269.                                                 break;
  270.                                             }
  271.                                             case static_cast<qint32>(TextVariable::SUPERMAJORITY_PERCENTAGE): {
  272.                                                 if ((result->get_raw_topic().majority == 4
  273.                                                         || result->get_raw_topic().majority == 5
  274.                                                         || result->get_raw_topic().majority == 6)
  275.                                                         && result->get_raw_topic().supermajority_type == 2)
  276.                                                     after = QString::number(result->get_raw_topic().supermajority_percentage);
  277.                                                 break;
  278.                                             }
  279.                                             case static_cast<qint32>(TextVariable::SUPERMAJORITY_NUMERATOR): {
  280.                                                 if ((result->get_raw_topic().majority == 4
  281.                                                         || result->get_raw_topic().majority == 5
  282.                                                         || result->get_raw_topic().majority == 6)
  283.                                                         && result->get_raw_topic().supermajority_type == 3)
  284.                                                     after = QString::number(result->get_raw_topic().supermajority_numerator);
  285.                                                 break;
  286.                                             }
  287.                                             case static_cast<qint32>(TextVariable::SUPERMAJORITY_DENOMINATOR): {
  288.                                                 if ((result->get_raw_topic().majority == 4
  289.                                                         || result->get_raw_topic().majority == 5
  290.                                                         || result->get_raw_topic().majority == 6)
  291.                                                         && result->get_raw_topic().supermajority_type == 3)
  292.                                                     after = QString::number(result->get_raw_topic().supermajority_denominator);
  293.                                                 break;
  294.                                             }
  295.                                             case static_cast<qint32>(TextVariable::TALK_START_TIME): {
  296.                                                 if (result->get_raw_topic().get_talk_start() != Q_NULLPTR) {
  297.                                                     if (result->get_raw_topic().get_talk_start()->isValid()
  298.                                                             && !result->get_raw_topic().get_talk_start()->isNull()) {
  299.                                                         after = result->get_raw_topic().get_talk_start()->time().toString();
  300.                                                     }
  301.                                                 }
  302.                                                 break;
  303.                                             }
  304.                                             case static_cast<qint32>(TextVariable::TALK_END_TIME): {
  305.                                                 if (result->get_raw_topic().get_talk_end() != Q_NULLPTR) {
  306.                                                     if (result->get_raw_topic().get_talk_end()->isValid()
  307.                                                             && !result->get_raw_topic().get_talk_end()->isNull()) {
  308.                                                         after = result->get_raw_topic().get_talk_end()->time().toString();
  309.                                                     }
  310.                                                 }
  311.                                                 break;
  312.                                             }
  313.                                             case static_cast<qint32>(TextVariable::VOTE_START_TIME): {
  314.                                                 if (result->get_raw_topic().get_vote_start() != Q_NULLPTR) {
  315.                                                     if (result->get_raw_topic().get_vote_start()->isValid()
  316.                                                             && !result->get_raw_topic().get_vote_start()->isNull()) {
  317.                                                         after = result->get_raw_topic().get_vote_start()->time().toString();
  318.                                                     }
  319.                                                 }
  320.                                                 break;
  321.                                             }
  322.                                             case static_cast<qint32>(TextVariable::VOTE_END_TIME): {
  323.                                                 if (result->get_raw_topic().get_vote_end() != Q_NULLPTR) {
  324.                                                     if (result->get_raw_topic().get_vote_end()->isValid()
  325.                                                             && !result->get_raw_topic().get_vote_end()->isNull()) {
  326.                                                         after = result->get_raw_topic().get_vote_end()->time().toString();
  327.                                                     }
  328.                                                 }
  329.                                                 break;
  330.                                             }
  331.                                             case static_cast<qint32>(TextVariable::TALK_START_DATE): {
  332.                                                 if (result->get_raw_topic().get_talk_start() != Q_NULLPTR) {
  333.                                                     if (result->get_raw_topic().get_talk_start()->isValid()
  334.                                                             && !result->get_raw_topic().get_talk_start()->isNull()) {
  335.                                                         after = result->get_raw_topic().get_talk_start()->date().toString();
  336.                                                     }
  337.                                                 }
  338.                                                 break;
  339.                                             }
  340.                                             case static_cast<qint32>(TextVariable::TALK_END_DATE): {
  341.                                                 if (result->get_raw_topic().get_talk_end() != Q_NULLPTR) {
  342.                                                     if (result->get_raw_topic().get_talk_end()->isValid()
  343.                                                             && !result->get_raw_topic().get_talk_end()->isNull()) {
  344.                                                         after = result->get_raw_topic().get_talk_end()->date().toString();
  345.                                                     }
  346.                                                 }
  347.                                                 break;
  348.                                             }
  349.                                             case static_cast<qint32>(TextVariable::VOTE_START_DATE): {
  350.                                                 if (result->get_raw_topic().get_vote_start() != Q_NULLPTR) {
  351.                                                     if (result->get_raw_topic().get_vote_start()->isValid()
  352.                                                             && !result->get_raw_topic().get_vote_start()->isNull()) {
  353.                                                         after = result->get_raw_topic().get_vote_start()->date().toString();
  354.                                                     }
  355.                                                 }
  356.                                                 break;
  357.                                             }
  358.                                             case static_cast<qint32>(TextVariable::VOTE_END_DATE): {
  359.                                                 if (result->get_raw_topic().get_vote_end() != Q_NULLPTR) {
  360.                                                     if (result->get_raw_topic().get_vote_end()->isValid()
  361.                                                             && !result->get_raw_topic().get_vote_end()->isNull()) {
  362.                                                         after = result->get_raw_topic().get_vote_end()->date().toString();
  363.                                                     }
  364.                                                 }
  365.                                                 break;
  366.                                             }
  367.                                             case static_cast<qint32>(TextVariable::PRESENT_NO): {
  368.                                                 qint32 out = 0;
  369.                                                 for (const Vote& vote : result->get_votes()) {
  370.                                                     if (vote.get_was_present()) {
  371.                                                         out++;
  372.                                                     }
  373.                                                 }
  374.                                                 after = QString::number(out);
  375.                                                 break;
  376.                                             }
  377.                                             case static_cast<qint32>(TextVariable::VOTES_NO): {
  378.                                                 qint32 out = 0;
  379.                                                 for (const Vote& vote : result->get_votes()) {
  380.                                                     if (vote.get_was_voting()) {
  381.                                                         out++;
  382.                                                     }
  383.                                                 }
  384.                                                 after = QString::number(out);
  385.                                                 break;
  386.                                             }
  387.                                             case static_cast<qint32>(TextVariable::YES_NO): {
  388.                                                 qint32 out = 0;
  389.                                                 for (const Vote& vote : result->get_votes()) {
  390.                                                     if (vote.get_was_yes()) {
  391.                                                         out++;
  392.                                                     }
  393.                                                 }
  394.                                                 after = QString::number(out);
  395.                                                 break;
  396.                                             }
  397.                                             case static_cast<qint32>(TextVariable::NO_NO): {
  398.                                                 qint32 out = 0;
  399.                                                 for (const Vote& vote : result->get_votes()) {
  400.                                                     if (vote.get_was_no()) {
  401.                                                         out++;
  402.                                                     }
  403.                                                 }
  404.                                                 after = QString::number(out);
  405.                                                 break;
  406.                                             }
  407.                                             case static_cast<qint32>(TextVariable::ABS_NO): {
  408.                                                 qint32 out = 0;
  409.                                                 for (const Vote& vote : result->get_votes()) {
  410.                                                     if (vote.get_was_abs()) {
  411.                                                         out++;
  412.                                                     }
  413.                                                 }
  414.                                                 after = QString::number(out);
  415.                                                 break;
  416.                                             }
  417.                                             case static_cast<qint32>(TextVariable::NULL_NO): {
  418.                                                 qint32 out = 0;
  419.                                                 for (const Vote& vote : result->get_votes()) {
  420.                                                     if (!(vote.get_was_yes()
  421.                                                             || vote.get_was_no()
  422.                                                             || vote.get_was_abs())
  423.                                                             && vote.get_was_present()) {
  424.                                                         out++;
  425.                                                     }
  426.                                                 }
  427.                                                 after = QString::number(out);
  428.                                                 break;
  429.                                             }
  430.                                             case static_cast<qint32>(TextVariable::NULL_ABS_NO): {
  431.                                                 qint32 out = 0;
  432.                                                 for (const Vote& vote : result->get_votes()) {
  433.                                                     if (!(vote.get_was_yes()
  434.                                                             || vote.get_was_no())
  435.                                                             && vote.get_was_present()) {
  436.                                                         out++;
  437.                                                     }
  438.                                                 }
  439.                                                 after = QString::number(out);
  440.                                                 break;
  441.                                             }
  442.                                             case static_cast<qint32>(TextVariable::POWER_PRESENT): {
  443.                                                 qint32 out = 0;
  444.                                                 for (const Vote& vote : result->get_votes()) {
  445.                                                     if (vote.get_was_present()
  446.                                                             && vote.get_raw_vote() != Q_NULLPTR
  447.                                                             && result->get_raw_topic().use_shares) {
  448.                                                         out += vote.get_raw_vote()->vote_power;
  449.                                                     }
  450.                                                 }
  451.                                                 after = QString::number(out);
  452.                                                 break;
  453.                                             }
  454.                                             case static_cast<qint32>(TextVariable::POWER_VOTED): {
  455.                                                 qint32 out = 0;
  456.                                                 for (const Vote& vote : result->get_votes()) {
  457.                                                     if (vote.get_was_voting()
  458.                                                             && vote.get_raw_vote() != Q_NULLPTR
  459.                                                             && result->get_raw_topic().use_shares) {
  460.                                                         out += vote.get_raw_vote()->vote_power;
  461.                                                     }
  462.                                                 }
  463.                                                 after = QString::number(out);
  464.                                                 break;
  465.                                             }
  466.                                             case static_cast<qint32>(TextVariable::POWER_YES): {
  467.                                                 qint32 out = 0;
  468.                                                 for (const Vote& vote : result->get_votes()) {
  469.                                                     if (vote.get_was_yes()
  470.                                                             && vote.get_raw_vote() != Q_NULLPTR
  471.                                                             && result->get_raw_topic().use_shares) {
  472.                                                         out += vote.get_raw_vote()->vote_power;
  473.                                                     }
  474.                                                 }
  475.                                                 after = QString::number(out);
  476.                                                 break;
  477.                                             }
  478.                                             case static_cast<qint32>(TextVariable::POWER_NO): {
  479.                                                 qint32 out = 0;
  480.                                                 for (const Vote& vote : result->get_votes()) {
  481.                                                     if (vote.get_was_no()
  482.                                                             && vote.get_raw_vote() != Q_NULLPTR
  483.                                                             && result->get_raw_topic().use_shares) {
  484.                                                         out += vote.get_raw_vote()->vote_power;
  485.                                                     }
  486.                                                 }
  487.                                                 after = QString::number(out);
  488.                                                 break;
  489.                                             }
  490.                                             case static_cast<qint32>(TextVariable::POWER_ABS): {
  491.                                                 qint32 out = 0;
  492.                                                 for (const Vote& vote : result->get_votes()) {
  493.                                                     if (vote.get_was_abs()
  494.                                                             && vote.get_raw_vote() != Q_NULLPTR
  495.                                                             && result->get_raw_topic().use_shares) {
  496.                                                         out += vote.get_raw_vote()->vote_power;
  497.                                                     }
  498.                                                 }
  499.                                                 after = QString::number(out);
  500.                                                 break;
  501.                                             }
  502.                                             case static_cast<qint32>(TextVariable::POWER_NULL): {
  503.                                                 qint32 out = 0;
  504.                                                 for (const Vote& vote : result->get_votes()) {
  505.                                                     if (!(vote.get_was_yes()
  506.                                                           || vote.get_was_no()
  507.                                                           || vote.get_was_abs())
  508.                                                           && vote.get_was_present()
  509.                                                             && vote.get_raw_vote() != Q_NULLPTR
  510.                                                             && result->get_raw_topic().use_shares) {
  511.                                                         out += vote.get_raw_vote()->vote_power;
  512.                                                     }
  513.                                                 }
  514.                                                 after = QString::number(out);
  515.                                                 break;
  516.                                             }
  517.                                             case static_cast<qint32>(TextVariable::POWER_NULL_ABS): {
  518.                                                 qint32 out = 0;
  519.                                                 for (const Vote& vote : result->get_votes()) {
  520.                                                     if (!(vote.get_was_yes()
  521.                                                           || vote.get_was_no())
  522.                                                           && vote.get_was_present()
  523.                                                             && vote.get_raw_vote() != Q_NULLPTR
  524.                                                             && result->get_raw_topic().use_shares) {
  525.                                                         out += vote.get_raw_vote()->vote_power;
  526.                                                     }
  527.                                                 }
  528.                                                 after = QString::number(out);
  529.                                                 break;
  530.                                             }
  531.                                             default: {
  532.                                                 break;
  533.                                             }
  534.                                             }
  535.                                         }
  536.  
  537.                                         if (after.length() == 0) {
  538.                                             after = "X";
  539.                                         }
  540.  
  541.                                         object_text = object_text.replace("~" + QString::number(var), after);
  542.                                         match = re.match(object_text);
  543.                                     }
  544.  
  545.                                     object_font = txt.font;
  546.                                     object_color = txt.color;
  547.                                     break;
  548.                                 }
  549.                             }
  550.                         }
  551.  
  552.                         QGraphicsTextItem * obj_item = ui->graphicsView->scene()->addText(
  553.                                     object_text,
  554.                                     object_font);
  555.                         obj_item->setDefaultTextColor(object_color);
  556.                         obj_item->setTextWidth(col.width*2);
  557.                         obj_item->setPos(QPointF(5.0 + j_taken, 15.0 + taken + k_taken));
  558.                         obj_item->setZValue(7);
  559.                         k_taken += obj_item->boundingRect().height();
  560.                         if (j == selected_col && i == selected_row && k == selected_obj) {
  561.                             QGraphicsRectItem * obj_rect = ui->graphicsView->scene()->addRect(
  562.                                         obj_item->pos().x() + 1.0,
  563.                                         obj_item->pos().y() + 1.0,
  564.                                         obj_item->boundingRect().width() - 2.0,
  565.                                         obj_item->boundingRect().height() - 2.0,
  566.                                         QPen(QBrush(QColor(Qt::red)), 1.0));
  567.                             obj_rect->setZValue(6);
  568.                         }
  569.                     }
  570.                     else if (obj.get_object_type() == ObjectType::LIST) {
  571.                         if (result != Q_NULLPTR) {
  572.                             const QList<ListObject> lsts = obj.get_list_objects();
  573.                             std::sort(a.begin(), a.end());
  574.                             for (const ListObject& lst : lsts) {
  575.                                 QStringList b = lst.combined_state;
  576.                                 std::sort(b.begin(), b.end());
  577.                                 if (a == b) {
  578.                                     qint32 l_taken = 0;
  579.                                     qint32 row_no = 0;
  580.                                     qint32 x_1st, y_1st, w_1st;
  581.                                     for (const Vote& vote : result->get_votes()) {
  582.                                         QFont object_font;
  583.                                         QColor object_color;
  584.                                         QString object_text;
  585.                                         bool use_row = false;
  586.                                         switch(lst.list_type) {
  587.                                         case ListType::PRESENT: {
  588.                                             if (vote.get_was_present()) {
  589.                                                 use_row = true;
  590.                                             }
  591.                                             break;
  592.                                         }
  593.                                         case ListType::PRESENT_VOTED: {
  594.                                             if (vote.get_was_voting()) {
  595.                                                 use_row = true;
  596.                                             }
  597.                                             break;
  598.                                         }
  599.                                         case ListType::PRESENT_VOTES: {
  600.                                             if (vote.get_was_present()) {
  601.                                                 use_row = true;
  602.                                             }
  603.                                             break;
  604.                                         }
  605.                                         case ListType::CLICKVOTED:
  606.                                         case ListType::CLICKVOTED_VOTES: {
  607.                                             if (vote.get_was_yes()
  608.                                                     || vote.get_was_no()
  609.                                                     || vote.get_was_abs()) {
  610.                                                 use_row = true;
  611.                                             }
  612.                                             break;
  613.                                         }
  614.                                         case ListType::YES: {
  615.                                             if (vote.get_was_yes()) {
  616.                                                 use_row = true;
  617.                                             }
  618.                                             break;
  619.                                         }
  620.                                         case ListType::NO: {
  621.                                             if (vote.get_was_no()) {
  622.                                                 use_row = true;
  623.                                             }
  624.                                             break;
  625.                                         }
  626.                                         case ListType::ABS: {
  627.                                             if (vote.get_was_abs()) {
  628.                                                 use_row = true;
  629.                                             }
  630.                                             break;
  631.                                         }
  632.                                         case ListType::NULLVOTED: {
  633.                                             if (vote.get_was_voting()
  634.                                                     && !vote.get_was_yes()
  635.                                                     && !vote.get_was_no()
  636.                                                     && !vote.get_was_abs()) {
  637.                                                 use_row = true;
  638.                                             }
  639.                                             break;
  640.                                         }
  641.                                         case ListType::NULLVOTED_AND_ABS: {
  642.                                             if (vote.get_was_voting()
  643.                                                     && vote.get_was_abs()) {
  644.                                                 use_row = true;
  645.                                             }
  646.                                             break;
  647.                                         }
  648.                                         default: {
  649.                                             use_row = false;
  650.                                         }
  651.                                         }
  652.                                         if (use_row) {
  653.                                             row_no++;
  654.  
  655.                                             switch(lst.list_type) {
  656.                                             case ListType::ABS:
  657.                                             case ListType::NO:
  658.                                             case ListType::YES:
  659.                                             case ListType::CLICKVOTED:
  660.                                             case ListType::NULLVOTED:
  661.                                             case ListType::PRESENT:
  662.                                             {
  663.                                                 if (row_no % 2 == 0) {
  664.                                                     object_font = lst.row_fonts.at(0);
  665.                                                     object_color = lst.colors.at(0);
  666.                                                     object_text = lst.row_texts.at(0);
  667.                                                 }
  668.                                                 else {
  669.                                                     object_font = lst.row_fonts.at(1);
  670.                                                     object_color = lst.colors.at(1);
  671.                                                     object_text = lst.row_texts.at(1);
  672.                                                 }
  673.                                                 break;
  674.                                             }
  675.                                             case ListType::CLICKVOTED_VOTES:
  676.                                             {
  677.                                                 if (vote.get_was_abs()) {
  678.                                                     object_font = lst.row_fonts.at(0);
  679.                                                     object_color = lst.colors.at(0);
  680.                                                     object_text = lst.row_texts.at(0);
  681.                                                 }
  682.                                                 else if (vote.get_was_no()) {
  683.                                                     object_font = lst.row_fonts.at(1);
  684.                                                     object_color = lst.colors.at(1);
  685.                                                     object_text = lst.row_texts.at(1);
  686.                                                 }
  687.                                                 else if (vote.get_was_yes()) {
  688.                                                     object_font = lst.row_fonts.at(2);
  689.                                                     object_color = lst.colors.at(2);
  690.                                                     object_text = lst.row_texts.at(2);
  691.                                                 }
  692.                                                 break;
  693.                                             }
  694.                                             case ListType::PRESENT_VOTES:
  695.                                             {
  696.                                                 if (vote.get_was_abs()) {
  697.                                                     object_font = lst.row_fonts.at(0);
  698.                                                     object_color = lst.colors.at(0);
  699.                                                     object_text = lst.row_texts.at(0);
  700.                                                 }
  701.                                                 else if (vote.get_was_no()) {
  702.                                                     object_font = lst.row_fonts.at(1);
  703.                                                     object_color = lst.colors.at(1);
  704.                                                     object_text = lst.row_texts.at(1);
  705.                                                 }
  706.                                                 else if (vote.get_was_yes()) {
  707.                                                     object_font = lst.row_fonts.at(2);
  708.                                                     object_color = lst.colors.at(2);
  709.                                                     object_text = lst.row_texts.at(2);
  710.                                                 }
  711.                                                 else {
  712.                                                     object_font = lst.row_fonts.at(3);
  713.                                                     object_color = lst.colors.at(3);
  714.                                                     object_text = lst.row_texts.at(3);
  715.                                                 }
  716.                                                 break;
  717.                                             }
  718.                                             case ListType::PRESENT_VOTED:
  719.                                             {
  720.                                                 if (vote.get_was_abs()
  721.                                                         || vote.get_was_no()
  722.                                                         || vote.get_was_yes()) {
  723.                                                     object_font = lst.row_fonts.at(0);
  724.                                                     object_color = lst.colors.at(0);
  725.                                                     object_text = lst.row_texts.at(0);
  726.                                                 }
  727.                                                 else {
  728.                                                     object_font = lst.row_fonts.at(1);
  729.                                                     object_color = lst.colors.at(1);
  730.                                                     object_text = lst.row_texts.at(1);
  731.                                                 }
  732.                                                 break;
  733.                                             }
  734.                                             case ListType::NULLVOTED_AND_ABS:
  735.                                             {
  736.                                                 if (vote.get_was_abs()) {
  737.                                                     object_font = lst.row_fonts.at(0);
  738.                                                     object_color = lst.colors.at(0);
  739.                                                     object_text = lst.row_texts.at(0);
  740.                                                 }
  741.                                                 else {
  742.                                                     object_font = lst.row_fonts.at(1);
  743.                                                     object_color = lst.colors.at(1);
  744.                                                     object_text = lst.row_texts.at(1);
  745.                                                 }
  746.                                                 break;
  747.                                             }
  748.                                             default: {}
  749.                                             }
  750.  
  751.                                             QRegularExpression re("(~)([0-9]{1,2})");
  752.                                             QRegularExpressionMatch match = re.match(object_text);
  753.                                             while (match.hasMatch()) {
  754.                                                 bool conv;
  755.                                                 qint32 var = match.captured(2).toInt(&conv);
  756.                                                 QString after;
  757.                                                 if (conv && var >= 0) {
  758.                                                     switch (var + 1) {
  759.                                                     case static_cast<qint32>(ListVariable::NALE_1ST): {
  760.                                                         after = vote.get_raw_debater()->copy_name_1st;
  761.                                                         break;
  762.                                                     }
  763.                                                     case static_cast<qint32>(ListVariable::NAME_LAST): {
  764.                                                         after = vote.get_raw_debater()->copy_name_last;
  765.                                                         break;
  766.                                                     }
  767.                                                     case static_cast<qint32>(ListVariable::SHORT_1ST): {
  768.                                                         QString short_1st = vote.get_raw_debater()->copy_name_1st;
  769.                                                         short_1st.remove(1, short_1st.length() - 2);
  770.                                                         after = short_1st;
  771.                                                         break;
  772.                                                     }
  773.                                                     case static_cast<qint32>(ListVariable::SHORT_LAST): {
  774.                                                         QString short_last = vote.get_raw_debater()->copy_name_last;
  775.                                                         short_last.remove(1, short_last.length() - 2);
  776.                                                         after = short_last;
  777.                                                         break;
  778.                                                     }
  779.                                                     case static_cast<qint32>(ListVariable::ORDER_NO): {
  780.                                                         after = QString::number(row_no);
  781.                                                         break;
  782.                                                     }
  783.                                                     case static_cast<qint32>(ListVariable::VOTE_POWER): {
  784.                                                         after = QString::number(vote.get_raw_vote()->vote_power);
  785.                                                         break;
  786.                                                     }
  787.                                                     default: {
  788.                                                         break;
  789.                                                     }
  790.                                                     }
  791.                                                 }
  792.  
  793.                                                 if (after.length() == 0) {
  794.                                                     after = "X";
  795.                                                 }
  796.                                                 object_text = object_text.replace("~" + QString::number(var), after);
  797.                                                 match = re.match(object_text);
  798.                                             }
  799.  
  800.                                             QGraphicsTextItem * row_item = ui->graphicsView->scene()->addText(
  801.                                                         object_text,
  802.                                                         object_font);
  803.                                             row_item->setDefaultTextColor(object_color);
  804.                                             row_item->setTextWidth(col.width*2);
  805.                                             row_item->setPos(QPointF(5.0 + j_taken, 15.0 + taken + k_taken));
  806.                                             row_item->setZValue(7);
  807.                                             l_taken += row_item->boundingRect().height();
  808.                                             k_taken += row_item->boundingRect().height();
  809.                                             if (row_no == 1) {
  810.                                                 x_1st = row_item->pos().x();
  811.                                                 y_1st = row_item->pos().y();
  812.                                                 w_1st = row_item->boundingRect().width();
  813.                                             }
  814.                                             if (w_1st < row_item->boundingRect().width()) {
  815.                                                 w_1st = row_item->boundingRect().width();
  816.                                             }
  817.                                         }
  818.                                     }
  819.                                     if (j == selected_col && i == selected_row && k == selected_obj && row_no > 0) {
  820.                                         QGraphicsRectItem * obj_rect = ui->graphicsView->scene()->addRect(
  821.                                                     x_1st + 1.0,
  822.                                                     y_1st + 1.0,
  823.                                                     w_1st - 2.0,
  824.                                                     l_taken - 2.0,
  825.                                                     QPen(QBrush(QColor(Qt::red)), 1.0));
  826.                                         obj_rect->setZValue(6);
  827.                                     }
  828.                                     break;
  829.                                 }
  830.                             }
  831.                         }
  832.                     }
  833.                 }
  834.  
  835.                 qint32 height = row_h;
  836.                 if (k_taken > height) {
  837.                     height = k_taken;
  838.                 }
  839.  
  840.                 if (height > big_h) {
  841.                     big_h = height;
  842.                 }
  843.  
  844.                 QGraphicsRectItem * col_item = ui->graphicsView->scene()->addRect(
  845.                             QRectF(QPointF(5.0 + static_cast<qreal>(j_taken), 15.0 + static_cast<qreal>(taken)),
  846.                                    QSizeF(static_cast<qreal>(col.width*2), static_cast<qreal>(height))),
  847.                             QPen(QBrush(QColor(Qt::gray)), 1.0), QBrush(QColor(Qt::white)));
  848.                 cols.append(col_item);
  849.                 col_item->setZValue(3);
  850.  
  851.                 if (j == selected_col && i == selected_row && selected_obj == -1) {
  852.                     QGraphicsRectItem * col_item = ui->graphicsView->scene()->addRect(
  853.                                 QRectF(QPointF(5.0 + static_cast<qreal>(j_taken) + 1.0, 15.0 + static_cast<qreal>(taken) + 1.0),
  854.                                        QSizeF(static_cast<qreal>(col.width*2 - 2), static_cast<qreal>(height - 2))),
  855.                                 QPen(QBrush(QColor(Qt::red)), 1.0));
  856.                     cols.append(col_item);
  857.                     col_item->setZValue(5);
  858.                 }
  859.  
  860.                 j_taken += col.width*2;
  861.             }
  862.  
  863.             for (QGraphicsRectItem * col : cols) {
  864.                 if (col->rect().height() < big_h) {
  865.                     col->setRect(col->rect().x(), col->rect().y(), col->rect().size().width(), big_h);
  866.                 }
  867.             }
  868.  
  869.             QGraphicsRectItem * row_obj = ui->graphicsView->scene()->addRect(
  870.                         QRectF(QPointF(5.0, 15.0 + static_cast<qreal>(taken)),
  871.                                QSizeF(static_cast<qreal>(template_ptr->page_width*2), static_cast<qreal>(big_h))),
  872.                         QPen(QBrush(QColor(Qt::gray)), 1.0));
  873.             row_obj->setZValue(2);
  874.  
  875.             if (i == selected_row && selected_col == -1 && selected_obj == -1) {
  876.                 QGraphicsRectItem * row_obj = ui->graphicsView->scene()->addRect(
  877.                             QRectF(QPointF(5.0 + 1.0, 15.0 + taken + 1.0),
  878.                                    QSizeF(static_cast<qreal>(template_ptr->page_width*2 - 2), static_cast<qreal>(big_h - 2))),
  879.                             QPen(QBrush(QColor(Qt::red)), 1.0));
  880.                 row_obj->setZValue(4);
  881.             }
  882.  
  883.             if (i == selected_row) {
  884.                 qint32 left = template_ptr->page_width - j_taken/2;
  885.                 if (left < 0) left = 0;
  886.                 ui->vertical_width->setValue(left);
  887.             }
  888.  
  889.             taken += big_h;
  890.             default_taken += row_h;
  891.         }
  892.     }
  893. }
Advertisement
Add Comment
Please, Sign In to add comment