MCPcopy Create free account
hub / github.com/KDE/labplot / textChanged

Method textChanged

src/frontend/widgets/LabelWidget.cpp:563–658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

561// text formatting slots
562
563void LabelWidget::textChanged() {
564 // QDEBUG("############\n" << Q_FUNC_INFO << ", label text =" << m_label->text().text)
565 CONDITIONAL_LOCK_RETURN;
566
567 const auto& plainText = ui.teLabel->toPlainText();
568 QTextEdit te(ui.chbShowPlaceholderText->isChecked() ? m_label->text().textPlaceholder : m_label->text().text);
569 bool plainTextChanged = plainText != te.toPlainText();
570
571 const auto mode = static_cast<TextLabel::Mode>(ui.cbMode->currentIndex());
572 switch (mode) {
573 case TextLabel::Mode::LaTeX:
574 case TextLabel::Mode::Markdown: {
575 QString text = ui.teLabel->toPlainText();
576 TextLabel::TextWrapper wrapper;
577 wrapper.mode = mode;
578
579 if (!ui.chbShowPlaceholderText->isChecked()) {
580 if (plainTextChanged) {
581 // set text only if the plain text change. otherwise the text is changed
582 // already in the setter functions
583 wrapper.text = std::move(text);
584 for (auto* label : m_labelsList) {
585 wrapper.textPlaceholder = label->text().textPlaceholder;
586 wrapper.allowPlaceholder = label->text().allowPlaceholder;
587 label->setText(wrapper);
588 }
589 }
590 } else {
591 // No need to compare if plainTextChanged
592 // Change it always.
593 wrapper.textPlaceholder = std::move(text);
594 for (auto* label : m_labelsList) {
595 wrapper.allowPlaceholder = label->text().allowPlaceholder;
596 wrapper.text = label->text().text;
597 label->setPlaceholderText(wrapper);
598 }
599 }
600 break;
601 }
602 case TextLabel::Mode::Text: {
603 // QDEBUG(Q_FUNC_INFO << ", color = " << m_label->fontColor())
604 // QDEBUG(Q_FUNC_INFO << ", background color = " << m_label->backgroundColor())
605 // QDEBUG(Q_FUNC_INFO << ", format color = " << ui.teLabel->currentCharFormat().foreground().color())
606 // QDEBUG(Q_FUNC_INFO << ", Plain TEXT = " << ui.teLabel->toPlainText() << '\n')
607 // QDEBUG(Q_FUNC_INFO << ", OLD TEXT =" << m_label->text().text << '\n')
608 // save an empty string instead of html with empty body if no text is in QTextEdit
609 QString text;
610 if (!ui.teLabel->toPlainText().isEmpty()) {
611 // if the current or previous label text is empty, set the color first
612 QTextEdit pte(m_label->text().text); // te with previous text
613 if (m_label->text().text.isEmpty() || pte.toPlainText().isEmpty()) {
614 // DEBUG("EMPTY TEXT")
615 ui.teLabel->selectAll();
616 ui.teLabel->setTextColor(m_label->fontColor());
617 ui.teLabel->setTextBackgroundColor(m_label->backgroundColor());
618 // clear the selection after setting the color
619 auto tc = ui.teLabel->textCursor();
620 tc.setPosition(tc.selectionEnd());

Callers

nothing calls this directly

Calls 14

setPlaceholderTextMethod · 0.80
setTextColorMethod · 0.80
fontColorMethod · 0.80
backgroundColorMethod · 0.80
toHtmlMethod · 0.80
textMethod · 0.45
currentIndexMethod · 0.45
setTextMethod · 0.45
isEmptyMethod · 0.45
selectAllMethod · 0.45
setPositionMethod · 0.45
setFontColorMethod · 0.45

Tested by

no test coverage detected