本文整理汇总了C++中QPlainTextEdit类的典型用法代码示例。如果您正苦于以下问题:C++ QPlainTextEdit类的具体用法?C++ QPlainTextEdit怎么用?C++ QPlainTextEdit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPlainTextEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tr
void QgsMessageLogViewer::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
{
QString cleanedTag = tag;
if ( cleanedTag.isNull() )
cleanedTag = tr( "General" );
int i;
for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != cleanedTag; i++ )
;
QPlainTextEdit *w = nullptr;
if ( i < tabWidget->count() )
{
w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
tabWidget->setCurrentIndex( i );
}
else
{
w = new QPlainTextEdit( this );
w->setReadOnly( true );
tabWidget->addTab( w, cleanedTag );
tabWidget->setCurrentIndex( tabWidget->count() - 1 );
tabWidget->setTabsClosable( true );
}
QString levelString;
switch ( level )
{
case QgsMessageLog::INFO:
levelString = "INFO";
break;
case QgsMessageLog::WARNING:
levelString = "WARNING";
break;
case QgsMessageLog::CRITICAL:
levelString = "CRITICAL";
break;
case QgsMessageLog::NONE:
levelString = "NONE";
break;
}
QString prefix = QStringLiteral( "%1\t%2\t" )
.arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
.arg( levelString );
QString cleanedMessage = message;
cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "\n\t\t\t" ) );
w->appendPlainText( cleanedMessage );
w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
}
示例2: if
void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const
{
QVariant variant = index.data(Qt::EditRole);
if (tryDisplay)
{
if (!variant.isValid())
{
variant = index.data(Qt::DisplayRole);
if (!variant.isValid())
{
return;
}
}
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor);
if(plainTextEdit) //for some reason it is easier to brake the loop here
{
if (plainTextEdit->toPlainText() == variant.toString())
{
return;
}
}
}
// Color columns use a custom editor, so we need explicitly set a data for it
CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor);
if (colorEditor != nullptr)
{
colorEditor->setColor(variant.toInt());
return;
}
QByteArray n = editor->metaObject()->userProperty().name();
if (n == "dateTime")
{
if (editor->inherits("QTimeEdit"))
n = "time";
else if (editor->inherits("QDateEdit"))
n = "date";
}
if (!n.isEmpty())
{
if (!variant.isValid())
variant = QVariant(editor->property(n).userType(), (const void *)0);
editor->setProperty(n, variant);
}
}
示例3: QWidget
HexDumpWindow::HexDumpWindow(QString romFilePath, QWidget * parent) : QWidget(parent, Qt::Window)
{
this->setWindowTitle(tr("Hex Dump"));
QString dump = QString::fromStdString(disassembler::RomParser::hexDump(romFilePath.toStdString()));
QPlainTextEdit* editor = new QPlainTextEdit(dump);
editor->setFont(QFont ("Courier", 11));
editor->setReadOnly(true);
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(editor);
this->setLayout(layout);
this->setFixedSize(600, 600);
}
示例4: QVBoxLayout
DebugWidget::DebugWidget()
{
this->setWindowTitle("Debug Log");
this->setAttribute( Qt::WA_QuitOnClose, false ); //quit only when main window is closed
QBoxLayout* layout = new QVBoxLayout();
this->setLayout(layout);
QPlainTextEdit *textEdit = new QPlainTextEdit(this);
QFont font = QFont("Monospace");
font.setStyleHint(QFont::TypeWriter);
textEdit->setFont(font);
textEdit->setReadOnly(true);
layout->addWidget(textEdit);
this->show();
DEBUG_DISPLAY = textEdit;
}
示例5: setModelData
void BudgetEntityDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
BudgetEntity entity = qvariant_cast<BudgetEntity>(index.data());
QDateEdit *dateEdit = qobject_cast<QDateEdit *>( editor->layout()->itemAt(0)->widget() );
QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit *>( editor->layout()->itemAt(1)->widget() );
QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox *>( editor->layout()->itemAt(2)->widget() );
entity.setDate(dateEdit->date());
entity.setDescription(textEdit->toPlainText());
entity.setAmount(spinBox->value());
QVariant val;
val.setValue<BudgetEntity>(entity);
model->setData(index, val, Qt::EditRole);
}
示例6: myPrintFunction
//! [45]
QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine)
{
QString result;
for (int i = 0; i < context->argumentCount(); ++i) {
if (i > 0)
result.append(" ");
result.append(context->argument(i).toString());
}
QScriptValue calleeData = context->callee().data();
QPlainTextEdit *edit = qobject_cast<QPlainTextEdit*>(calleeData.toQObject());
edit->appendPlainText(result);
return engine->undefinedValue();
}
示例7: testQtOutputFormatter_appendMessage
void QtSupportPlugin::testQtOutputFormatter_appendMessage()
{
QPlainTextEdit edit;
TestQtOutputFormatter formatter;
formatter.setPlainTextEdit(&edit);
QFETCH(QString, inputText);
QFETCH(QString, outputText);
QFETCH(QTextCharFormat, inputFormat);
QFETCH(QTextCharFormat, outputFormat);
formatter.appendMessage(inputText, inputFormat);
QCOMPARE(edit.toPlainText(), outputText);
QCOMPARE(edit.currentCharFormat(), outputFormat);
}
示例8: main
//! [46]
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QScriptEngine eng;
QPlainTextEdit edit;
QScriptValue fun = eng.newFunction(myPrintFunction);
fun.setData(eng.newQObject(&edit));
eng.globalObject().setProperty("print", fun);
eng.evaluate("print('hello', 'world')");
edit.show();
return app.exec();
}
示例9: QTextCursor
void PlainTextViewWidget::searchDocument(const QString &text, Qt::CaseSensitivity caseSensitive)
{
m_currentSearchResult = QTextCursor();
m_searchResults.clear();
QTextDocument::FindFlags findFlags;
if (caseSensitive == Qt::CaseSensitive) {
findFlags |= QTextDocument::FindCaseSensitively;
}
QPlainTextEdit *textEdit = ui->plainTextEdit;
QTextDocument *textDocument = textEdit->document();
QTextCursor currentCursor = textEdit->textCursor();
currentCursor.clearSelection(); // To get QTextDocument::find to work properly
// Find all results forwards beginning from current cursor
QTextCursor findCursor = textDocument->find(text, currentCursor, findFlags);
if (!findCursor.isNull()) {
// Set to first result after current cursor pos
m_currentSearchResult = findCursor;
}
while (!findCursor.isNull()) {
m_searchResults.append(findCursor);
findCursor = textDocument->find(text, findCursor, findFlags);
}
// Find all results backwards beginning from current cursor
findFlags |= QTextDocument::FindBackward;
findCursor = textDocument->find(text, currentCursor, findFlags);
while (!findCursor.isNull()) {
m_searchResults.prepend(findCursor);
findCursor = textDocument->find(text, findCursor, findFlags);
}
if (m_searchResults.isEmpty()) {
ui->searchBar->setResultNumberAndCount(0, 0);
return;
}
if (m_currentSearchResult.isNull()) {
// Set to first result because after current cursor pos wasn't a search match
m_currentSearchResult = m_searchResults.at(0);
}
jumpToHighlightResult(m_currentSearchResult);
}
示例10: moveCursorToEndOfName
// TODO: Can this be improved? This code is ripped from CppEditor, especially CppElementEvaluater
// We cannot depend on this since CppEditor plugin code is internal and requires building the implementation files ourselves
CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor()
{
EditorManager *editorManager = EditorManager::instance();
if (!editorManager)
return 0;
IEditor *editor = editorManager->currentEditor();
if (!editor)
return 0;
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor);
if (!textEditor)
return 0;
TextEditor::BaseTextEditorWidget *editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
if (!editorWidget)
return 0;
QPlainTextEdit *ptEdit = qobject_cast<QPlainTextEdit *>(editor->widget());
if (!ptEdit)
return 0;
QTextCursor tc;
tc = ptEdit->textCursor();
int line = 0;
int column = 0;
const int pos = tc.position();
editorWidget->convertPosition(pos, &line, &column);
const CPlusPlus::Snapshot &snapshot = CPlusPlus::CppModelManagerInterface::instance()->snapshot();
CPlusPlus::Document::Ptr doc = snapshot.document(editor->document()->fileName());
QTC_ASSERT(doc, return 0)
// fetch the expression's code
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
moveCursorToEndOfName(&tc);
const QString &expression = expressionUnderCursor(tc);
CPlusPlus::Scope *scope = doc->scopeAt(line, column);
CPlusPlus::TypeOfExpression typeOfExpression;
typeOfExpression.init(doc, snapshot);
const QList<CPlusPlus::LookupItem> &lookupItems = typeOfExpression(expression.toUtf8(), scope);
if (lookupItems.isEmpty())
return 0;
const CPlusPlus::LookupItem &lookupItem = lookupItems.first(); // ### TODO: select best candidate.
return lookupItem.declaration();
}
示例11: indentRegion
void FakeVimProxy::indentRegion(int beginBlock, int endBlock, QChar typedChar) {
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget);
if (!ed)
return;
const auto indentSize = theFakeVimSetting(FakeVim::Internal::ConfigShiftWidth)
->value().toInt();
QTextDocument *doc = ed->document();
QTextBlock startBlock = doc->findBlockByNumber(beginBlock);
// Record line lengths for mark adjustments
QVector<int> lineLengths(endBlock - beginBlock + 1);
QTextBlock block = startBlock;
for (int i = beginBlock; i <= endBlock; ++i) {
const auto line = block.text();
lineLengths[i - beginBlock] = line.length();
if (typedChar.unicode() == 0 && line.simplified().isEmpty()) {
// clear empty lines
QTextCursor cursor(block);
while (!cursor.atBlockEnd())
cursor.deleteChar();
} else {
const auto previousBlock = block.previous();
const auto previousLine = previousBlock.isValid() ? previousBlock.text() : QString();
int indent = firstNonSpace(previousLine);
if (typedChar == '}')
indent = std::max(0, indent - indentSize);
else if ( previousLine.endsWith("{") )
indent += indentSize;
const auto indentString = QString(" ").repeated(indent);
QTextCursor cursor(block);
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::StartOfBlock);
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, firstNonSpace(line));
cursor.removeSelectedText();
cursor.insertText(indentString);
cursor.endEditBlock();
}
block = block.next();
}
}
示例12: Q_D
int QScriptDebuggerCodeView::find(const QString &exp, int options)
{
Q_D(QScriptDebuggerCodeView);
QPlainTextEdit *ed = (QPlainTextEdit*)d->editor;
QTextCursor cursor = ed->textCursor();
if (options & 0x100) {
// start searching from the beginning of selection
if (cursor.hasSelection()) {
int len = cursor.selectedText().length();
cursor.clearSelection();
cursor.setPosition(cursor.position() - len);
ed->setTextCursor(cursor);
}
options &= ~0x100;
}
int ret = 0;
if (ed->find(exp, QTextDocument::FindFlags(options))) {
ret |= 0x1;
} else {
QTextCursor curse = cursor;
curse.movePosition(QTextCursor::Start);
ed->setTextCursor(curse);
if (ed->find(exp, QTextDocument::FindFlags(options)))
ret |= 0x1 | 0x2;
else
ed->setTextCursor(cursor);
}
return ret;
}
示例13: while
void Authorization::test_answer(QNetworkReply *reply)
{
QStringList html;
while (!reply->atEnd())
html << QString(reply->readLine());
QPlainTextEdit *text = new QPlainTextEdit();
text->appendPlainText(html.join('\n'));
QStringList headers;
QList<QByteArray> headerList = reply->request().rawHeaderList();
foreach (QByteArray header, headerList)
headers << QString(header+"\t"+reply->request().rawHeader(header));
text->appendPlainText(headers.join('\n'));
headerList = reply->rawHeaderList();
foreach (QByteArray header, headerList)
headers << QString(header+"\t"+reply->rawHeader(header));
text->appendPlainText(headers.join('\n'));
text->appendPlainText(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
text->appendPlainText(reply->errorString());
text->show();
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302) {
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request(QUrl(reply->rawHeader("Location")));
request.setHeader(QNetworkRequest::CookieHeader, reply->header(QNetworkRequest::SetCookieHeader));
manager->get(request);
connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(test_answer(QNetworkReply*)));
connect(manager, SIGNAL(finished(QNetworkReply*)), manager, SLOT(deleteLater()));
}
}
示例14: disconnect
void FakeVimProxy::requestDisableBlockSelection() {
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget);
if (!ed)
return;
QPalette pal = ed->parentWidget() != NULL ? ed->parentWidget()->palette()
: QApplication::palette();
m_blockSelection.clear();
m_clearSelection.clear();
ed->setPalette(pal);
disconnect( ed, &QPlainTextEdit::selectionChanged,
this, &FakeVimProxy::updateBlockSelection );
updateExtraSelections();
}
示例15: lock
void LogWindow::onTimeout()
{
QMap<QPlainTextEdit*, QStringList> updates;
QStringList buffer;
{
// lock scope
QMutexLocker lock(&sMutex);
buffer = mBuffer;
mBuffer = QStringList();
mAllBuffer = QString();
QMutableMapIterator<int, LogTypeStruct> messages(mLogTypes);
while(messages.hasNext())
{
LogTypeStruct& logType = messages.next().value();
if(logType.buffer.isEmpty())
continue;
updates.insert(logType.edit, logType.buffer);
logType.buffer = QStringList();
}
}
int maxBlocks = ui->plainTextEdit->maximumBlockCount();
int startElement = qMax(0, buffer.size()-maxBlocks);
for(int i=startElement; i<buffer.size(); i++)
{
ui->plainTextEdit->appendPlainText(buffer[i]);
}
QApplication::processEvents();
QMapIterator<QPlainTextEdit*, QStringList> iter(updates);
while(iter.hasNext())
{
iter.next();
QPlainTextEdit* edit = iter.key();
const QStringList& dataBuffer = iter.value();
maxBlocks = edit->maximumBlockCount();
startElement = qMax(0, dataBuffer.size()-maxBlocks);
for(int i=startElement; i<dataBuffer.size(); i++)
{
edit->appendPlainText(dataBuffer[i]);
}
QApplication::processEvents();
}
mTimer.start(300);
}