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

Method setText

src/backend/worksheet/TextLabel.cpp:286–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284
285STD_SETTER_CMD_IMPL_F_S(TextLabel, SetText, TextLabel::TextWrapper, textWrapper, updateText)
286void TextLabel::setText(const TextWrapper& textWrapper) {
287 Q_D(TextLabel);
288
289 if (d->textWrapper == textWrapper)
290 return;
291
292 // DEBUG("********************\n" << Q_FUNC_INFO << ", old/new mode = " << (int)d->textWrapper.mode << " " << (int)textWrapper.mode)
293 // DEBUG("\nOLD TEXT = " << STDSTRING(d->textWrapper.text) << '\n')
294 // DEBUG("NEW TEXT = " << STDSTRING(textWrapper.text) << '\n')
295 // QDEBUG("COLORS: color =" << d->fontColor << ", background color =" << d->backgroundColor)
296
297 bool oldEmpty = d->textWrapper.text.isEmpty();
298 if (textWrapper.mode == TextLabel::Mode::Text && !textWrapper.text.isEmpty()) {
299 QTextEdit pte(d->textWrapper.text); // te with previous text
300 // pte.selectAll();
301 // restore formatting when text changes or switching back to text mode
302 if (d->textWrapper.mode != TextLabel::Mode::Text || oldEmpty || pte.toPlainText().isEmpty()) {
303 // DEBUG("RESTORE FORMATTING")
304 QTextEdit te(d->textWrapper.text);
305 te.selectAll();
306 auto font = te.currentFont();
307 // QDEBUG("CURRENT FONT =" << font)
308 te.setText(textWrapper.text);
309 te.selectAll();
310 te.setTextColor(d->fontColor);
311 te.setTextBackgroundColor(d->backgroundColor);
312 te.setCurrentFont(font); // needed to keep font
313 te.setFont(font); // body style
314
315 auto tw = textWrapper;
316 tw.text = te.toHtml();
317 // DEBUG("\nTW TEXT = " << STDSTRING(tw.text) << std::endl)
318 exec(new TextLabelSetTextCmd(d, tw, ki18n("%1: set label text")));
319 } else { // the existing text (mode Text) is being modified
320 // DEBUG("MODIFY TEXT")
321 pte.selectAll();
322 auto font = pte.currentFont();
323 // QDEBUG("CURRENT FONT =" << font)
324 pte.setHtml(textWrapper.text);
325 pte.selectAll();
326 pte.setCurrentFont(font);
327
328 QUndoCommand* parent = nullptr;
329 TextLabelSetTextCmd* command = nullptr;
330 if (textWrapper.text.indexOf(QStringLiteral("background-color:")) != -1) {
331 const auto& bgColor = pte.textBackgroundColor();
332 if (bgColor != d->backgroundColor) {
333 parent = new QUndoCommand(ki18n("%1: set label text").subs(name()).toString());
334 new TextLabelSetTeXBackgroundColorCmd(d, bgColor, ki18n("%1: set background color"), parent);
335 }
336 command = new TextLabelSetTextCmd(d, textWrapper, ki18n("%1: set label text"), parent);
337 } else {
338 // no color available yet, plain text is being provided -> set the color from member variable
339 pte.setTextBackgroundColor(d->backgroundColor);
340 TextWrapper tw = textWrapper;
341 tw.text = pte.toHtml();
342 command = new TextLabelSetTextCmd(d, tw, ki18n("%1: set label text"), parent);
343 }

Callers 15

InfoElementMethod · 0.45
initMethod · 0.45
addCurveMethod · 0.45
removeCurveMethod · 0.45
curveDataChangedMethod · 0.45
childRemovedMethod · 0.45
setPositionLogicalMethod · 0.45
setLabelsFontMethod · 0.45
setLabelsFontColorMethod · 0.45
recalcMethod · 0.45

Calls 9

setTextColorMethod · 0.80
toHtmlMethod · 0.80
setHtmlMethod · 0.80
isEmptyMethod · 0.45
selectAllMethod · 0.45
setFontMethod · 0.45
indexOfMethod · 0.45
toStringMethod · 0.45
updatePositionMethod · 0.45

Tested by

no test coverage detected