#include #include #include #include #include #include #include QList markdownText = { "To create a JSON array of objects from multiple features using JSONTemplater, you need to " "aggregate your features and use sub-templates. Here's a step-by-step setup with code:\n\n" "1. Aggregate your features into a single feature (so you get one JSON array, not one JSON per " "feature). Use a ListBuilder or Aggregator to collect your features into a list attribute.\n\n", "\n2. Add a Creator and connect it to the Root port of JSONTemplater. This ensures only one " "feature triggers the JSON output.\n\n" "3. In JSONTemplater, enable Sub Templates. Add a sub-template (e.g., \"ITEMS\") and set its " "template to describe a single object, referencing list attributes:\n", "\n4. In the Root template, use fme:process-features to build the array:\n", "\n5. Set the Result Attribute to store the output JSON.\n\n" "Troubleshooting tips:\n" "- Make sure your list attribute (e.g., mylist{}) is correctly built and populated.\n" "- Use the correct syntax for list attribute access in the sub-template.\n" "- Only one feature should reach the Root port, or you'll get multiple JSON outputs.\n\n" "This approach ensures you get a single JSON array of objects, each built from your original " "features. Let me know if you want a workspace summary or more details on any step!"}; QWidget* createMessage() { QWidget* message = new QWidget(); QHBoxLayout* messageLayout = new QHBoxLayout(message); QFrame* bubble = new QFrame(); bubble->setStyleSheet( "QFrame { background-color: #2C3E50;}"); bubble->setSizePolicy(QSizePolicy::Minimum, bubble->sizePolicy().verticalPolicy()); bubble->setMaximumWidth(1000); auto messageComponentLayout = new QVBoxLayout(); messageComponentLayout->setContentsMargins(0, 0, 0, 0); messageComponentLayout->setSpacing(8); messageComponentLayout->addWidget(bubble, 1); messageLayout->addLayout(messageComponentLayout, 1); QVBoxLayout* bubbleLayout = new QVBoxLayout(bubble); bubbleLayout->setContentsMargins(16, 8, 16, 8); for (int i = 0; i < markdownText.size(); ++i) { QLabel* label = new QLabel(); QTextDocument doc; doc.setMarkdown(markdownText[i]); QString html = doc.toHtml(); label->setText(html); label->setStyleSheet("QLabel { color: white}"); label->setWordWrap(true); label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); label->setMinimumHeight(24); label->setMinimumWidth(100); bubbleLayout->addWidget(label); const QFontMetrics fm(label->font()); const int textWidth = fm.horizontalAdvance(markdownText[i]); label->setMaximumWidth(textWidth + 4); } return message; } int main(int argc, char* argv[]) { QApplication app(argc, argv); // Create the main window QMainWindow mainWindow; auto chatScrollArea = new QScrollArea(&mainWindow); chatScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); chatScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); chatScrollArea->setWidgetResizable(true); auto chatListWidget = new QWidget(); chatScrollArea->setWidget(chatListWidget); auto chatListLayout = new QVBoxLayout(chatListWidget); chatListLayout->setContentsMargins(0, 0, 0, 0); chatListLayout->setSpacing(0); chatListLayout->addStretch(1); chatListLayout->addWidget(createMessage()); // Set the scroll area as the central widget of the main window mainWindow.setCentralWidget(chatScrollArea); mainWindow.resize(1080, 720); // Set the main window title mainWindow.setWindowTitle("Example"); // Show the main window mainWindow.show(); return app.exec(); }