void ExpressionQueryWidget::showResult() { if (m_query) { m_textEdit->moveCursor(QTextCursor::End); QVariant value = m_query->result(); QString result; if (value.type() == QVariant::List || value.type() == QVariant::StringList) { result = tr("<%n items>", 0, value.toList().count()); } else if (value.isNull()) { result = QLatin1String("<no value>"); } else { result = value.toString(); } if (m_mode == SeparateEntryMode) { m_textEdit->insertPlainText(m_expr + " : "); m_textEdit->insertPlainText(result); } else { m_textEdit->insertPlainText(" => "); m_textEdit->insertPlainText(result); } appendPrompt(); m_expr.clear(); } }
void ExpressionQueryWidget::clear() { clearTextEditor(); if (m_lineEdit) m_lineEdit->clear(); if (m_mode == ShellMode) appendPrompt(); }
void ScriptingWidget::executeCommand(const QString& strCommand) { Interpreter* pInterpreter = NULL; InterpreterManager* pInterMgr = dynamic_cast<InterpreterManager*>(mInterpreter.get()); if (pInterMgr != NULL) { pInterpreter = pInterMgr->getInterpreter(); } if (pInterpreter == NULL) { appendPrompt(); QMessageBox::critical(this, "Scripting Window", "Could not get the interpreter plug-in!"); return; } // Set the input values for the plug-in mExecutingCommand = true; pInterpreter->executeCommand(strCommand.toStdString()); mExecutingCommand = false; appendPrompt(); }
ExpressionQueryWidget::ExpressionQueryWidget(Mode mode, QDeclarativeEngineDebug *client, QWidget *parent) : QWidget(parent), m_mode(mode), m_client(client), m_query(0), m_textEdit(new QPlainTextEdit), m_lineEdit(0) { m_prompt = QLatin1String(">"); QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); layout->setSpacing(0); layout->addWidget(m_textEdit); m_textEdit->setFrameStyle(QFrame::NoFrame); updateTitle(); m_highlighter = new QmlJSEditor::Highlighter(m_textEdit->document()); m_highlighter->setParent(m_textEdit->document()); if (m_mode == SeparateEntryMode) { Utils::StyledBar *bar = new Utils::StyledBar; m_lineEdit = new Utils::FilterLineEdit; m_lineEdit->setPlaceholderText(tr("<Type expression to evaluate>")); m_lineEdit->setToolTip(tr("Write and evaluate QtScript expressions.")); m_clearButton = new QToolButton(); m_clearButton->setToolTip(tr("Clear Output")); m_clearButton->setIcon(QIcon(Core::Constants::ICON_CLEAN_PANE)); connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clearTextEditor())); connect(m_lineEdit, SIGNAL(textChanged(QString)), SLOT(changeContextHelpId(QString))); connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(executeExpression())); QHBoxLayout *hbox = new QHBoxLayout(bar); hbox->setMargin(1); hbox->setSpacing(1); hbox->addWidget(m_lineEdit); hbox->addWidget(m_clearButton); layout->addWidget(bar); m_textEdit->setReadOnly(true); m_lineEdit->installEventFilter(this); } else { m_textEdit->installEventFilter(this); appendPrompt(); } setFontSettings(); clear(); }
void ExpressionQueryWidget::showCurrentContext() { if (m_mode == ShellMode) { // clear the initial prompt if (m_textEdit->document()->lineCount() == 1) m_textEdit->clear(); } m_textEdit->moveCursor(QTextCursor::End); m_textEdit->appendPlainText(m_currObject.className() + QLatin1String(": ") + (m_currObject.name().isEmpty() ? QLatin1String("<unnamed object>") : m_currObject.name())); appendPrompt(); }
void ScriptingWidget::showEvent(QShowEvent* pEvent) { if ((mInterpreter.get() == NULL) && (mInterpreterName.isEmpty() == false)) { Interpreter* pInterpreter = NULL; setReadOnly(true); std::vector<PlugIn*> plugIns = mpPims->getPlugInInstances(mInterpreterName.toStdString()); if (plugIns.empty() == false && dynamic_cast<InterpreterManager*>(plugIns.front()) != NULL) { mInterpreter = PlugInResource(plugIns.front()); } else { mInterpreter = PlugInResource(mInterpreterName.toStdString()); } InterpreterManager* pInterMgr = dynamic_cast<InterpreterManager*>(mInterpreter.get()); if (pInterMgr != NULL) { mInteractive = pInterMgr->isInteractiveEnabled(); pInterMgr->start(); QString startupMsg = QString::fromStdString(pInterMgr->getStartupMessage()); addOutputText(startupMsg, false, false); pInterMgr->attach(SIGNAL_NAME(InterpreterManager, InterpreterStarted), Slot(this, &ScriptingWidget::interpreterStarted)); pInterpreter = pInterMgr->getInterpreter(); } if (pInterpreter != NULL) { pInterpreter->attach(SIGNAL_NAME(Interpreter, OutputText), Slot(this, &ScriptingWidget::receiveOutput)); pInterpreter->attach(SIGNAL_NAME(Interpreter, ErrorText), Slot(this, &ScriptingWidget::receiveOutput)); setReadOnly(!mInteractive); } } // Append a prompt if the widget is shown for the first time if (mDisplayedOnce == false) { appendPrompt(); mDisplayedOnce = true; } // Show the widget QTextEdit::showEvent(pEvent); }
void ScriptingWidget::interpreterStarted(Subject& subject, const std::string& signal, const boost::any& data) { Interpreter* pInterpreter = NULL; InterpreterManager* pInterMgr = dynamic_cast<InterpreterManager*>(mInterpreter.get()); if (pInterMgr != NULL) { pInterpreter = pInterMgr->getInterpreter(); QString startupMsg = QString::fromStdString(pInterMgr->getStartupMessage()); addOutputText(startupMsg, false, true); } if (pInterpreter != NULL) { pInterpreter->attach(SIGNAL_NAME(Interpreter, OutputText), Slot(this, &ScriptingWidget::receiveOutput)); pInterpreter->attach(SIGNAL_NAME(Interpreter, ErrorText), Slot(this, &ScriptingWidget::receiveOutput)); setReadOnly(!mInteractive); appendPrompt(); } }
void ScriptingWidget::clearOutput() { clear(); appendPrompt(); }