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

Method multiLabelEditColorChangeSelection

tests/backend/TextLabel/TextLabelTest.cpp:215–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215void TextLabelTest::multiLabelEditColorChangeSelection() {
216 Project project;
217 auto* ws = new Worksheet(QStringLiteral("worksheet"));
218 QVERIFY(ws != nullptr);
219 project.addChild(ws);
220
221 auto* p = new CartesianPlot(QStringLiteral("plot"));
222 QVERIFY(p != nullptr);
223 ws->addChild(p);
224
225 LabelWidget w(nullptr);
226
227 auto* l1 = new TextLabel(QStringLiteral("Label"));
228 QVERIFY(l1 != nullptr);
229 ws->addChild(l1);
230 l1->setText(QStringLiteral("This is the text of label 1"));
231
232 VERIFYLABELCOLORS(l1, Qt::black, Qt::transparent);
233
234 auto* l2 = new TextLabel(QStringLiteral("Label"));
235 QVERIFY(l2 != nullptr);
236 ws->addChild(l2);
237 w.setLabels({l2}); // This setlabels is important, otherwise a specific scenario does not occur
238 l2->setText(QStringLiteral("Text label 2"));
239
240 STORETEXTPROPERTIES(l1, l1InitProperties);
241 STORETEXTPROPERTIES(l2, l2InitProperties);
242
243 w.setLabels({l1, l2});
244 auto cursor = w.ui.teLabel->textCursor();
245 // marks character 2 to 4
246 cursor.setPosition(2);
247 cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
248 w.ui.teLabel->setTextCursor(cursor);
249 w.fontColorChanged(Qt::cyan);
250 w.backgroundColorChanged(Qt::green);
251 w.fontBoldChanged(true);
252 w.fontItalicChanged(true);
253
254 {
255 QTextEdit te(l1->text().text);
256 QTextCursor cTest = te.textCursor();
257 cTest.setPosition(2);
258 cTest.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
259 te.setTextCursor(cTest);
260 auto ccf = te.currentCharFormat();
261 QCOMPARE(ccf.foreground().color(), Qt::cyan);
262 QCOMPARE(ccf.background().color(), Qt::green);
263 QCOMPARE(te.fontItalic(), true);
264 QCOMPARE(te.fontWeight(), QFont::Bold);
265 QCOMPARE(te.toPlainText(), QStringLiteral("This is the text of label 1"));
266 }
267
268 {
269 QTextEdit te(l2->text().text);
270 QTextCursor cTest = te.textCursor();
271 cTest.setPosition(2);
272 cTest.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);

Callers

nothing calls this directly

Calls 12

setLabelsMethod · 0.80
fontColorChangedMethod · 0.80
fontBoldChangedMethod · 0.80
fontItalicChangedMethod · 0.80
fontItalicMethod · 0.80
addChildMethod · 0.45
setTextMethod · 0.45
setPositionMethod · 0.45
textMethod · 0.45
colorMethod · 0.45
backgroundMethod · 0.45

Tested by

no test coverage detected