/usr/share/qt5/doc/qtxmlpatterns/qtxmlpatterns-xmlpatterns-schema-mainwindow-cpp.html is in qtxmlpatterns5-doc-html 5.2.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mainwindow.cpp Example File (xmlpatterns/schema/mainwindow.cpp) | QtXmlPatterns </title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li>Qt 5.2</li>
<li><a href="qtxmlpatterns-index.html">Qt XML Patterns</a></li>
<li>mainwindow.cpp Example File (xmlpatterns/schema/mainwindow.cpp)</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<h1 class="title">mainwindow.cpp Example File</h1>
<span class="small-subtitle">xmlpatterns/schema/mainwindow.cpp</span>
<!-- $$$xmlpatterns/schema/mainwindow.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp"><span class="comment">/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/</span>
<span class="preprocessor">#include <QtGui></span>
<span class="preprocessor">#include <QtXmlPatterns></span>
<span class="preprocessor">#include "mainwindow.h"</span>
<span class="preprocessor">#include "xmlsyntaxhighlighter.h"</span>
<span class="keyword">class</span> MessageHandler : <span class="keyword">public</span> <span class="type"><a href="qabstractmessagehandler.html">QAbstractMessageHandler</a></span>
{
<span class="keyword">public</span>:
MessageHandler()
: <span class="type"><a href="qabstractmessagehandler.html">QAbstractMessageHandler</a></span>(<span class="number">0</span>)
{
}
<span class="type">QString</span> statusMessage() <span class="keyword">const</span>
{
<span class="keyword">return</span> m_description;
}
<span class="type">int</span> line() <span class="keyword">const</span>
{
<span class="keyword">return</span> m_sourceLocation<span class="operator">.</span>line();
}
<span class="type">int</span> column() <span class="keyword">const</span>
{
<span class="keyword">return</span> m_sourceLocation<span class="operator">.</span>column();
}
<span class="keyword">protected</span>:
<span class="keyword">virtual</span> <span class="type">void</span> handleMessage(<span class="type">QtMsgType</span> type<span class="operator">,</span> <span class="keyword">const</span> <span class="type">QString</span> <span class="operator">&</span>description<span class="operator">,</span>
<span class="keyword">const</span> <span class="type">QUrl</span> <span class="operator">&</span>identifier<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qsourcelocation.html">QSourceLocation</a></span> <span class="operator">&</span>sourceLocation)
{
Q_UNUSED(type);
Q_UNUSED(identifier);
m_messageType <span class="operator">=</span> type;
m_description <span class="operator">=</span> description;
m_sourceLocation <span class="operator">=</span> sourceLocation;
}
<span class="keyword">private</span>:
<span class="type">QtMsgType</span> m_messageType;
<span class="type">QString</span> m_description;
<span class="type"><a href="qsourcelocation.html">QSourceLocation</a></span> m_sourceLocation;
};
MainWindow<span class="operator">::</span>MainWindow()
{
setupUi(<span class="keyword">this</span>);
<span class="keyword">new</span> XmlSyntaxHighlighter(schemaView<span class="operator">-</span><span class="operator">></span>document());
<span class="keyword">new</span> XmlSyntaxHighlighter(instanceEdit<span class="operator">-</span><span class="operator">></span>document());
schemaSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Contact Schema"</span>));
schemaSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Recipe Schema"</span>));
schemaSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Order Schema"</span>));
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Valid Contact Instance"</span>));
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Invalid Contact Instance"</span>));
connect(schemaSelection<span class="operator">,</span> SIGNAL(currentIndexChanged(<span class="type">int</span>))<span class="operator">,</span> SLOT(schemaSelected(<span class="type">int</span>)));
connect(instanceSelection<span class="operator">,</span> SIGNAL(currentIndexChanged(<span class="type">int</span>))<span class="operator">,</span> SLOT(instanceSelected(<span class="type">int</span>)));
connect(validateButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> SLOT(validate()));
connect(instanceEdit<span class="operator">,</span> SIGNAL(textChanged())<span class="operator">,</span> SLOT(textChanged()));
validationStatus<span class="operator">-</span><span class="operator">></span>setAlignment(<span class="type">Qt</span><span class="operator">::</span>AlignCenter <span class="operator">|</span> <span class="type">Qt</span><span class="operator">::</span>AlignVCenter);
schemaSelected(<span class="number">0</span>);
instanceSelected(<span class="number">0</span>);
}
<span class="type">void</span> MainWindow<span class="operator">::</span>schemaSelected(<span class="type">int</span> index)
{
instanceSelection<span class="operator">-</span><span class="operator">></span>clear();
<span class="keyword">if</span> (index <span class="operator">=</span><span class="operator">=</span> <span class="number">0</span>) {
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Valid Contact Instance"</span>));
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Invalid Contact Instance"</span>));
} <span class="keyword">else</span> <span class="keyword">if</span> (index <span class="operator">=</span><span class="operator">=</span> <span class="number">1</span>) {
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Valid Recipe Instance"</span>));
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Invalid Recipe Instance"</span>));
} <span class="keyword">else</span> <span class="keyword">if</span> (index <span class="operator">=</span><span class="operator">=</span> <span class="number">2</span>) {
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Valid Order Instance"</span>));
instanceSelection<span class="operator">-</span><span class="operator">></span>addItem(tr(<span class="string">"Invalid Order Instance"</span>));
}
textChanged();
<span class="type">QFile</span> schemaFile(<span class="type">QString</span>(<span class="string">":/schema_%1.xsd"</span>)<span class="operator">.</span>arg(index));
schemaFile<span class="operator">.</span>open(<span class="type">QIODevice</span><span class="operator">::</span>ReadOnly);
<span class="keyword">const</span> <span class="type">QString</span> schemaText(<span class="type">QString</span><span class="operator">::</span>fromUtf8(schemaFile<span class="operator">.</span>readAll()));
schemaView<span class="operator">-</span><span class="operator">></span>setPlainText(schemaText);
validate();
}
<span class="type">void</span> MainWindow<span class="operator">::</span>instanceSelected(<span class="type">int</span> index)
{
<span class="type">QFile</span> instanceFile(<span class="type">QString</span>(<span class="string">":/instance_%1.xml"</span>)<span class="operator">.</span>arg((<span class="number">2</span><span class="operator">*</span>schemaSelection<span class="operator">-</span><span class="operator">></span>currentIndex()) <span class="operator">+</span> index));
instanceFile<span class="operator">.</span>open(<span class="type">QIODevice</span><span class="operator">::</span>ReadOnly);
<span class="keyword">const</span> <span class="type">QString</span> instanceText(<span class="type">QString</span><span class="operator">::</span>fromUtf8(instanceFile<span class="operator">.</span>readAll()));
instanceEdit<span class="operator">-</span><span class="operator">></span>setPlainText(instanceText);
validate();
}
<span class="type">void</span> MainWindow<span class="operator">::</span>validate()
{
<span class="keyword">const</span> <span class="type">QByteArray</span> schemaData <span class="operator">=</span> schemaView<span class="operator">-</span><span class="operator">></span>toPlainText()<span class="operator">.</span>toUtf8();
<span class="keyword">const</span> <span class="type">QByteArray</span> instanceData <span class="operator">=</span> instanceEdit<span class="operator">-</span><span class="operator">></span>toPlainText()<span class="operator">.</span>toUtf8();
MessageHandler messageHandler;
<span class="type"><a href="qxmlschema.html">QXmlSchema</a></span> schema;
schema<span class="operator">.</span>setMessageHandler(<span class="operator">&</span>messageHandler);
schema<span class="operator">.</span>load(schemaData);
bool errorOccurred <span class="operator">=</span> <span class="keyword">false</span>;
<span class="keyword">if</span> (<span class="operator">!</span>schema<span class="operator">.</span>isValid()) {
errorOccurred <span class="operator">=</span> <span class="keyword">true</span>;
} <span class="keyword">else</span> {
<span class="type"><a href="qxmlschemavalidator.html">QXmlSchemaValidator</a></span> validator(schema);
<span class="keyword">if</span> (<span class="operator">!</span>validator<span class="operator">.</span>validate(instanceData))
errorOccurred <span class="operator">=</span> <span class="keyword">true</span>;
}
<span class="keyword">if</span> (errorOccurred) {
validationStatus<span class="operator">-</span><span class="operator">></span>setText(messageHandler<span class="operator">.</span>statusMessage());
moveCursor(messageHandler<span class="operator">.</span>line()<span class="operator">,</span> messageHandler<span class="operator">.</span>column());
} <span class="keyword">else</span> {
validationStatus<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"validation successful"</span>));
}
<span class="keyword">const</span> <span class="type">QString</span> styleSheet <span class="operator">=</span> <span class="type">QString</span>(<span class="string">"QLabel {background: %1; padding: 3px}"</span>)
<span class="operator">.</span>arg(errorOccurred <span class="operator">?</span> <span class="type">QColor</span>(<span class="type">Qt</span><span class="operator">::</span>red)<span class="operator">.</span>lighter(<span class="number">160</span>)<span class="operator">.</span>name() :
<span class="type">QColor</span>(<span class="type">Qt</span><span class="operator">::</span>green)<span class="operator">.</span>lighter(<span class="number">160</span>)<span class="operator">.</span>name());
validationStatus<span class="operator">-</span><span class="operator">></span>setStyleSheet(styleSheet);
}
<span class="type">void</span> MainWindow<span class="operator">::</span>textChanged()
{
instanceEdit<span class="operator">-</span><span class="operator">></span>setExtraSelections(<span class="type">QList</span><span class="operator"><</span><span class="type">QTextEdit</span><span class="operator">::</span>ExtraSelection<span class="operator">></span>());
}
<span class="type">void</span> MainWindow<span class="operator">::</span>moveCursor(<span class="type">int</span> line<span class="operator">,</span> <span class="type">int</span> column)
{
instanceEdit<span class="operator">-</span><span class="operator">></span>moveCursor(<span class="type">QTextCursor</span><span class="operator">::</span>Start);
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">1</span>; i <span class="operator"><</span> line; <span class="operator">+</span><span class="operator">+</span>i)
instanceEdit<span class="operator">-</span><span class="operator">></span>moveCursor(<span class="type">QTextCursor</span><span class="operator">::</span>Down);
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">1</span>; i <span class="operator"><</span> column; <span class="operator">+</span><span class="operator">+</span>i)
instanceEdit<span class="operator">-</span><span class="operator">></span>moveCursor(<span class="type">QTextCursor</span><span class="operator">::</span>Right);
<span class="type">QList</span><span class="operator"><</span><span class="type">QTextEdit</span><span class="operator">::</span>ExtraSelection<span class="operator">></span> extraSelections;
<span class="type">QTextEdit</span><span class="operator">::</span>ExtraSelection selection;
<span class="keyword">const</span> <span class="type">QColor</span> lineColor <span class="operator">=</span> <span class="type">QColor</span>(<span class="type">Qt</span><span class="operator">::</span>red)<span class="operator">.</span>lighter(<span class="number">160</span>);
selection<span class="operator">.</span>format<span class="operator">.</span>setBackground(lineColor);
selection<span class="operator">.</span>format<span class="operator">.</span>setProperty(<span class="type">QTextFormat</span><span class="operator">::</span>FullWidthSelection<span class="operator">,</span> <span class="keyword">true</span>);
selection<span class="operator">.</span>cursor <span class="operator">=</span> instanceEdit<span class="operator">-</span><span class="operator">></span>textCursor();
selection<span class="operator">.</span>cursor<span class="operator">.</span>clearSelection();
extraSelections<span class="operator">.</span>append(selection);
instanceEdit<span class="operator">-</span><span class="operator">></span>setExtraSelections(extraSelections);
instanceEdit<span class="operator">-</span><span class="operator">></span>setFocus();
}</pre>
</div>
<!-- @@@xmlpatterns/schema/mainwindow.cpp -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2013 Digia Plc and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|