Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MainWindow::refresh_template_view() {
- ui->row_box->setDisabled(true);
- ui->save_template->setDisabled(true);
- ui->page_box->setDisabled(true);
- ui->cols_selection->setDisabled(true);
- ui->rows_selection->setDisabled(true);
- ui->section_box->setDisabled(true);
- ui->obj_selection->setDisabled(true);
- QGraphicsScene * scene;
- if (ui->graphicsView->scene() != Q_NULLPTR) {
- scene = ui->graphicsView->scene();
- scene->clear();
- }
- else {
- scene = new QGraphicsScene(ui->graphicsView);
- ui->graphicsView->setScene(scene);
- }
- if (template_ptr != Q_NULLPTR) {
- ui->vertical_width->setValue(0);
- ui->vertical_width->setMaximum(template_ptr->page_width);
- ui->vertical_width->setValue(template_ptr->page_width);
- QRectF sceneRect = QRectF(QPointF(5.0, 5.0), QSizeF(template_ptr->page_width*2.0, template_ptr->page_height*2.0*5));
- scene->setSceneRect(sceneRect);
- //scene->addRect(sceneRect, QPen(QBrush(QColor(Qt::gray)), 1));
- ui->save_template->setEnabled(true);
- ui->page_box->setEnabled(true);
- ui->rows_selection->setEnabled(true);
- if (template_ptr->sections.length() < selected_row + 1 && selected_row != -1) {
- select_row(); return;
- }
- if (selected_row >= 0) {
- if (template_ptr->sections.at(selected_row).fields.length() < selected_col + 1 && selected_col != -1) {
- select_col(); return;
- }
- }
- ui->row_4->setDisabled(true);
- ui->row_3->setDisabled(true);
- ui->row_2->setDisabled(true);
- ui->row_1->setDisabled(true);
- ui->row_0->setDisabled(true);
- ui->row_null->setDisabled(true);
- ui->col_4->setDisabled(true);
- ui->col_3->setDisabled(true);
- ui->col_2->setDisabled(true);
- ui->col_1->setDisabled(true);
- ui->col_0->setDisabled(true);
- ui->col_null->setDisabled(true);
- ui->obj_10->setDisabled(true);
- ui->obj_9->setDisabled(true);
- ui->obj_8->setDisabled(true);
- ui->obj_7->setDisabled(true);
- ui->obj_6->setDisabled(true);
- ui->obj_5->setDisabled(true);
- ui->obj_4->setDisabled(true);
- ui->obj_3->setDisabled(true);
- ui->obj_2->setDisabled(true);
- ui->obj_1->setDisabled(true);
- ui->obj_0->setDisabled(true);
- ui->obj_null->setDisabled(true);
- switch (template_ptr->sections.length()) {
- case 5:
- ui->row_4->setEnabled(true);
- case 4:
- ui->row_3->setEnabled(true);
- case 3:
- ui->row_2->setEnabled(true);
- case 2:
- ui->row_1->setEnabled(true);
- case 1:
- ui->row_0->setEnabled(true);
- default:
- ui->row_null->setEnabled(true);
- }
- if (selected_row >= 0) {
- ui->row_box->setEnabled(true);
- ui->cols_selection->setEnabled(true);
- switch (template_ptr->sections.at(selected_row).fields.length()) {
- case 5:
- ui->col_4->setEnabled(true);
- case 4:
- ui->col_3->setEnabled(true);
- case 3:
- ui->col_2->setEnabled(true);
- case 2:
- ui->col_1->setEnabled(true);
- case 1:
- ui->col_0->setEnabled(true);
- default:
- ui->col_null->setEnabled(true);
- }
- if (selected_col >= 0) {
- ui->section_box->setEnabled(true);
- ui->obj_selection->setEnabled(true);
- switch (template_ptr->sections.at(selected_row).fields.at(selected_col).objects.length()) {
- case 11:
- ui->obj_10->setEnabled(true);
- case 10:
- ui->obj_9->setEnabled(true);
- case 9:
- ui->obj_8->setEnabled(true);
- case 8:
- ui->obj_7->setEnabled(true);
- case 7:
- ui->obj_6->setEnabled(true);
- case 6:
- ui->obj_5->setEnabled(true);
- case 5:
- ui->obj_4->setEnabled(true);
- case 4:
- ui->obj_3->setEnabled(true);
- case 3:
- ui->obj_2->setEnabled(true);
- case 2:
- ui->obj_1->setEnabled(true);
- case 1:
- ui->obj_0->setEnabled(true);
- default:
- ui->obj_null->setEnabled(true);
- }
- }
- }
- qint32 row_h = static_cast<qint32>(static_cast<qreal>(template_ptr->page_height*2)/static_cast<qreal>(template_ptr->sections.length()));
- qint32 taken = 0;
- qint32 default_taken = 0;
- if (template_ptr->sections.length() == 0) {
- QGraphicsRectItem * item = ui->graphicsView->scene()->addRect(
- QRectF(QPointF(5.0, 15.0),
- QSizeF(static_cast<qreal>(template_ptr->page_width*2), static_cast<qreal>(template_ptr->page_height*2))),
- QPen(QBrush(QColor(Qt::black)), 1.0));
- item->setZValue(1);
- }
- for (qint32 i = 0; i != template_ptr->sections.length(); ++i) {
- const HorizontalSection& row = template_ptr->sections.at(i);
- if (i == template_ptr->sections.length() - 1)
- row_h = template_ptr->page_height*2 - default_taken;
- qint32 j_taken = 0;
- qint32 big_h = row_h;
- QList<QGraphicsRectItem*> cols;
- for (qint32 j = 0; j != row.fields.length(); ++j) {
- const VerticalField& col = row.fields.at(j);
- qint32 k_taken = 0;
- for (qint32 k = 0; k != col.objects.length(); ++k) {
- const FieldObject obj = col.objects.at(k);
- QStringList a;
- if (result != Q_NULLPTR) {
- for (const ConditionType& condition : obj.get_condition_types()) {
- a.append(result->get_state(condition));
- }
- }
- else {
- qDebug() << "NULL result";
- }
- if (obj.get_object_type() == ObjectType::TEXT) {
- const QList<TextObject> txts = obj.get_text_objects();
- QString object_text;
- QFont object_font;
- QColor object_color = QColor(Qt::black);
- if (txts.length() == 1) {
- object_text = txts.first().text;
- object_font = txts.first().font;
- object_color = txts.first().color;
- }
- else {
- object_text = txts.first().text;
- bool same_font = true;
- bool same_color = true;
- for (const TextObject& a : txts) {
- for (const TextObject& b : txts) {
- if (a.font != b.font) {
- same_font = false;
- }
- if (a.color != b.color) {
- same_color = false;
- }
- }
- }
- if (same_font) {
- object_font = txts.first().font;
- }
- if (same_color) {
- object_color = txts.first().color;
- }
- }
- if (result != Q_NULLPTR) {
- std::sort(a.begin(), a.end());
- for (const TextObject& txt : txts) {
- QStringList b = txt.combined_state;
- std::sort(b.begin(), b.end());
- if (a == b) {
- object_text = txt.text;
- QRegularExpression re("(~)([0-9]{1,2})");
- QRegularExpressionMatch match = re.match(object_text);
- while (match.hasMatch()) {
- bool conv;
- qint32 var = match.captured(2).toInt(&conv);
- QString after;
- if (conv && var >= 0) {
- switch (var + 1) {
- case static_cast<qint32>(TextVariable::TOPIC_NAME): {
- after = result->get_raw_topic().topic_name;
- break;
- }
- case static_cast<qint32>(TextVariable::REGULAR_QUORUM_VALUE): {
- if (result->get_raw_topic().use_regular_quorum)
- after = QString::number(result->get_raw_topic().regular_quorum_value);
- break;
- }
- case static_cast<qint32>(TextVariable::REGULAR_QUORUM_PERCENTAGE): {
- if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 2)
- after = QString::number(result->get_raw_topic().regular_quorum_percentage);
- break;
- }
- case static_cast<qint32>(TextVariable::REGULAR_QUORUM_NUMERATOR): {
- if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 3)
- after = QString::number(result->get_raw_topic().regular_quorum_numerator);
- break;
- }
- case static_cast<qint32>(TextVariable::REGULAR_QUORUM_DENOMINATOR): {
- if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 3)
- after = QString::number(result->get_raw_topic().regular_quorum_denominator);
- break;
- }
- case static_cast<qint32>(TextVariable::SHARES_QUORUM_VALUE): {
- if (result->get_raw_topic().use_regular_quorum && result->get_raw_topic().regular_quorum_type == 1)
- after = QString::number(result->get_raw_topic().shares_quorum_value);
- break;
- }
- case static_cast<qint32>(TextVariable::SHARES_QUORUM_PERCENTAGE): {
- if (result->get_raw_topic().use_shares_quorum && result->get_raw_topic().shares_quorum_type == 2)
- after = QString::number(result->get_raw_topic().shares_quorum_percentage);
- break;
- }
- case static_cast<qint32>(TextVariable::SHARES_QUORUM_NUMERATOR): {
- if (result->get_raw_topic().use_shares_quorum && result->get_raw_topic().shares_quorum_type == 3)
- after = QString::number(result->get_raw_topic().shares_quorum_numerator);
- break;
- }
- case static_cast<qint32>(TextVariable::SHARES_QUORUM_DENOMINATOR): {
- if (result->get_raw_topic().use_shares_quorum && result->get_raw_topic().shares_quorum_type == 3)
- after = QString::number(result->get_raw_topic().shares_quorum_denominator);
- break;
- }
- case static_cast<qint32>(TextVariable::SUPERMAJORITY_PERCENTAGE): {
- if ((result->get_raw_topic().majority == 4
- || result->get_raw_topic().majority == 5
- || result->get_raw_topic().majority == 6)
- && result->get_raw_topic().supermajority_type == 2)
- after = QString::number(result->get_raw_topic().supermajority_percentage);
- break;
- }
- case static_cast<qint32>(TextVariable::SUPERMAJORITY_NUMERATOR): {
- if ((result->get_raw_topic().majority == 4
- || result->get_raw_topic().majority == 5
- || result->get_raw_topic().majority == 6)
- && result->get_raw_topic().supermajority_type == 3)
- after = QString::number(result->get_raw_topic().supermajority_numerator);
- break;
- }
- case static_cast<qint32>(TextVariable::SUPERMAJORITY_DENOMINATOR): {
- if ((result->get_raw_topic().majority == 4
- || result->get_raw_topic().majority == 5
- || result->get_raw_topic().majority == 6)
- && result->get_raw_topic().supermajority_type == 3)
- after = QString::number(result->get_raw_topic().supermajority_denominator);
- break;
- }
- case static_cast<qint32>(TextVariable::TALK_START_TIME): {
- if (result->get_raw_topic().get_talk_start() != Q_NULLPTR) {
- if (result->get_raw_topic().get_talk_start()->isValid()
- && !result->get_raw_topic().get_talk_start()->isNull()) {
- after = result->get_raw_topic().get_talk_start()->time().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::TALK_END_TIME): {
- if (result->get_raw_topic().get_talk_end() != Q_NULLPTR) {
- if (result->get_raw_topic().get_talk_end()->isValid()
- && !result->get_raw_topic().get_talk_end()->isNull()) {
- after = result->get_raw_topic().get_talk_end()->time().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::VOTE_START_TIME): {
- if (result->get_raw_topic().get_vote_start() != Q_NULLPTR) {
- if (result->get_raw_topic().get_vote_start()->isValid()
- && !result->get_raw_topic().get_vote_start()->isNull()) {
- after = result->get_raw_topic().get_vote_start()->time().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::VOTE_END_TIME): {
- if (result->get_raw_topic().get_vote_end() != Q_NULLPTR) {
- if (result->get_raw_topic().get_vote_end()->isValid()
- && !result->get_raw_topic().get_vote_end()->isNull()) {
- after = result->get_raw_topic().get_vote_end()->time().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::TALK_START_DATE): {
- if (result->get_raw_topic().get_talk_start() != Q_NULLPTR) {
- if (result->get_raw_topic().get_talk_start()->isValid()
- && !result->get_raw_topic().get_talk_start()->isNull()) {
- after = result->get_raw_topic().get_talk_start()->date().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::TALK_END_DATE): {
- if (result->get_raw_topic().get_talk_end() != Q_NULLPTR) {
- if (result->get_raw_topic().get_talk_end()->isValid()
- && !result->get_raw_topic().get_talk_end()->isNull()) {
- after = result->get_raw_topic().get_talk_end()->date().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::VOTE_START_DATE): {
- if (result->get_raw_topic().get_vote_start() != Q_NULLPTR) {
- if (result->get_raw_topic().get_vote_start()->isValid()
- && !result->get_raw_topic().get_vote_start()->isNull()) {
- after = result->get_raw_topic().get_vote_start()->date().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::VOTE_END_DATE): {
- if (result->get_raw_topic().get_vote_end() != Q_NULLPTR) {
- if (result->get_raw_topic().get_vote_end()->isValid()
- && !result->get_raw_topic().get_vote_end()->isNull()) {
- after = result->get_raw_topic().get_vote_end()->date().toString();
- }
- }
- break;
- }
- case static_cast<qint32>(TextVariable::PRESENT_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_present()) {
- out++;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::VOTES_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_voting()) {
- out++;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::YES_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_yes()) {
- out++;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::NO_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_no()) {
- out++;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::ABS_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_abs()) {
- out++;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::NULL_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (!(vote.get_was_yes()
- || vote.get_was_no()
- || vote.get_was_abs())
- && vote.get_was_present()) {
- out++;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::NULL_ABS_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (!(vote.get_was_yes()
- || vote.get_was_no())
- && vote.get_was_present()) {
- out++;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::POWER_PRESENT): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_present()
- && vote.get_raw_vote() != Q_NULLPTR
- && result->get_raw_topic().use_shares) {
- out += vote.get_raw_vote()->vote_power;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::POWER_VOTED): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_voting()
- && vote.get_raw_vote() != Q_NULLPTR
- && result->get_raw_topic().use_shares) {
- out += vote.get_raw_vote()->vote_power;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::POWER_YES): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_yes()
- && vote.get_raw_vote() != Q_NULLPTR
- && result->get_raw_topic().use_shares) {
- out += vote.get_raw_vote()->vote_power;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::POWER_NO): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_no()
- && vote.get_raw_vote() != Q_NULLPTR
- && result->get_raw_topic().use_shares) {
- out += vote.get_raw_vote()->vote_power;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::POWER_ABS): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (vote.get_was_abs()
- && vote.get_raw_vote() != Q_NULLPTR
- && result->get_raw_topic().use_shares) {
- out += vote.get_raw_vote()->vote_power;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::POWER_NULL): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (!(vote.get_was_yes()
- || vote.get_was_no()
- || vote.get_was_abs())
- && vote.get_was_present()
- && vote.get_raw_vote() != Q_NULLPTR
- && result->get_raw_topic().use_shares) {
- out += vote.get_raw_vote()->vote_power;
- }
- }
- after = QString::number(out);
- break;
- }
- case static_cast<qint32>(TextVariable::POWER_NULL_ABS): {
- qint32 out = 0;
- for (const Vote& vote : result->get_votes()) {
- if (!(vote.get_was_yes()
- || vote.get_was_no())
- && vote.get_was_present()
- && vote.get_raw_vote() != Q_NULLPTR
- && result->get_raw_topic().use_shares) {
- out += vote.get_raw_vote()->vote_power;
- }
- }
- after = QString::number(out);
- break;
- }
- default: {
- break;
- }
- }
- }
- if (after.length() == 0) {
- after = "X";
- }
- object_text = object_text.replace("~" + QString::number(var), after);
- match = re.match(object_text);
- }
- object_font = txt.font;
- object_color = txt.color;
- break;
- }
- }
- }
- QGraphicsTextItem * obj_item = ui->graphicsView->scene()->addText(
- object_text,
- object_font);
- obj_item->setDefaultTextColor(object_color);
- obj_item->setTextWidth(col.width*2);
- obj_item->setPos(QPointF(5.0 + j_taken, 15.0 + taken + k_taken));
- obj_item->setZValue(7);
- k_taken += obj_item->boundingRect().height();
- if (j == selected_col && i == selected_row && k == selected_obj) {
- QGraphicsRectItem * obj_rect = ui->graphicsView->scene()->addRect(
- obj_item->pos().x() + 1.0,
- obj_item->pos().y() + 1.0,
- obj_item->boundingRect().width() - 2.0,
- obj_item->boundingRect().height() - 2.0,
- QPen(QBrush(QColor(Qt::red)), 1.0));
- obj_rect->setZValue(6);
- }
- }
- else if (obj.get_object_type() == ObjectType::LIST) {
- if (result != Q_NULLPTR) {
- const QList<ListObject> lsts = obj.get_list_objects();
- std::sort(a.begin(), a.end());
- for (const ListObject& lst : lsts) {
- QStringList b = lst.combined_state;
- std::sort(b.begin(), b.end());
- if (a == b) {
- qint32 l_taken = 0;
- qint32 row_no = 0;
- qint32 x_1st, y_1st, w_1st;
- for (const Vote& vote : result->get_votes()) {
- QFont object_font;
- QColor object_color;
- QString object_text;
- bool use_row = false;
- switch(lst.list_type) {
- case ListType::PRESENT: {
- if (vote.get_was_present()) {
- use_row = true;
- }
- break;
- }
- case ListType::PRESENT_VOTED: {
- if (vote.get_was_voting()) {
- use_row = true;
- }
- break;
- }
- case ListType::PRESENT_VOTES: {
- if (vote.get_was_present()) {
- use_row = true;
- }
- break;
- }
- case ListType::CLICKVOTED:
- case ListType::CLICKVOTED_VOTES: {
- if (vote.get_was_yes()
- || vote.get_was_no()
- || vote.get_was_abs()) {
- use_row = true;
- }
- break;
- }
- case ListType::YES: {
- if (vote.get_was_yes()) {
- use_row = true;
- }
- break;
- }
- case ListType::NO: {
- if (vote.get_was_no()) {
- use_row = true;
- }
- break;
- }
- case ListType::ABS: {
- if (vote.get_was_abs()) {
- use_row = true;
- }
- break;
- }
- case ListType::NULLVOTED: {
- if (vote.get_was_voting()
- && !vote.get_was_yes()
- && !vote.get_was_no()
- && !vote.get_was_abs()) {
- use_row = true;
- }
- break;
- }
- case ListType::NULLVOTED_AND_ABS: {
- if (vote.get_was_voting()
- && vote.get_was_abs()) {
- use_row = true;
- }
- break;
- }
- default: {
- use_row = false;
- }
- }
- if (use_row) {
- row_no++;
- switch(lst.list_type) {
- case ListType::ABS:
- case ListType::NO:
- case ListType::YES:
- case ListType::CLICKVOTED:
- case ListType::NULLVOTED:
- case ListType::PRESENT:
- {
- if (row_no % 2 == 0) {
- object_font = lst.row_fonts.at(0);
- object_color = lst.colors.at(0);
- object_text = lst.row_texts.at(0);
- }
- else {
- object_font = lst.row_fonts.at(1);
- object_color = lst.colors.at(1);
- object_text = lst.row_texts.at(1);
- }
- break;
- }
- case ListType::CLICKVOTED_VOTES:
- {
- if (vote.get_was_abs()) {
- object_font = lst.row_fonts.at(0);
- object_color = lst.colors.at(0);
- object_text = lst.row_texts.at(0);
- }
- else if (vote.get_was_no()) {
- object_font = lst.row_fonts.at(1);
- object_color = lst.colors.at(1);
- object_text = lst.row_texts.at(1);
- }
- else if (vote.get_was_yes()) {
- object_font = lst.row_fonts.at(2);
- object_color = lst.colors.at(2);
- object_text = lst.row_texts.at(2);
- }
- break;
- }
- case ListType::PRESENT_VOTES:
- {
- if (vote.get_was_abs()) {
- object_font = lst.row_fonts.at(0);
- object_color = lst.colors.at(0);
- object_text = lst.row_texts.at(0);
- }
- else if (vote.get_was_no()) {
- object_font = lst.row_fonts.at(1);
- object_color = lst.colors.at(1);
- object_text = lst.row_texts.at(1);
- }
- else if (vote.get_was_yes()) {
- object_font = lst.row_fonts.at(2);
- object_color = lst.colors.at(2);
- object_text = lst.row_texts.at(2);
- }
- else {
- object_font = lst.row_fonts.at(3);
- object_color = lst.colors.at(3);
- object_text = lst.row_texts.at(3);
- }
- break;
- }
- case ListType::PRESENT_VOTED:
- {
- if (vote.get_was_abs()
- || vote.get_was_no()
- || vote.get_was_yes()) {
- object_font = lst.row_fonts.at(0);
- object_color = lst.colors.at(0);
- object_text = lst.row_texts.at(0);
- }
- else {
- object_font = lst.row_fonts.at(1);
- object_color = lst.colors.at(1);
- object_text = lst.row_texts.at(1);
- }
- break;
- }
- case ListType::NULLVOTED_AND_ABS:
- {
- if (vote.get_was_abs()) {
- object_font = lst.row_fonts.at(0);
- object_color = lst.colors.at(0);
- object_text = lst.row_texts.at(0);
- }
- else {
- object_font = lst.row_fonts.at(1);
- object_color = lst.colors.at(1);
- object_text = lst.row_texts.at(1);
- }
- break;
- }
- default: {}
- }
- QRegularExpression re("(~)([0-9]{1,2})");
- QRegularExpressionMatch match = re.match(object_text);
- while (match.hasMatch()) {
- bool conv;
- qint32 var = match.captured(2).toInt(&conv);
- QString after;
- if (conv && var >= 0) {
- switch (var + 1) {
- case static_cast<qint32>(ListVariable::NALE_1ST): {
- after = vote.get_raw_debater()->copy_name_1st;
- break;
- }
- case static_cast<qint32>(ListVariable::NAME_LAST): {
- after = vote.get_raw_debater()->copy_name_last;
- break;
- }
- case static_cast<qint32>(ListVariable::SHORT_1ST): {
- QString short_1st = vote.get_raw_debater()->copy_name_1st;
- short_1st.remove(1, short_1st.length() - 2);
- after = short_1st;
- break;
- }
- case static_cast<qint32>(ListVariable::SHORT_LAST): {
- QString short_last = vote.get_raw_debater()->copy_name_last;
- short_last.remove(1, short_last.length() - 2);
- after = short_last;
- break;
- }
- case static_cast<qint32>(ListVariable::ORDER_NO): {
- after = QString::number(row_no);
- break;
- }
- case static_cast<qint32>(ListVariable::VOTE_POWER): {
- after = QString::number(vote.get_raw_vote()->vote_power);
- break;
- }
- default: {
- break;
- }
- }
- }
- if (after.length() == 0) {
- after = "X";
- }
- object_text = object_text.replace("~" + QString::number(var), after);
- match = re.match(object_text);
- }
- QGraphicsTextItem * row_item = ui->graphicsView->scene()->addText(
- object_text,
- object_font);
- row_item->setDefaultTextColor(object_color);
- row_item->setTextWidth(col.width*2);
- row_item->setPos(QPointF(5.0 + j_taken, 15.0 + taken + k_taken));
- row_item->setZValue(7);
- l_taken += row_item->boundingRect().height();
- k_taken += row_item->boundingRect().height();
- if (row_no == 1) {
- x_1st = row_item->pos().x();
- y_1st = row_item->pos().y();
- w_1st = row_item->boundingRect().width();
- }
- if (w_1st < row_item->boundingRect().width()) {
- w_1st = row_item->boundingRect().width();
- }
- }
- }
- if (j == selected_col && i == selected_row && k == selected_obj && row_no > 0) {
- QGraphicsRectItem * obj_rect = ui->graphicsView->scene()->addRect(
- x_1st + 1.0,
- y_1st + 1.0,
- w_1st - 2.0,
- l_taken - 2.0,
- QPen(QBrush(QColor(Qt::red)), 1.0));
- obj_rect->setZValue(6);
- }
- break;
- }
- }
- }
- }
- }
- qint32 height = row_h;
- if (k_taken > height) {
- height = k_taken;
- }
- if (height > big_h) {
- big_h = height;
- }
- QGraphicsRectItem * col_item = ui->graphicsView->scene()->addRect(
- QRectF(QPointF(5.0 + static_cast<qreal>(j_taken), 15.0 + static_cast<qreal>(taken)),
- QSizeF(static_cast<qreal>(col.width*2), static_cast<qreal>(height))),
- QPen(QBrush(QColor(Qt::gray)), 1.0), QBrush(QColor(Qt::white)));
- cols.append(col_item);
- col_item->setZValue(3);
- if (j == selected_col && i == selected_row && selected_obj == -1) {
- QGraphicsRectItem * col_item = ui->graphicsView->scene()->addRect(
- QRectF(QPointF(5.0 + static_cast<qreal>(j_taken) + 1.0, 15.0 + static_cast<qreal>(taken) + 1.0),
- QSizeF(static_cast<qreal>(col.width*2 - 2), static_cast<qreal>(height - 2))),
- QPen(QBrush(QColor(Qt::red)), 1.0));
- cols.append(col_item);
- col_item->setZValue(5);
- }
- j_taken += col.width*2;
- }
- for (QGraphicsRectItem * col : cols) {
- if (col->rect().height() < big_h) {
- col->setRect(col->rect().x(), col->rect().y(), col->rect().size().width(), big_h);
- }
- }
- QGraphicsRectItem * row_obj = ui->graphicsView->scene()->addRect(
- QRectF(QPointF(5.0, 15.0 + static_cast<qreal>(taken)),
- QSizeF(static_cast<qreal>(template_ptr->page_width*2), static_cast<qreal>(big_h))),
- QPen(QBrush(QColor(Qt::gray)), 1.0));
- row_obj->setZValue(2);
- if (i == selected_row && selected_col == -1 && selected_obj == -1) {
- QGraphicsRectItem * row_obj = ui->graphicsView->scene()->addRect(
- QRectF(QPointF(5.0 + 1.0, 15.0 + taken + 1.0),
- QSizeF(static_cast<qreal>(template_ptr->page_width*2 - 2), static_cast<qreal>(big_h - 2))),
- QPen(QBrush(QColor(Qt::red)), 1.0));
- row_obj->setZValue(4);
- }
- if (i == selected_row) {
- qint32 left = template_ptr->page_width - j_taken/2;
- if (left < 0) left = 0;
- ui->vertical_width->setValue(left);
- }
- taken += big_h;
- default_taken += row_h;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment