void Ut_MSettingsLanguageTextFactory::testCreateWidget() { // Create a settings text MSettingsLanguageText settingsText("TestKey", "Title"); MSettingsLanguageWidget dds; MockDataStore dataStore; MWidget *widget = MSettingsLanguageTextFactory::createWidget(settingsText, dds, &dataStore); QVERIFY(widget != NULL); // Expecting the widget to have a layout and linear policy QGraphicsLinearLayout *layout = dynamic_cast<QGraphicsLinearLayout *>(widget->layout()); QVERIFY(layout != NULL); // Expecting the layout to contain a MLabel and a MTextEdit QCOMPARE(layout->count(), 2); // The label's title should be the SettingsText's title MLabel *label = dynamic_cast<MLabel *>(layout->itemAt(0)); QVERIFY(label != NULL); QCOMPARE(label->text(), settingsText.title()); // The label's title should be the specified key's value MTextEdit *textEdit = dynamic_cast<MTextEdit *>(layout->itemAt(1)); QVERIFY(textEdit != NULL); QCOMPARE(textEdit->text(), dataStore.value("TestKey").toString()); delete widget; }
QString AppWindow::getText(QString title, QString prompt, QString text) { MWidget *centralWidget = new MWidget; QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); centralWidget->setLayout(layout); MLabel *label = new MLabel(prompt, centralWidget); label->setStyleName("CommonTitleInverted"); MTextEdit *textEdit = new MTextEdit(MTextEditModel::SingleLine, text, centralWidget); layout->addItem(label); layout->addItem(textEdit); MDialog* dialog = new MDialog(title, M::OkButton | M::CancelButton); dialog->setCentralWidget(centralWidget); connect(dialog, SIGNAL(disappeared()), SLOT(processDialogResult())); if (dialog->exec(this) == M::OkButton) return textEdit->text(); return ""; }