~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qvalidator.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/gui/widgets/qvalidator.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QValidator Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QValidator Class Reference</h1>
 
21
<p>The QValidator class provides validation of input text. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QValidator&gt;</pre><p>Part of the <a href="qtgui.html">QtGui</a> module.</p>
 
23
<p>Inherits <a href="qobject.html">QObject</a>.</p>
 
24
<p>Inherited by <a href="qdoublevalidator.html">QDoubleValidator</a>, <a href="qintvalidator.html">QIntValidator</a>, and <a href="qregexpvalidator.html">QRegExpValidator</a>.</p>
 
25
<ul>
 
26
<li><a href="qvalidator-members.html">List of all members, including inherited members</a></li>
 
27
<li><a href="qvalidator-qt3.html">Qt 3 support members</a></li>
 
28
</ul>
 
29
<a name="public-types"></a>
 
30
<h3>Public Types</h3>
 
31
<ul>
 
32
<li><div class="fn"/>enum <b><a href="qvalidator.html#State-enum">State</a></b> { Invalid, Intermediate, Acceptable }</li>
 
33
</ul>
 
34
<a name="public-functions"></a>
 
35
<h3>Public Functions</h3>
 
36
<ul>
 
37
<li><div class="fn"/><b><a href="qvalidator.html#QValidator">QValidator</a></b> ( QObject * <i>parent</i> )</li>
 
38
<li><div class="fn"/><b><a href="qvalidator.html#dtor.QValidator">~QValidator</a></b> ()</li>
 
39
<li><div class="fn"/>virtual void <b><a href="qvalidator.html#fixup">fixup</a></b> ( QString &amp; <i>input</i> ) const</li>
 
40
<li><div class="fn"/>virtual State <b><a href="qvalidator.html#validate">validate</a></b> ( QString &amp; <i>input</i>, int &amp; <i>pos</i> ) const = 0</li>
 
41
</ul>
 
42
<ul>
 
43
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
44
</ul>
 
45
<h3>Additional Inherited Members</h3>
 
46
<ul>
 
47
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
48
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
49
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
50
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
51
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
52
</ul>
 
53
<a name="details"></a>
 
54
<hr />
 
55
<h2>Detailed Description</h2>
 
56
<p>The QValidator class provides validation of input text.</p>
 
57
<p>The class itself is abstract. Two subclasses, <a href="qintvalidator.html">QIntValidator</a> and <a href="qdoublevalidator.html">QDoubleValidator</a>, provide basic numeric-range checking, and <a href="qregexpvalidator.html">QRegExpValidator</a> provides general checking using a custom regular expression.</p>
 
58
<p>If the built-in validators aren't sufficient, you can subclass QValidator. The class has two virtual functions: <a href="qvalidator.html#validate">validate</a>() and <a href="qvalidator.html#fixup">fixup</a>().</p>
 
