本文整理汇总了C++中QTextDocumentFragment::toPlainText方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocumentFragment::toPlainText方法的具体用法?C++ QTextDocumentFragment::toPlainText怎么用?C++ QTextDocumentFragment::toPlainText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocumentFragment
的用法示例。
在下文中一共展示了QTextDocumentFragment::toPlainText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testPrefixMerge
void TestChangeTrackedDelete::testPrefixMerge()
{
TextTool *textTool = new TextTool(new MockCanvas);
KoTextEditor *textEditor = textTool->textEditor();
QVERIFY(textEditor);
QTextDocument *document = textEditor->document();
KTextDocumentLayout *layout = qobject_cast<KTextDocumentLayout*>(document->documentLayout());
QTextCursor *cursor = textEditor->cursor();
cursor->insertText("Hello World");
cursor->setPosition(3);
ChangeTrackedDeleteCommand *delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
textEditor->addCommand(delCommand);
QCOMPARE(document->characterAt(3).unicode(), (ushort)(QChar::ObjectReplacementCharacter));
cursor->setPosition(4);
delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
textEditor->addCommand(delCommand);
// This is wierd. Without this loop present the succeeding call to inlineTextObject returs NULL. Why ??????
for (int i=0; i<document->characterCount(); i++) {
cursor->setPosition(i);
}
cursor->setPosition(4);
KDeleteChangeMarker *testMarker = dynamic_cast<KDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(*cursor));
QTextDocumentFragment deleteData = KTextDocument(document).changeTracker()->elementById(testMarker->changeId())->deleteData();
QCOMPARE(deleteData.toPlainText(), QString("lo"));
delete textTool;
}
示例2: createMimeDataFromSelection
QMimeData* QTextBrowserEx::createMimeDataFromSelection() const
{
QMimeData *data = new QMimeData();
QTextCursor txtCursor = textCursor();
QTextDocumentFragment htmlFrag = txtCursor.selection();
data->setHtml(htmlFrag.toHtml());
data->setText(htmlFrag.toPlainText());
QString html = htmlFrag.toHtml();
QList<QPair<QString,QTextCharFormat>> frags;
getSelectTextFragments(frags);
QList<QByteArray> lstFrags;
for(int i = 0; i < frags.count(); i++)
{
const QPair<QString,QTextCharFormat> &frag = frags.at(i);
QString txt = frag.first;
QTextCharFormat txtfmt = frag.second;
QByteArray buf;
QDataStream ds(&buf, QIODevice::WriteOnly);
ds << txt << txtfmt;
lstFrags.push_back(buf);
}
QByteArray fragsBuffer;
QDataStream dataStream(&fragsBuffer, QIODevice::WriteOnly);
dataStream << lstFrags;
data->setData(KTextEditMime, fragsBuffer);
return data;
}
示例3: main
int main(int argc, char *argv[]){
// here the QT_program is created
QApplication app(argc, argv);
//Qt translations
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
//My translations
QTranslator translator;
QString trDir = "/usr/share/qshutdown/translations/";
translator.load(trDir + "qshutdown-" + QLocale::system().name());
app.installTranslator(&translator);
QTextStream myOutput(stdout);
if(!QProcessEnvironment().isEmpty())
shell = QProcess::systemEnvironment().filter("SHELL").first().remove("SHELL=");
if(shell.isEmpty() && QFile("/bin/bash").exists())
shell = "/bin/bash";
else
myOutput << "E: No shell found! Custom commands won't work!";
QString infoStr = QString(QObject::tr("qshutdown will show itself 3 times as a warning "
"if there are less than 70 seconds left.<br/><br/>This program uses qdbus to send a "
"shutdown/reboot/suspend/hibernate request to either the gnome- or "
"kde-session-manager, to HAL/ConsoleKit/DeviceKit/UPower and if none of these works, the "
"command 'sudo shutdown' will be used (note that when sending the shutdown request to HAL or "
"ConsoleKit, or the shutdown command is used, the Session will never be saved. If the "
"shutdown command is used, the program will only be able to shutdown and reboot). So "
"if nothing happens when the shutdown- or reboot-time is reached, it means that one "
"lacks the rights for the shutdown command. In this case one can do the following:"
"<br/><br/>Paste the following in a terminal:<pre>EDITOR=nano sudo -E visudo</pre>and "
"add this line:<pre>* ALL = NOPASSWD:/sbin/shutdown</pre>whereas * replaces the "
"user name or %group name.<br/><br/>The maximum Number of countdown_minutes is "
"1440 (24 hours).<br/>The configuration file (and logfile) is located at "
"<i>~/.qshutdown/</i> (under Linux/Unix).<br/><br/><b>For admins:</b><br/>If you want "
"qshutdown to run with \"parental lock\" for every user, you can do "
"\"sudo cp /usr/share/qshutdown/autostart/99qshutdown /etc/X11/Xsession.d/\" "
"and set the option Lock_all in /root/.qshutdown/qshutdown.conf to true. Note that "
"qshutdown has to start once to generate the qshutdown.conf. Furthermore there is a "
"need to add the following line to the sudoers (as above):"
"<pre>* ALL = NOPASSWD:/usr/bin/qshutdown</pre><br/>If you should ever forget "
"your set password, just remove the whole line starting with \"Password\" manually from "
"the qshutdown.conf.<br/><br/><b>Hints on usage:</b><br/>If you want qshutdown to stop "
"\"bugging\" you, just remove the hook from "
"\"warnings on?\".<br/><br/><b>Hotkeys:</b><table border=\"1\"><tr><td>Ctrl+I</td><td>(this)"
" information window</td></tr><tr><td>Ctrl+Q</td><td>Quit</td></tr><tr><td>Ctrl+P</td>"
"<td>Preferences</td></tr><tr><td>Ctrl+L</td><td>write the run time once into the logfile (works "
"only if qshutdown quits. To make it permanent set it in the preferences.)</td></tr><tr>"
"<td>Ctrl+S</td><td>set to shutdown</td></tr><tr><td>Ctrl+R</td><td>set to restart</td></tr>"
"<tr><td>Ctrl+U</td><td>set to suspend to RAM</td></tr><tr><td>Ctrl+H</td><td>set to hibernate"
"</td></tr><tr><td>Ctrl+E</td><td>stop countdown (only if the countdown has started and the admin "
"didn't restrict the access)</td></tr><tr><td>Shift+E</td><td>to edit the configuration file (for "
"this a password is necessary. If you are a user, you can set an \"empty password\" (leave the "
"password field empty)).</td></tr></table>"));
QTextDocumentFragment infoDoc;
infoDoc = QTextDocumentFragment::fromHtml(infoStr);
QString info = infoDoc.toPlainText();
//Get the arguments passed from the terminal
QStringList args = QApplication::arguments();
args.removeFirst(); //this is just the program
for(int i=1; i<args.size();args.removeLast());
if(!args.empty()){
QString arg = args[0];
if(arg[0] == '-'){
if(arg[1] == 'h' || arg == "--help")
myOutput << "\nqshutdown [ options ... ]\n\nOptions are:\n\t-h "
<< "or --help\tPrints this message.\n\t-i\t\tPrints "
<< "information.\n\t-v\t\tPrints all errors and warnings.\n"
<< "\t-s or --start\tStarts the countdown for the set time."
<< endl;
if(arg[1] == 'i')
myOutput << info << endl;
}
if(arg != "-h" && arg != "--help" && arg != "-i"
&& !((arg[0] == '-' && (arg.contains("s") || arg.contains("v")))
|| args.contains("--start")))
myOutput << "Wrong options! Try qshutdown -h" << endl;
if(arg.contains("-") && arg.contains("-v"))
verbose = true;
}
if(!args.empty() && !((args[0][0] == '-' && (args[0].contains("v")
|| args[0].contains("s"))) || args.contains("--start")))
exit(0);
Gui window; //Create the main widget
#ifndef Q_OS_WIN32
QDBusConnection::sessionBus().registerObject(OBJECT_NAME, &window,
QDBusConnection::ExportScriptableSlots);
if(QDBusConnection::sessionBus().registerService(SERVICE_NAME)){
//if possible register qshutdown as a service in the session bus
#endif //Q_OS_WIN32
window.information = infoStr;
//.........这里部分代码省略.........