File: specialqtflags.html

package info (click to toggle)
qcustomplot 1.3.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,112 kB
  • ctags: 2,361
  • sloc: cpp: 17,354; sh: 1,555; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 10,382 bytes parent folder | download
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
<!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">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta name="author" content="Emanuel Eichhammer" />
<meta name="copyright" content="(C) 2013-2015 Emanuel Eichhammer" />
<title>Using QCustomPlot with special Qt define flags</title>
<link href="qt.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top">
<a class="headerLink"  href="index.html">Main Page</a> &middot;
<a class="headerLink"  href="classoverview.html">Class Overview</a> &middot;
<a class="headerLink"  href="hierarchy.html">Hierarchy</a> &middot;
<a class="headerLink"  href="annotated.html">All Classes</a> &middot;
<a class="headerLink"  href="pages.html">Special Pages</a>
<!-- Generated by Doxygen 1.8.6 -->
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Using <a class="el" href="classQCustomPlot.html" title="The central class of the library. This is the QWidget which displays the plot and interacts with the ...">QCustomPlot</a> with special Qt define flags </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="specialqtflags-noascii"></a>
Safe string casts with QT_NO_CAST_FROM_ASCII and QT_NO_CAST_TO_ASCII</h1>
<p><a class="el" href="classQCustomPlot.html" title="The central class of the library. This is the QWidget which displays the plot and interacts with the ...">QCustomPlot</a> can be compiled with the special Qt flags <code>QT_NO_CAST_FROM_ASCII</code> and <code>QT_NO_CAST_TO_ASCII</code> out of the box. All strings used in the library are wrapped in QLatin1String to avoid casts from string/char literals. So if your project requires the added cast safety from these Qt flags, you can use QCustomPlot without any changes necessary.</p>
<h1><a class="anchor" id="specialqtflags-nokeywords"></a>
Avoiding Qt specific language extensions with QT_NO_KEYWORDS</h1>
<p>QCustomPlot is a library based on and <em>written in</em> Qt. This means it uses Qt keywords such as <code>foreach</code>, <code>signal</code>, <code>slot</code> and <code>emit</code> for improved legibility.</p>
<p>However, some projects wish to disable these Qt specific language extensions by using the define flag <code>QT_NO_KEYWORDS</code>. To compile QCustomPlot with that flag set, it is necessary to replace all occurances of Qt keywords. This is easily done with QCustomPlot code, by using the following regular expression replacements:</p>
<table class="doxtable">
<tr>
<td style="text-align:center;font-weight:bold">Search pattern</td><td style="text-align:center;font-weight:bold">Replace with </td></tr>
<tr>
<td><code>(^|[^\a_])emit\s</code></td><td><code>\1Q_EMIT&#160;</code>&mdash;<span style="font-size:0.9em">note the trailing space</span> </td></tr>
<tr>
<td><code>^( *)signals:</code></td><td><code>\1Q_SIGNALS:</code> </td></tr>
<tr>
<td><code>(^|[^\a_])foreach( *)\(</code></td><td><code>\1Q_FOREACH\2(</code> </td></tr>
</table>
<p>QCustomPlot code is written with these replacements in mind. They always work and catch all occurances of used Qt keywords. Their functioning is also automatically tested upon every release.</p>
<p>The regular expressions can be applied in any IDE/Editor that supports them, including QtCreator itself. Below is a python script that is used to test the functioning of the regular expressions. It takes the names of the files to process (e.g. <em>qcustomplot.cpp qcustomplot.h</em>) from the command line and performs the replacement on them.</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">#!/usr/bin/env python</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;</div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"># This script is used to make the amalgamated sources qcustomplot.h/.cpp compatible</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"># to compiles with flag QT_NO_KEYWORDS set. It applies the following regular expression replacements</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment">#</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">#   (^|[^\a_])emit\s        -&gt;  \1Q_EMIT </span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment">#   ^( *)signals:           -&gt;  \1Q_SIGNALS:</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment">#   (^|[^\a_])foreach( *)\( -&gt;  \1Q_FOREACH\2(</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment">#</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"># to the files whose filenames are passed on the command line. The replacement can in principle be</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"># applied to the sources with any other tool or editor that knows regular expressions.</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment">#</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"># To test: Copy freshly amalgamated qcustomplot.h/.cpp files into this directory, call this script on</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"># them, and then run qmake; make</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="keyword">import</span> os, sys, re</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;baseDir = sys.path[0];</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;os.chdir(baseDir) <span class="comment"># change current working dir to script dir</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;  </div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="keyword">def </span>performKeywordReplacement(filename):</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;  <span class="keywordflow">print</span> <span class="stringliteral">&quot;making &#39;&quot;</span>+filename+<span class="stringliteral">&quot;&#39; no-keywords-compatible...&quot;</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;  patterns = []</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;  patterns.append((re.compile(<span class="stringliteral">&quot;(^|[^\\a_])emit\\s&quot;</span>), <span class="stringliteral">&quot;\\1Q_EMIT &quot;</span>))</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;  patterns.append((re.compile(<span class="stringliteral">&quot;^( *)signals:&quot;</span>), <span class="stringliteral">&quot;\\1Q_SIGNALS:&quot;</span>))</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;  patterns.append((re.compile(<span class="stringliteral">&quot;(^|[^\\a_])foreach( *)\\(&quot;</span>), <span class="stringliteral">&quot;\\1Q_FOREACH\\2(&quot;</span>))</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;  inFile = open(filename)</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;  outFilename = filename + <span class="stringliteral">&quot;.tmp&quot;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;  outFile = open(outFilename, <span class="stringliteral">&quot;w&quot;</span>)</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;  <span class="keywordflow">for</span> line <span class="keywordflow">in</span> inFile:</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <span class="keywordflow">for</span> patt <span class="keywordflow">in</span> patterns:</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;      line = re.sub(patt[0], patt[1], line)</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    outFile.write(line)</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;  outFile.close()</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;  inFile.close()</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;  os.remove(filename)</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;  os.rename(outFilename, filename)</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    </div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="keywordflow">for</span> filename <span class="keywordflow">in</span> sys.argv[1:]:</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;  <span class="keywordflow">if</span> <span class="keywordflow">not</span> os.path.isfile(filename):</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="keywordflow">print</span> <span class="stringliteral">&quot;file &#39;&quot;</span>+filename+<span class="stringliteral">&quot;&#39; not found&quot;</span></div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    sys.exit(-1)</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;  performKeywordReplacement(filename);</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;</div>
</div><!-- fragment --> </div></div><!-- contents -->
</body>
</html>