59
<p><a href="qvalidator.html#validate">validate</a>() must be implemented by every subclass. It returns <tt>Invalid</tt>, <tt>Intermediate</tt> or <tt>Acceptable</tt> depending on whether its argument is valid (for the subclass's definition of valid).</p>
 
60
<p>These three states require some explanation. An <tt>Invalid</tt> string is <i>clearly</i> invalid. <tt>Intermediate</tt> is less obvious: the concept of validity is difficult to apply when the string is incomplete (still being edited). QValidator defines <tt>Intermediate</tt> as the property of a string that is neither clearly invalid nor acceptable as a final result. <tt>Acceptable</tt> means that the string is acceptable as a final result. One might say that any string that is a plausible intermediate state during entry of an <tt>Acceptable</tt> string is <tt>Intermediate</tt>.</p>
 
61
<p>Here are some examples:</p>
 
62
<ul>
 
63
<li>For a line edit that accepts integers from 10 to 999 inclusive, 42 and 123 are <tt>Acceptable</tt>, the empty string and 5 are <tt>Intermediate</tt>, and &quot;asdf&quot; and 1114 is <tt>Invalid</tt>.</li>
 
64
<li>For an editable combobox that accepts URLs, any well-formed URL is <tt>Acceptable</tt>, &quot;http://www.trolltech.com/,&quot; is <tt>Intermediate</tt> (it might be a cut and paste action that accidentally took in a comma at the end), the empty string is <tt>Intermediate</tt> (the user might select and delete all of the text in preparation for entering a new URL) and &quot;http:///./&quot; is <tt>Invalid</tt>.</li>
 
65
<li>For a spin box that accepts lengths, &quot;11cm&quot; and &quot;1in&quot; are <tt>Acceptable</tt>, &quot;11&quot; and the empty string are <tt>Intermediate</tt>, and &quot;http://www.trolltech.com&quot; and &quot;hour&quot; are <tt>Invalid</tt>.</li>
 
66
</ul>
 
67
<p><a href="qvalidator.html#fixup">fixup</a>() is provided for validators that can repair some user errors. The default implementation does nothing. <a href="qlineedit.html">QLineEdit</a>, for example, will call <a href="qvalidator.html#fixup">fixup</a>() if the user presses Enter (or Return) and the content is not currently valid. This allows the <a href="qvalidator.html#fixup">fixup</a>() function the opportunity of performing some magic to make an <tt>Invalid</tt> string <tt>Acceptable</tt>.</p>
 
68
<p>QValidator is typically used with <a href="qlineedit.html">QLineEdit</a>, <a href="qspinbox.html">QSpinBox</a> and <a href="qcombobox.html">QComboBox</a>.</p>
 
69
<hr />
 
70
<h2>Member Type Documentation</h2>
 
71
<h3 class="fn"><a name="State-enum"></a>enum QValidator::State</h3>
 
72
<p>This enum type defines the states in which a validated string can exist.</p>
 
73
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
74
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
75
<tr><td valign="top"><tt>QValidator::Invalid</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">The string is <i>clearly</i> invalid.</td></tr>
 
76
<tr><td valign="top"><tt>QValidator::Intermediate</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">The string is a plausible intermediate value during editing.</td></tr>
 
77
<tr><td valign="top"><tt>QValidator::Acceptable</tt></td><td align="center" valign="top">&nbsp;</td><td valign="top">The string is acceptable as a final result; i.e. it is valid.</td></tr>
 
78
</table>
 
79
<hr />
 
80
<h2>Member Function Documentation</h2>
 
81
<h3 class="fn"><a name="QValidator"></a>QValidator::QValidator ( <a href="qobject.html">QObject</a> * <i>parent</i> )</h3>
 
82
<p>Sets up the validator. The <i>parent</i> parameter is passed on to the <a href="qobject.html">QObject</a> constructor.</p>
 
83
<h3 class="fn"><a name="dtor.QValidator"></a>QValidator::~QValidator ()</h3>
 
84
<p>Destroys the validator, freeing any storage and other resources used.</p>
 
85
<h3 class="fn"><a name="fixup"></a>void QValidator::fixup ( <a href="qstring.html">QString</a> &amp; <i>input</i> ) const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
86
<p>This function attempts to change <i>input</i> to be valid according to this validator's rules. It need not result in a valid string: callers of this function must re-test afterwards; the default does nothing.</p>
 
87
<p>Reimplementations of this function can change <i>input</i> even if they do not produce a valid string. For example, an ISBN validator might want to delete every character except digits and &quot;-&quot;, even if the result is still not a valid ISBN; a surname validator might want to remove whitespace from the start and end of the string, even if the resulting string is not in the list of accepted surnames.</p>
 
88
<h3 class="fn"><a name="validate"></a><a href="qvalidator.html#State-enum">State</a> QValidator::validate ( <a href="qstring.html">QString</a> &amp; <i>input</i>, int &amp; <i>pos</i> ) const&nbsp;&nbsp;<tt> [pure virtual]</tt></h3>
 
89
<p>This virtual function returns <tt>Invalid</tt> if <i>input</i> is invalid according to this validator's rules, <tt>Intermediate</tt> if it is likely that a little more editing will make the input acceptable (e.g. the user types &quot;4&quot; into a widget which accepts integers between 10 and 99), and <tt>Acceptable</tt> if the input is valid.</p>
 
90
<p>The function can change both <i>input</i> and <i>pos</i> (the cursor position) if required.</p>
 
91
<p /><address><hr /><div align="center">
 
92
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
93
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
94
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
95
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
96
</tr></table></div></address></body>
 
97
</html>