mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
[OP-835] Qt 5.1.0 - removed libs/qxt as it is now part of Qt
This commit is contained in:
parent
2d3076e9b8
commit
7bcb82478d
@ -1,7 +0,0 @@
|
||||
Arvid Picciani <aep@libqxt.org>
|
||||
Adam Higerd <ahigerd@libqxt.org>
|
||||
J-P Nurmi <jpnurmi@libqxt.org>
|
||||
Benjamin Zeller <zbenjamin@libqxt.org>
|
||||
Thomas Mueller <deepdiver@libqxt.org>
|
||||
|
||||
thanks for all the minor contributions, bug reports, beta tests, and the free beer :-)
|
@ -1,89 +0,0 @@
|
||||
Qt Extension Library
|
||||
Copyright (C) 2007 Qxt Foundation
|
||||
|
||||
------------------- Disclaimer ------------------------------------------------
|
||||
|
||||
Until the Qxt Foundation is legally established, copyright for the
|
||||
source code falls back to the original contributor. For information about the
|
||||
status of the Qxt Foundation, or about the copyright status of any part of Qxt,
|
||||
contact the Qxt project maintainers at <foundation@libqxt.org>
|
||||
|
||||
Once the Qxt Foundation has been legally established, all contributors must
|
||||
transfer all copyright interest to the Qxt Foundation before their submissions
|
||||
will be added to the project.
|
||||
|
||||
------------------- License ---------------------------------------------------
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the terms of the Common Public License, version 1.0, as published by IBM
|
||||
or under the terms of the GNU Lesser General Public License, version 2.1,
|
||||
as published by the Free Software Foundation
|
||||
|
||||
This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
You should have received a copy of the CPL along with this file.
|
||||
See the LICENSE file and the cpl1.0.txt file included with the source
|
||||
distribution for more information. If you did not receive a copy of the
|
||||
license, contact the Qxt Foundation.
|
||||
|
||||
You should have received a copy of the LGPL along with this file.
|
||||
See the LICENSE file and the lgpl-2.1.txt file included with the source
|
||||
distribution for more information. If you did not receive a copy of the
|
||||
license, contact the Qxt Foundation.
|
||||
|
||||
Parts of Qxt depend on Qt 4 and/or other libraries that have their own
|
||||
licenses. Qxt is independent of these licenses; however, use of these other
|
||||
libraries is subject to their respective license agreements.
|
||||
|
||||
------------------- Intent ----------------------------------------------------
|
||||
|
||||
The following section describes the opinions and intent of the Qxt Foundation
|
||||
with regards to the licensing and use of the Qxt source code and library. In
|
||||
the event that the CPL is found to be illegal or invalid, or if any application
|
||||
or clause of the license is subjected to question or abuse, this section is a
|
||||
general statement of the desired interpretation.
|
||||
|
||||
This section has no legal standing and the statements made here are strictly
|
||||
subject to the text of the CPL; that is, if this section and the CPL are in
|
||||
disagreement, the text of the CPL takes precedence. In no way does this
|
||||
intent grant you any additional rights or impose any additional restrictions.
|
||||
|
||||
If you have questions about licensing, contact the maintainers.
|
||||
|
||||
Qxt is built and supported by open-source enthusiasts.
|
||||
- Please respect the open-source background of the contributors. The code is
|
||||
provided for everyone's use; you may not restrict the rights of anyone to
|
||||
use it.
|
||||
- No individual may claim ownership of any part of the code. It belongs
|
||||
to the community.
|
||||
- You may modify the source code to suit your needs, but these changes
|
||||
must be made free. If you distribute a modified form of Qxt, you must
|
||||
also distribute the entire source code of the modified form.
|
||||
- Digital Rights Management (DRM) puts unfair, unfree restrictions on
|
||||
users and developers. It is the opposite of Free Software. We can't
|
||||
stop you from using it, but please don't use the Qxt name for software
|
||||
restricted by DRM.
|
||||
- Please respect the time and effort put into the project by the developers.
|
||||
- If you find Qxt useful, it would be appreciated if you would include
|
||||
text in your application (for instance, in the About dialog) giving
|
||||
acknowledgement to Qxt.
|
||||
- If you make modifications to the source code, you must not call the
|
||||
modified version "Qxt." It's okay to include "Qxt" in the name, but
|
||||
anyone who receives the modified version needs to know that it's not
|
||||
the same as the version distributed by the Qxt Foundation.
|
||||
- We want everyone to be able to use Qxt without restrictions.
|
||||
- If you distribute Qxt in compiled binary form, please ensure that
|
||||
everyone who receives it can get the source code used to create it.
|
||||
- You are free to use Qxt in closed-source applications as long as you
|
||||
distribute Qxt in an open-source fashion. This does not require you
|
||||
to make your entire application open-source.
|
||||
- The Qxt Foundation is a non-profit, non-political organization.
|
||||
- Please don't use the Qxt name in any political or semi-political
|
||||
propaganda or publication. We don't like it.
|
||||
- Qxt is distributed "as-is," with no warranty.
|
||||
- If it makes your program crash, your computer blow up, or tiny demons
|
||||
fly out of your nose, please don't sue us.
|
||||
|
@ -1,39 +0,0 @@
|
||||
1) configure
|
||||
|
||||
make sure qmake is in your PATH and run ./configure or configure.bat on windows.
|
||||
|
||||
see configure --help for more information
|
||||
|
||||
(for msvc you could try ./configure.bat -msvc and open
|
||||
the solution file in msvc, we recomend compiling on
|
||||
commandline though)
|
||||
|
||||
2) build
|
||||
|
||||
type make or nmake when using msvc
|
||||
then don't forget to make install
|
||||
Note: This will also install qxt.prf to your qtdir/mkspecs/features directory.
|
||||
|
||||
|
||||
|
||||
3) use
|
||||
|
||||
Add the following lines to your qmake project file:
|
||||
CONFIG += qxt
|
||||
QXT += core gui
|
||||
|
||||
The QXT variable should contain the modules you want. (In this example core and gui are used.)
|
||||
Note: Some modules depend on other modules. The required modules are added automatically.
|
||||
|
||||
if you have an existing msvc project and can't swtich to qmake you can use zbenjamins solution:
|
||||
|
||||
Howto use libqxt in a existing Visual Studio Project:
|
||||
1. create and install libqxt. (See install instructions)
|
||||
2. add {libqxtinstalldir}\include\qxt\QxtCore to your include path
|
||||
3. add {libqxtinstalldir}\lib to your library search path
|
||||
4. to add a specific libqxt module (f.e QxtSql) you have to:
|
||||
- add {libqxtinstalldir}\include\qxt\QxtSql to your include path
|
||||
- add the library QxtSql.lib to your project
|
||||
Most of the times you have also to include the QxtCore and QxtKit modules.
|
||||
It's done the same way like the example above.
|
||||
|
@ -1,213 +0,0 @@
|
||||
|
||||
|
||||
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC
|
||||
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
|
||||
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
||||
|
||||
1. DEFINITIONS
|
||||
|
||||
"Contribution" means:
|
||||
|
||||
a) in the case of the initial Contributor, the initial code and
|
||||
documentation distributed under this Agreement, and
|
||||
|
||||
b) in the case of each subsequent Contributor:
|
||||
|
||||
i) changes to the Program, and
|
||||
|
||||
ii) additions to the Program;
|
||||
|
||||
where such changes and/or additions to the Program originate from and are
|
||||
distributed by that particular Contributor. A Contribution 'originates' from a
|
||||
Contributor if it was added to the Program by such Contributor itself or anyone
|
||||
acting on such Contributor's behalf. Contributions do not include additions to
|
||||
the Program which: (i) are separate modules of software distributed in
|
||||
conjunction with the Program under their own license agreement, and (ii) are not
|
||||
derivative works of the Program.
|
||||
|
||||
"Contributor" means any person or entity that distributes the Program.
|
||||
|
||||
"Licensed Patents " mean patent claims licensable by a Contributor which are
|
||||
necessarily infringed by the use or sale of its Contribution alone or when
|
||||
combined with the Program.
|
||||
|
||||
"Program" means the Contributions distributed in accordance with this Agreement.
|
||||
|
||||
"Recipient" means anyone who receives the Program under this Agreement,
|
||||
including all Contributors.
|
||||
|
||||
2. GRANT OF RIGHTS
|
||||
|
||||
a) Subject to the terms of this Agreement, each Contributor hereby grants
|
||||
Recipient a non-exclusive, worldwide, royalty-free copyright license to
|
||||
reproduce, prepare derivative works of, publicly display, publicly perform,
|
||||
distribute and sublicense the Contribution of such Contributor, if any, and such
|
||||
derivative works, in source code and object code form.
|
||||
|
||||
b) Subject to the terms of this Agreement, each Contributor hereby grants
|
||||
Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed
|
||||
Patents to make, use, sell, offer to sell, import and otherwise transfer the
|
||||
Contribution of such Contributor, if any, in source code and object code form.
|
||||
This patent license shall apply to the combination of the Contribution and the
|
||||
Program if, at the time the Contribution is added by the Contributor, such
|
||||
addition of the Contribution causes such combination to be covered by the
|
||||
Licensed Patents. The patent license shall not apply to any other combinations
|
||||
which include the Contribution. No hardware per se is licensed hereunder.
|
||||
|
||||
c) Recipient understands that although each Contributor grants the licenses
|
||||
to its Contributions set forth herein, no assurances are provided by any
|
||||
Contributor that the Program does not infringe the patent or other intellectual
|
||||
property rights of any other entity. Each Contributor disclaims any liability to
|
||||
Recipient for claims brought by any other entity based on infringement of
|
||||
intellectual property rights or otherwise. As a condition to exercising the
|
||||
rights and licenses granted hereunder, each Recipient hereby assumes sole
|
||||
responsibility to secure any other intellectual property rights needed, if any.
|
||||
For example, if a third party patent license is required to allow Recipient to
|
||||
distribute the Program, it is Recipient's responsibility to acquire that license
|
||||
before distributing the Program.
|
||||
|
||||
d) Each Contributor represents that to its knowledge it has sufficient
|
||||
copyright rights in its Contribution, if any, to grant the copyright license set
|
||||
forth in this Agreement.
|
||||
|
||||
3. REQUIREMENTS
|
||||
|
||||
A Contributor may choose to distribute the Program in object code form under its
|
||||
own license agreement, provided that:
|
||||
|
||||
a) it complies with the terms and conditions of this Agreement; and
|
||||
|
||||
b) its license agreement:
|
||||
|
||||
i) effectively disclaims on behalf of all Contributors all warranties and
|
||||
conditions, express and implied, including warranties or conditions of title and
|
||||
non-infringement, and implied warranties or conditions of merchantability and
|
||||
fitness for a particular purpose;
|
||||
|
||||
ii) effectively excludes on behalf of all Contributors all liability for
|
||||
damages, including direct, indirect, special, incidental and consequential
|
||||
damages, such as lost profits;
|
||||
|
||||
iii) states that any provisions which differ from this Agreement are offered
|
||||
by that Contributor alone and not by any other party; and
|
||||
|
||||
iv) states that source code for the Program is available from such
|
||||
Contributor, and informs licensees how to obtain it in a reasonable manner on or
|
||||
through a medium customarily used for software exchange.
|
||||
|
||||
When the Program is made available in source code form:
|
||||
|
||||
a) it must be made available under this Agreement; and
|
||||
|
||||
b) a copy of this Agreement must be included with each copy of the Program.
|
||||
|
||||
Contributors may not remove or alter any copyright notices contained within the
|
||||
Program.
|
||||
|
||||
Each Contributor must identify itself as the originator of its Contribution, if
|
||||
any, in a manner that reasonably allows subsequent Recipients to identify the
|
||||
originator of the Contribution.
|
||||
|
||||
4. COMMERCIAL DISTRIBUTION
|
||||
|
||||
Commercial distributors of software may accept certain responsibilities with
|
||||
respect to end users, business partners and the like. While this license is
|
||||
intended to facilitate the commercial use of the Program, the Contributor who
|
||||
includes the Program in a commercial product offering should do so in a manner
|
||||
which does not create potential liability for other Contributors. Therefore, if
|
||||
a Contributor includes the Program in a commercial product offering, such
|
||||
Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
|
||||
every other Contributor ("Indemnified Contributor") against any losses, damages
|
||||
and costs (collectively "Losses") arising from claims, lawsuits and other legal
|
||||
actions brought by a third party against the Indemnified Contributor to the
|
||||
extent caused by the acts or omissions of such Commercial Contributor in
|
||||
connection with its distribution of the Program in a commercial product
|
||||
offering. The obligations in this section do not apply to any claims or Losses
|
||||
relating to any actual or alleged intellectual property infringement. In order
|
||||
to qualify, an Indemnified Contributor must: a) promptly notify the Commercial
|
||||
Contributor in writing of such claim, and b) allow the Commercial Contributor to
|
||||
control, and cooperate with the Commercial Contributor in, the defense and any
|
||||
related settlement negotiations. The Indemnified Contributor may participate in
|
||||
any such claim at its own expense.
|
||||
|
||||
For example, a Contributor might include the Program in a commercial product
|
||||
offering, Product X. That Contributor is then a Commercial Contributor. If that
|
||||
Commercial Contributor then makes performance claims, or offers warranties
|
||||
related to Product X, those performance claims and warranties are such
|
||||
Commercial Contributor's responsibility alone. Under this section, the
|
||||
Commercial Contributor would have to defend claims against the other
|
||||
Contributors related to those performance claims and warranties, and if a court
|
||||
requires any other Contributor to pay any damages as a result, the Commercial
|
||||
Contributor must pay those damages.
|
||||
|
||||
5. NO WARRANTY
|
||||
|
||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
||||
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
|
||||
Recipient is solely responsible for determining the appropriateness of using and
|
||||
distributing the Program and assumes all risks associated with its exercise of
|
||||
rights under this Agreement, including but not limited to the risks and costs of
|
||||
program errors, compliance with applicable laws, damage to or loss of data,
|
||||
programs or equipment, and unavailability or interruption of operations.
|
||||
|
||||
6. DISCLAIMER OF LIABILITY
|
||||
|
||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
|
||||
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
|
||||
PROFITS), 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 OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS
|
||||
GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
7. GENERAL
|
||||
|
||||
If any provision of this Agreement is invalid or unenforceable under applicable
|
||||
law, it shall not affect the validity or enforceability of the remainder of the
|
||||
terms of this Agreement, and without further action by the parties hereto, such
|
||||
provision shall be reformed to the minimum extent necessary to make such
|
||||
provision valid and enforceable.
|
||||
|
||||
If Recipient institutes patent litigation against a Contributor with respect to
|
||||
a patent applicable to software (including a cross-claim or counterclaim in a
|
||||
lawsuit), then any patent licenses granted by that Contributor to such Recipient
|
||||
under this Agreement shall terminate as of the date such litigation is filed. In
|
||||
addition, if Recipient institutes patent litigation against any entity
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that the Program
|
||||
itself (excluding combinations of the Program with other software or hardware)
|
||||
infringes such Recipient's patent(s), then such Recipient's rights granted under
|
||||
Section 2(b) shall terminate as of the date such litigation is filed.
|
||||
|
||||
All Recipient's rights under this Agreement shall terminate if it fails to
|
||||
comply with any of the material terms or conditions of this Agreement and does
|
||||
not cure such failure in a reasonable period of time after becoming aware of
|
||||
such noncompliance. If all Recipient's rights under this Agreement terminate,
|
||||
Recipient agrees to cease use and distribution of the Program as soon as
|
||||
reasonably practicable. However, Recipient's obligations under this Agreement
|
||||
and any licenses granted by Recipient relating to the Program shall continue and
|
||||
survive.
|
||||
|
||||
Everyone is permitted to copy and distribute copies of this Agreement, but in
|
||||
order to avoid inconsistency the Agreement is copyrighted and may only be
|
||||
modified in the following manner. The Agreement Steward reserves the right to
|
||||
publish new versions (including revisions) of this Agreement from time to time.
|
||||
No one other than the Agreement Steward has the right to modify this Agreement.
|
||||
IBM is the initial Agreement Steward. IBM may assign the responsibility to serve
|
||||
as the Agreement Steward to a suitable separate entity. Each new version of the
|
||||
Agreement will be given a distinguishing version number. The Program (including
|
||||
Contributions) may always be distributed subject to the version of the Agreement
|
||||
under which it was received. In addition, after a new version of the Agreement
|
||||
is published, Contributor may elect to distribute the Program (including its
|
||||
Contributions) under the new version. Except as expressly stated in Sections
|
||||
2(a) and 2(b) above, Recipient receives no rights or licenses to the
|
||||
intellectual property of any Contributor under this Agreement, whether
|
||||
expressly, by implication, estoppel or otherwise. All rights in the Program not
|
||||
expressly granted under this Agreement are reserved.
|
||||
|
||||
This Agreement is governed by the laws of the State of New York and the
|
||||
intellectual property laws of the United States of America. No party to this
|
||||
Agreement will bring a legal action under this Agreement more than one year
|
||||
after the cause of action arose. Each party waives its rights to a jury trial in
|
||||
any resulting litigation.
|
@ -1,504 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
LIBS *= -l$$qtLibraryName(QxtCore)
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$GCS_SOURCE_TREE/src/libs/libqxt/src/core
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$GCS_SOURCE_TREE/src/libs/libqxt/src/core/logengines
|
@ -1,66 +0,0 @@
|
||||
#
|
||||
# Qxt main project file
|
||||
#
|
||||
#
|
||||
TEMPLATE = subdirs
|
||||
|
||||
QXT_MODULES = core
|
||||
|
||||
contains( QXT_MODULES, core ){
|
||||
message( building core module )
|
||||
sub_core.subdir = src/core
|
||||
SUBDIRS += sub_core
|
||||
}
|
||||
|
||||
contains( QXT_MODULES, gui ){
|
||||
message( building gui module )
|
||||
sub_gui.subdir = src/gui
|
||||
sub_gui.depends = sub_core
|
||||
SUBDIRS += sub_gui
|
||||
contains( QXT_MODULES, designer ){
|
||||
sub_designer.subdir = src/designer
|
||||
sub_designer.depends = sub_core sub_gui
|
||||
SUBDIRS += sub_designer
|
||||
}
|
||||
}
|
||||
|
||||
contains( QXT_MODULES, network ){
|
||||
message( building network module )
|
||||
sub_network.subdir = src/network
|
||||
sub_network.depends = sub_core
|
||||
SUBDIRS += sub_network
|
||||
}
|
||||
|
||||
contains( QXT_MODULES, sql ){
|
||||
message( building sql module )
|
||||
sub_sql.subdir = src/sql
|
||||
sub_sql.depends = sub_core
|
||||
SUBDIRS += sub_sql
|
||||
}
|
||||
|
||||
contains(DEFINES,HAVE_DB){
|
||||
contains( QXT_MODULES, berkeley ){
|
||||
message( building berkeley module )
|
||||
sub_berkeley.subdir = src/berkeley
|
||||
sub_berkeley.depends = sub_core
|
||||
SUBDIRS += sub_berkeley
|
||||
}
|
||||
}
|
||||
|
||||
contains(DEFINES,HAVE_ZEROCONF){
|
||||
contains( QXT_MODULES, zeroconf ){
|
||||
message( building zeroconf module )
|
||||
sub_zeroconf.subdir = src/zeroconf
|
||||
sub_zeroconf.depends = sub_network
|
||||
SUBDIRS += sub_zeroconf
|
||||
}
|
||||
}
|
||||
|
||||
contains( QXT_MODULES, web ){
|
||||
message( building web module )
|
||||
sub_web.subdir = src/web
|
||||
sub_web.depends = sub_core sub_network
|
||||
SUBDIRS += sub_web
|
||||
}
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
|
||||
HEADERS += qxtberkeley.h
|
||||
HEADERS += qxtbdb.h
|
||||
HEADERS += qxtbdbhash.h
|
||||
HEADERS += qxtbdbtree.h
|
||||
|
||||
SOURCES += qxtbdb.cpp
|
||||
SOURCES += qxtbdbhash.cpp
|
||||
SOURCES += qxtbdbtree.cpp
|
@ -1,10 +0,0 @@
|
||||
CLEAN_TARGET = QxtBerkeley
|
||||
DEFINES += BUILD_QXT_BERKELEY
|
||||
QT = core
|
||||
QXT = core
|
||||
CONVENIENCE += $$CLEAN_TARGET
|
||||
|
||||
include(berkeley.pri)
|
||||
#include(../qxtbase.pri)
|
||||
|
||||
!win32:LIBS += -ldb
|
@ -1,377 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtBerkeley module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtbdb.h"
|
||||
#include <QFileInfo>
|
||||
#include <QBuffer>
|
||||
#include <QDataStream>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void qxtBDBDatabaseErrorHandler(const BerkeleyDB::DB_ENV*, const char* a, const char* b)
|
||||
{
|
||||
qDebug("QxtBDBDatabase: %s, %s", a, b);
|
||||
}
|
||||
|
||||
|
||||
QxtBdb::QxtBdb()
|
||||
{
|
||||
isOpen = false;
|
||||
if (db_create(&db, NULL, 0) != 0)
|
||||
qFatal("db_create failed");
|
||||
db->set_errcall(db, qxtBDBDatabaseErrorHandler);
|
||||
|
||||
}
|
||||
QxtBdb::~QxtBdb()
|
||||
{
|
||||
db->close(db, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool QxtBdb::open(QString path, OpenFlags f)
|
||||
{
|
||||
Q_ASSERT(!isOpen);
|
||||
|
||||
if (QFileInfo(path).exists())
|
||||
{
|
||||
|
||||
BerkeleyDB::DB * tdb;
|
||||
if (db_create(&tdb, NULL, 0) != 0)
|
||||
qFatal("db_create failed");
|
||||
|
||||
if (tdb->verify(tdb, qPrintable(path), NULL, NULL, 0) == DB_VERIFY_BAD)
|
||||
qCritical("QxtBdb::open Database '%s' is corrupted.", qPrintable(path));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int flags = 0;
|
||||
if (f&CreateDatabase)
|
||||
flags |= DB_CREATE;
|
||||
|
||||
if (f&ReadOnly)
|
||||
flags |= DB_RDONLY;
|
||||
|
||||
if (f&LockFree)
|
||||
flags |= DB_THREAD;
|
||||
|
||||
|
||||
|
||||
|
||||
isOpen = (db->open(db, /* DB structure pointer */
|
||||
NULL, /* Transaction pointer */
|
||||
qPrintable(path), /* On-disk file that holds the database. */
|
||||
NULL, /* Optional logical database name */
|
||||
BerkeleyDB::DB_BTREE, /* Database access method */
|
||||
flags, /* Open flags */
|
||||
0)
|
||||
== 0);
|
||||
|
||||
return isOpen;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
QxtBdb::OpenFlags QxtBdb::openFlags()
|
||||
{
|
||||
if (!isOpen)
|
||||
return 0;
|
||||
OpenFlags f;
|
||||
|
||||
BerkeleyDB::u_int32_t open_flags;
|
||||
db->get_open_flags(db, &open_flags);
|
||||
|
||||
|
||||
|
||||
if (open_flags&DB_CREATE)
|
||||
f |= CreateDatabase;
|
||||
if (open_flags&DB_RDONLY)
|
||||
f |= ReadOnly;
|
||||
if (open_flags&DB_THREAD)
|
||||
f |= LockFree;
|
||||
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool QxtBdb::flush()
|
||||
{
|
||||
if (!isOpen)
|
||||
return false;
|
||||
return (db->sync(db, 0) == 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
low level get function.
|
||||
serialised key and value with the given meta ids.
|
||||
always reads <b>and</b> writes both key and value, if given.
|
||||
use this when doing operations that require the key to be read out of the db.
|
||||
*/
|
||||
bool QxtBdb::get(void* key, int keytype, void* value, int valuetype, BerkeleyDB::u_int32_t flags, BerkeleyDB::DBC * cursor) const
|
||||
{
|
||||
|
||||
BerkeleyDB::DBT dbkey, dbvalue;
|
||||
::memset(&dbkey, 0, sizeof(BerkeleyDB::DBT));
|
||||
::memset(&dbvalue, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
|
||||
|
||||
if (key)
|
||||
{
|
||||
QByteArray d_key;
|
||||
QBuffer buffer(&d_key);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, keytype, key))
|
||||
qCritical("QMetaType::save failed. is your key registered with the QMetaType?");
|
||||
buffer.close();
|
||||
dbkey.size = d_key.size();
|
||||
dbkey.data = ::malloc(d_key.size());
|
||||
::memcpy(dbkey.data, d_key.data(), d_key.size());
|
||||
}
|
||||
|
||||
if (value)
|
||||
{
|
||||
QByteArray d_value;
|
||||
QBuffer buffer(&d_value);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, valuetype, value))
|
||||
qCritical("QMetaType::save failed. is your value registered with the QMetaType?");
|
||||
buffer.close();
|
||||
dbvalue.size = d_value.size();
|
||||
dbvalue.data = ::malloc(d_value.size());
|
||||
::memcpy(dbvalue.data, d_value.data(), d_value.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
dbvalue.ulen = 0;
|
||||
dbvalue.flags = DB_DBT_USERMEM;
|
||||
|
||||
dbkey.ulen = 0;
|
||||
dbkey.flags = DB_DBT_USERMEM;
|
||||
|
||||
int ret;
|
||||
|
||||
if (cursor)
|
||||
ret = cursor->c_get(cursor, &dbkey, &dbvalue, flags);
|
||||
else
|
||||
ret = db->get(db, NULL, &dbkey, &dbvalue, flags);
|
||||
|
||||
if (ret != DB_BUFFER_SMALL)
|
||||
{
|
||||
::free(dbvalue.data);
|
||||
::free(dbkey.data);
|
||||
return (ret == 0);
|
||||
}
|
||||
dbvalue.ulen = dbvalue.size;
|
||||
dbvalue.data =::malloc(dbvalue.size);
|
||||
|
||||
dbkey.ulen = dbkey.size;
|
||||
dbkey.data =::malloc(dbkey.size);
|
||||
|
||||
if (cursor)
|
||||
ret = cursor->c_get(cursor, &dbkey, &dbvalue, flags);
|
||||
else
|
||||
ret = db->get(db, NULL, &dbkey, &dbvalue, flags);
|
||||
|
||||
QByteArray d_value = QByteArray::fromRawData((const char*) dbvalue.data, dbvalue.size);
|
||||
QByteArray d_key = QByteArray::fromRawData((const char*) dbkey.data, dbkey.size);
|
||||
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
::free(dbvalue.data);
|
||||
::free(dbkey.data);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (key)
|
||||
{
|
||||
QBuffer buffer(&d_key);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::load(s, keytype, key))
|
||||
qCritical("QMetaType::load failed. is your key registered with the QMetaType?");
|
||||
buffer.close();
|
||||
}
|
||||
if (value)
|
||||
{
|
||||
QBuffer buffer(&d_value);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::load(s, valuetype, value))
|
||||
qCritical("QMetaType::load failed. is your value registered with the QMetaType?");
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
::free(dbvalue.data);
|
||||
::free(dbkey.data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
low level get function.
|
||||
serialised key and value with the given meta ids.
|
||||
doesn't write to the key. use this when doing operations that require the key to be passed.
|
||||
*/
|
||||
bool QxtBdb::get(const void* key, int keytype, void* value, int valuetype, BerkeleyDB::u_int32_t flags, BerkeleyDB::DBC * cursor) const
|
||||
{
|
||||
|
||||
BerkeleyDB::DBT dbkey, dbvalue;
|
||||
memset(&dbkey, 0, sizeof(BerkeleyDB::DBT));
|
||||
memset(&dbvalue, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
if (key)
|
||||
{
|
||||
QByteArray d_key;
|
||||
QBuffer buffer(&d_key);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, keytype, key))
|
||||
qCritical("QMetaType::save failed. is your key registered with the QMetaType?");
|
||||
buffer.close();
|
||||
dbkey.size = d_key.size();
|
||||
dbkey.data = ::malloc(d_key.size());
|
||||
::memcpy(dbkey.data, d_key.data(), d_key.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (value)
|
||||
{
|
||||
QByteArray d_value;
|
||||
QBuffer buffer(&d_value);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, valuetype, value))
|
||||
qCritical("QMetaType::save failed. is your value registered with the QMetaType?");
|
||||
buffer.close();
|
||||
dbvalue.size = d_value.size();
|
||||
dbvalue.data = ::malloc(d_value.size());
|
||||
::memcpy(dbvalue.data, d_value.data(), d_value.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
dbvalue.ulen = 0;
|
||||
dbvalue.flags = DB_DBT_USERMEM;
|
||||
|
||||
dbkey.ulen = 0;
|
||||
dbkey.flags = 0;
|
||||
dbkey.flags = DB_DBT_USERMEM; //it's my memory, ffs. stop deleting it! >_<
|
||||
|
||||
int ret;
|
||||
|
||||
if (cursor)
|
||||
ret = cursor->c_get(cursor, &dbkey, &dbvalue, flags);
|
||||
else
|
||||
ret = db->get(db, NULL, &dbkey, &dbvalue, flags);
|
||||
|
||||
if (ret != DB_BUFFER_SMALL)
|
||||
{
|
||||
::free(dbvalue.data);
|
||||
::free(dbkey.data);
|
||||
return (ret == 0);
|
||||
}
|
||||
dbvalue.ulen = dbvalue.size;
|
||||
dbvalue.data =::malloc(dbvalue.size);
|
||||
|
||||
|
||||
if (cursor)
|
||||
ret = cursor->c_get(cursor, &dbkey, &dbvalue, flags);
|
||||
else
|
||||
ret = db->get(db, NULL, &dbkey, &dbvalue, flags);
|
||||
|
||||
QByteArray d_value((const char*) dbvalue.data, dbvalue.size);
|
||||
QByteArray d_key((const char*) dbkey.data, dbkey.size);
|
||||
|
||||
::free(dbvalue.data);
|
||||
::free(dbkey.data);
|
||||
|
||||
Q_ASSERT_X(ret != DB_BUFFER_SMALL, Q_FUNC_INFO, "QxtBdb::get bdb inists on retriving the key for this operation. You need to specify a non const key. (or just specify a non const void* with the value of 0, i'll delete the key for you after bdb fetched it, so you don't need to bother)");
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (value)
|
||||
{
|
||||
QBuffer buffer(&d_value);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::load(s, valuetype, value))
|
||||
qCritical("QMetaType::load failed. is your value registered with the QMetaType?");
|
||||
|
||||
buffer.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString QxtBdb::dbErrorCodeToString(int e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case DB_LOCK_DEADLOCK:
|
||||
return QString("Dead locked (%1)").arg(e);
|
||||
case DB_SECONDARY_BAD:
|
||||
return QString("Bad Secondary index (%1)").arg(e);
|
||||
case DB_RUNRECOVERY:
|
||||
return QString("Database corrupted. Run Recovery. (%1)").arg(e);
|
||||
|
||||
default:
|
||||
return QString("Unknown error %1").arg(e);
|
||||
};
|
||||
}
|
||||
|
@ -1,171 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtBerkeley module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
This is private API. it might change at any time without warning.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef QxtBdb_H_kpasd
|
||||
#define QxtBdb_H_kpasd
|
||||
|
||||
#include <QFlags>
|
||||
#include <QBuffer>
|
||||
#include <QDataStream>
|
||||
#include <QMetaType>
|
||||
|
||||
#include <QString>
|
||||
#include <qxtglobal.h>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
///its impossible to forward anyway,
|
||||
namespace BerkeleyDB
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include <db.h>
|
||||
}
|
||||
|
||||
/// aparantly MSVC and GCC have different understanding of what goes into a namespace and what not.
|
||||
#ifndef Q_CC_MSVC
|
||||
typedef quint32 u_int32_t;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
class QXT_BERKELEY_EXPORT QxtBdb
|
||||
{
|
||||
public:
|
||||
enum OpenFlag
|
||||
{
|
||||
CreateDatabase = 0x1,
|
||||
ReadOnly = 0x2,
|
||||
LockFree = 0x4
|
||||
|
||||
};
|
||||
Q_DECLARE_FLAGS(OpenFlags, OpenFlag);
|
||||
|
||||
QxtBdb();
|
||||
~QxtBdb();
|
||||
|
||||
|
||||
bool get(void* key, int keytype, void* value, int valuetype, BerkeleyDB::u_int32_t flags = NULL, BerkeleyDB::DBC * cursor = 0) const ;
|
||||
bool get(const void* key, int keytype, void* value, int valuetype, BerkeleyDB::u_int32_t flags = NULL, BerkeleyDB::DBC * cursor = 0) const ;
|
||||
|
||||
|
||||
bool open(QString path, OpenFlags f = 0);
|
||||
OpenFlags openFlags();
|
||||
bool flush();
|
||||
BerkeleyDB::DB * db;
|
||||
bool isOpen;
|
||||
|
||||
|
||||
static QString dbErrorCodeToString(int e);
|
||||
|
||||
|
||||
template<class T>
|
||||
static T qxtMetaLoad(const void * data, size_t size)
|
||||
{
|
||||
T t;
|
||||
QByteArray b = QByteArray::fromRawData((const char*)data, size);
|
||||
QBuffer buffer(&b);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::load(s, qMetaTypeId<T>(), &t))
|
||||
qCritical("QMetaType::load failed. is your type registered with the QMetaType?");
|
||||
buffer.close();
|
||||
return t;
|
||||
}
|
||||
|
||||
static void * qxtMetaLoad(const void * data, size_t size, int type)
|
||||
{
|
||||
void *p = QMetaType::construct(type);
|
||||
QByteArray b = QByteArray::fromRawData(static_cast<const char*>(data), size);
|
||||
QBuffer buffer(&b);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::load(s, type, p))
|
||||
qCritical("QMetaType::load failed. is your type registered with the QMetaType?");
|
||||
|
||||
buffer.close();
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
static QByteArray qxtMetaSave(const T & t)
|
||||
{
|
||||
QByteArray d;
|
||||
QBuffer buffer(&d);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, qMetaTypeId<T>(), &t))
|
||||
qCritical("QMetaType::save failed. is your type registered with the QMetaType?");
|
||||
|
||||
buffer.close();
|
||||
return d;
|
||||
}
|
||||
|
||||
static void * qxtMetaSave(size_t * size, void * t, int type)
|
||||
{
|
||||
QByteArray d;
|
||||
QBuffer buffer(&d);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, type, t))
|
||||
qCritical("QMetaType::save failed. is your type registered with the QMetaType?");
|
||||
buffer.close();
|
||||
*size = d.size();
|
||||
void *p = ::malloc(d.size());
|
||||
::memcpy(p, d.data(), d.size());
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QxtBdb::OpenFlags);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,264 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtBerkeley module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtbdbhash.h"
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
\class QxtBdbHash
|
||||
\inmodule QxtBerkeley
|
||||
\brief The QxtBdbHash class is a template class that provides key/value access to a berkeley db file.
|
||||
|
||||
Both value and key must be registered with the qt meta system.
|
||||
You may not touch the file while a QxtBdbHash instance is running on it.
|
||||
|
||||
examples usage:
|
||||
\code
|
||||
QxtBdbHash<qreal,QStringList> db("test.db");
|
||||
db.insert(344.4,QStringList<<"HI"<<":)");
|
||||
qDebug()<<db[344.4];
|
||||
\endcode
|
||||
|
||||
|
||||
There is an extensive example in /examples/berkeley/adressbook.
|
||||
|
||||
|
||||
All functions of this class are thread safe.
|
||||
Calling open() multiple times is undefined.
|
||||
An iterator may only be used from one thread at once, but you can have multiple iterators.
|
||||
|
||||
TODO: {implicitshared}
|
||||
\sa QxtBdbHashIterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtBdbHash::QxtBdbHash()
|
||||
|
||||
Constructs an invalid QxtBdbHash
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtBdbHash::QxtBdbHash(QString file)
|
||||
|
||||
Constructs a QxtBdbHash, and opens the \a file specified as its database.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbHash::open(QString file)
|
||||
|
||||
Opens the specified \a file.
|
||||
|
||||
Returns \c true on success and \c false on failure.
|
||||
\bold {Note:} A sanity check is performed before opening the file.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtBdbHash::clear()
|
||||
|
||||
Erase all records. This does not delete the underlying file.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHash::begin()
|
||||
|
||||
Returns an iterator to the first key,value pair.
|
||||
\sa QxtBdbHashIterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHash::end()
|
||||
|
||||
Return an iterator to the last key,value pair
|
||||
\sa QxtBdbHashIterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHash::find ( const KEY & key )
|
||||
|
||||
Returns an iterator to the position of the pair identified by \a key
|
||||
\sa QxtBdbHashIterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbHash::contains ( const KEY & key ) const
|
||||
|
||||
Returns \c true if there is a record for the specified \a key.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbHash::remove ( const KEY & key )
|
||||
|
||||
Removes all records with the specified \a key. Returns \c true on success and \c false on failure.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbHash::insert( KEY key, VAL value )
|
||||
|
||||
Inserts a record with the specified \a key / \a value combination. Replaces any record with the same key.
|
||||
\bold {Note:} When working with iterators, keep in mind that inserting pairs, works reverse to the iteration.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn const VAL QxtBdbHash::value( const KEY & key ) const
|
||||
|
||||
Returns the value associated with the specified \a key, or a default contructed value, if no such key exists.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn const VAL QxtBdbHash::operator[] ( const KEY & key ) const
|
||||
|
||||
Same as value()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbHash::flush()
|
||||
|
||||
Flushes the underlying DB file. All changes are synced to disk.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
\class QxtBdbHashIterator
|
||||
\inmodule QxtBerkeley
|
||||
\brief The QxtBdbHashIterator class provides a fast iterator over a QxtBdbHash
|
||||
|
||||
|
||||
\sa QxtBdbHash
|
||||
|
||||
|
||||
TODO: {implicitshared}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtBdbHashIterator<KEY,VAL>::QxtBdbHashIterator()
|
||||
|
||||
Constructs an invalid QxtBdbHashIterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL>::QxtBdbHashIterator(const QxtBdbHashIterator<KEY,VAL> & other)
|
||||
|
||||
Copy constructor
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> & QxtBdbHashIterator<KEY,VAL>::operator= ( const QxtBdbHashIterator<KEY,VAL> & other )
|
||||
|
||||
Assignment operator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbHashIterator<KEY,VAL>::isValid() const
|
||||
|
||||
Returns \c true if the iterator is valid.
|
||||
Invalid iterators are unusable and accessing any function will fail.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL>::operator KEY() const
|
||||
|
||||
Convertion operator to the current value.
|
||||
|
||||
\sa key()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn KEY QxtBdbHashIterator<KEY,VAL>::key() const
|
||||
|
||||
Returns the current key.
|
||||
|
||||
\sa value()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn VAL QxtBdbHashIterator<KEY,VAL>::value() const
|
||||
|
||||
Returns the current value.
|
||||
|
||||
\sa key()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHashIterator<KEY,VAL>::operator + ( int j ) const
|
||||
|
||||
Returns an iterator to the item at \a j positions forward from this iterator.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> & QxtBdbHashIterator<KEY,VAL>::operator ++ ()
|
||||
|
||||
The prefix ++ operator (++i) advances the iterator to the next item in the hash and returns an iterator to the new current item.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHashIterator<KEY,VAL>::operator ++ (int)
|
||||
|
||||
The postfix ++ operator (i++) advances the iterator to the next item in the hash and returns an iterator to the previously current item.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> & QxtBdbHashIterator<KEY,VAL>::operator += ( int j )
|
||||
|
||||
Advances the iterator by \a j items.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHashIterator<KEY,VAL>::operator - ( int j ) const
|
||||
|
||||
Returns an iterator to the item at \a j positions backward from this iterator.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> & QxtBdbHashIterator<KEY,VAL>::operator -- ()
|
||||
|
||||
The prefix -- operator (--i) makes the preceding item current and returns an iterator pointing to the new current item.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHashIterator<KEY,VAL>::operator -- (int)
|
||||
|
||||
The postfix -- operator (i--) makes the preceding item current and returns an iterator pointing to the previously current item.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> & QxtBdbHashIterator<KEY,VAL>::operator -= ( int j )
|
||||
|
||||
Makes the iterator go back by \a j items.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbHashIterator<KEY,VAL> QxtBdbHashIterator<KEY,VAL>::erase ()
|
||||
|
||||
Removes the (key, value) pair associated with the iterator from the hash, and returns an iterator to the next item in the hash.
|
||||
|
||||
This instance is invalid then, and cannot be used further.
|
||||
*/
|
@ -1,577 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtBerkeley module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QxtBdbHash_H_kpasd
|
||||
#define QxtBdbHash_H_kpasd
|
||||
|
||||
#include "qxtbdb.h"
|
||||
#include <QBuffer>
|
||||
#include <QDataStream>
|
||||
#include <QVariant>
|
||||
#include <qxtsharedprivate.h>
|
||||
#include <qxtglobal.h>
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
class QxtBdbHashIterator;
|
||||
|
||||
template<class KEY, class VAL>
|
||||
class /*QXT_BERKELEY_EXPORT*/ QxtBdbHash
|
||||
{
|
||||
public:
|
||||
QxtBdbHash();
|
||||
QxtBdbHash(QString file);
|
||||
bool open(QString file);
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> begin();
|
||||
QxtBdbHashIterator<KEY, VAL> end();
|
||||
QxtBdbHashIterator<KEY, VAL> find(const KEY & key);
|
||||
|
||||
void clear();
|
||||
bool contains(const KEY & key) const;
|
||||
bool remove(const KEY & key);
|
||||
bool insert(KEY k, VAL v);
|
||||
const VAL value(const KEY & key) const;
|
||||
const VAL operator[](const KEY & key) const;
|
||||
|
||||
bool flush();
|
||||
|
||||
private:
|
||||
int meta_id_key;
|
||||
int meta_id_val;
|
||||
QxtSharedPrivate<QxtBdb> qxt_d;
|
||||
};
|
||||
|
||||
|
||||
class QxtBdbHashIteratorPrivate
|
||||
{
|
||||
public:
|
||||
QxtBdb * db;
|
||||
BerkeleyDB::DBC *dbc;
|
||||
void invalidate()
|
||||
{
|
||||
if (dbc)
|
||||
dbc->c_close(dbc);
|
||||
dbc = 0;
|
||||
}
|
||||
~QxtBdbHashIteratorPrivate()
|
||||
{
|
||||
invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
template<class KEY, class VAL>
|
||||
class QxtBdbHashIterator
|
||||
{
|
||||
public:
|
||||
QxtBdbHashIterator();
|
||||
QxtBdbHashIterator(const QxtBdbHashIterator<KEY, VAL> & other);
|
||||
QxtBdbHashIterator & operator= (const QxtBdbHashIterator<KEY, VAL> & other);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
operator KEY() const;
|
||||
|
||||
KEY key() const;
|
||||
VAL value() const;
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> operator + (int j) const;
|
||||
QxtBdbHashIterator<KEY, VAL> & operator ++ ();
|
||||
QxtBdbHashIterator<KEY, VAL> operator ++ (int);
|
||||
QxtBdbHashIterator<KEY, VAL> & operator += (int j);
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> operator - (int j) const;
|
||||
QxtBdbHashIterator<KEY, VAL> & operator -- ();
|
||||
QxtBdbHashIterator<KEY, VAL> operator -- (int);
|
||||
QxtBdbHashIterator<KEY, VAL> & operator -= (int j);
|
||||
|
||||
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> erase();
|
||||
|
||||
|
||||
private:
|
||||
friend class QxtBdbHash<KEY, VAL>;
|
||||
QxtBdbHashIterator(BerkeleyDB::DBC*, QxtBdb * p);
|
||||
QxtSharedPrivate<QxtBdbHashIteratorPrivate> qxt_d;
|
||||
|
||||
int meta_id_key;
|
||||
int meta_id_val;
|
||||
|
||||
/*won't work. no support in bdb*/
|
||||
bool operator== (const QxtBdbHashIterator<KEY, VAL> & other) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool operator!= (const QxtBdbHashIterator<KEY, VAL> & other) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHash<KEY, VAL>::QxtBdbHash()
|
||||
{
|
||||
qxt_d = new QxtBdb();
|
||||
|
||||
///this will fail to compile if KEY or VALUE are not declared metatypes. Good.
|
||||
meta_id_key = qMetaTypeId<KEY>();
|
||||
meta_id_val = qMetaTypeId<VAL>();
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHash<KEY, VAL>::QxtBdbHash(QString file)
|
||||
{
|
||||
qxt_d = new QxtBdb();
|
||||
open(file);
|
||||
|
||||
///this will fail to compile if KEY or VALUE are not declared metatypes. Good.
|
||||
meta_id_key = qMetaTypeId<KEY>();
|
||||
meta_id_val = qMetaTypeId<VAL>();
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
bool QxtBdbHash<KEY, VAL>::open(QString file)
|
||||
{
|
||||
return qxt_d().open(file, QxtBdb::CreateDatabase | QxtBdb::LockFree);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHash<KEY, VAL>::begin()
|
||||
{
|
||||
BerkeleyDB::DBC *cursor;
|
||||
qxt_d().db->cursor(qxt_d().db, NULL, &cursor, 0);
|
||||
if (qxt_d().get((void*)0, 0, 0, 0, DB_FIRST, cursor))
|
||||
return QxtBdbHashIterator<KEY, VAL>(cursor, &qxt_d());
|
||||
else
|
||||
return QxtBdbHashIterator<KEY, VAL>();
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHash<KEY, VAL>::end()
|
||||
{
|
||||
BerkeleyDB::DBC *cursor;
|
||||
qxt_d().db->cursor(qxt_d().db, NULL, &cursor, 0);
|
||||
if (qxt_d().get((void*)0, 0, 0, 0, DB_LAST, cursor))
|
||||
return QxtBdbHashIterator<KEY, VAL>(cursor, &qxt_d());
|
||||
else
|
||||
return QxtBdbHashIterator<KEY, VAL>();
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHash<KEY, VAL>::find(const KEY & k)
|
||||
{
|
||||
BerkeleyDB::DBC *cursor;
|
||||
qxt_d().db->cursor(qxt_d().db, NULL, &cursor, 0);
|
||||
if (qxt_d().get(&k, meta_id_key, 0, 0, DB_SET, cursor))
|
||||
return QxtBdbHashIterator<KEY, VAL>(cursor, &qxt_d());
|
||||
else
|
||||
return QxtBdbHashIterator<KEY, VAL>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
void QxtBdbHash<KEY, VAL>::clear()
|
||||
{
|
||||
if (!qxt_d().isOpen)
|
||||
return;
|
||||
|
||||
BerkeleyDB::u_int32_t x;
|
||||
qxt_d().db->truncate(qxt_d().db, NULL, &x, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
bool QxtBdbHash<KEY, VAL>::contains(const KEY & k) const
|
||||
{
|
||||
if (!qxt_d().isOpen)
|
||||
return false;
|
||||
|
||||
BerkeleyDB::DBT key;
|
||||
/* Zero out the DBTs before using them. */
|
||||
memset(&key, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
QByteArray d_key;
|
||||
{
|
||||
QBuffer buffer(&d_key);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, meta_id_key, &k))
|
||||
qCritical("QMetaType::save failed. is your type registered with the QMetaType?");
|
||||
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
key.data = d_key.data();
|
||||
key.size = d_key.size();
|
||||
|
||||
return (qxt_d().db->exists(qxt_d().db, NULL, &key, 0) == 0);
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
bool QxtBdbHash<KEY, VAL>::remove(const KEY & k)
|
||||
{
|
||||
if (!qxt_d().isOpen)
|
||||
return false;
|
||||
|
||||
BerkeleyDB::DBT key;
|
||||
/* Zero out the DBTs before using them. */
|
||||
memset(&key, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
QByteArray d_key;
|
||||
{
|
||||
QBuffer buffer(&d_key);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, meta_id_key, &k))
|
||||
qCritical("QMetaType::save failed. is your type registered with the QMetaType?");
|
||||
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
key.data = d_key.data();
|
||||
key.size = d_key.size();
|
||||
|
||||
|
||||
return (qxt_d().db->del(qxt_d().db, NULL, &key, 0) == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
bool QxtBdbHash<KEY, VAL>::insert(KEY k, VAL v)
|
||||
{
|
||||
if (!qxt_d().isOpen)
|
||||
return false;
|
||||
|
||||
QByteArray d_key, d_value;
|
||||
|
||||
{
|
||||
QBuffer buffer(&d_key);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, meta_id_key, &k))
|
||||
qCritical("QMetaType::save failed. is your type registered with the QMetaType?");
|
||||
|
||||
buffer.close();
|
||||
}
|
||||
{
|
||||
QBuffer buffer(&d_value);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QDataStream s(&buffer);
|
||||
if (!QMetaType::save(s, meta_id_val, &v))
|
||||
qCritical("QMetaType::save failed. is your value registered with the QMetaType?");
|
||||
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
BerkeleyDB::DBT key, value;
|
||||
/* Zero out the DBTs before using them. */
|
||||
memset(&key, 0, sizeof(BerkeleyDB::DBT));
|
||||
memset(&value, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
key.data = d_key.data();
|
||||
key.size = d_key.size();
|
||||
|
||||
value.data = d_value.data();
|
||||
value.size = d_value.size();
|
||||
|
||||
|
||||
int ret = qxt_d().db->put(qxt_d().db, NULL, &key, &value, 0);
|
||||
return (ret == 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
const VAL QxtBdbHash<KEY, VAL>::value(const KEY & k) const
|
||||
{
|
||||
if (!qxt_d().isOpen)
|
||||
return VAL() ;
|
||||
|
||||
VAL v;
|
||||
if (!qxt_d().get(&k, meta_id_key, &v, meta_id_val))
|
||||
return VAL();
|
||||
return v;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
const VAL QxtBdbHash<KEY, VAL>::operator[](const KEY & key) const
|
||||
{
|
||||
return value(key);
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
bool QxtBdbHash<KEY, VAL>::flush()
|
||||
{
|
||||
return qxt_d().flush();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL>::QxtBdbHashIterator()
|
||||
{
|
||||
qxt_d = new QxtBdbHashIteratorPrivate;
|
||||
qxt_d().dbc = 0;
|
||||
qxt_d().db = 0;
|
||||
meta_id_key = qMetaTypeId<KEY>();
|
||||
meta_id_val = qMetaTypeId<VAL>();
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL>::QxtBdbHashIterator(const QxtBdbHashIterator<KEY, VAL> & other)
|
||||
{
|
||||
///FIXME: possible leaking, since the other isnt properly destructed?
|
||||
qxt_d = other.qxt_d;
|
||||
meta_id_key = qMetaTypeId<KEY>();
|
||||
meta_id_val = qMetaTypeId<VAL>();
|
||||
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> & QxtBdbHashIterator<KEY, VAL>::operator= (const QxtBdbHashIterator<KEY, VAL> & other)
|
||||
{
|
||||
///FIXME: possible leaking, since the other isnt properly destructed?
|
||||
qxt_d = other.qxt_d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
bool QxtBdbHashIterator<KEY, VAL>::isValid() const
|
||||
{
|
||||
return (qxt_d().dbc != 0);
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL>::operator KEY() const
|
||||
{
|
||||
return key();
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
KEY QxtBdbHashIterator<KEY, VAL>::key() const
|
||||
{
|
||||
|
||||
if (!isValid())
|
||||
return KEY();
|
||||
KEY k;
|
||||
if (qxt_d().db->get(&k, meta_id_key, 0, 0, DB_CURRENT, qxt_d().dbc))
|
||||
return k;
|
||||
else
|
||||
return KEY();
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
VAL QxtBdbHashIterator<KEY, VAL>::value() const
|
||||
{
|
||||
if (!isValid())
|
||||
return VAL();
|
||||
|
||||
VAL v;
|
||||
if (qxt_d().db->get((void*)0, 0, &v, meta_id_val, DB_CURRENT, qxt_d().dbc))
|
||||
return v;
|
||||
else
|
||||
return VAL();
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHashIterator<KEY, VAL>::operator + (int j) const
|
||||
{
|
||||
// if j is negative, it should subtract as apposed to do nothing...
|
||||
if(j < 0)
|
||||
return this->operator-(j*(-1));
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> d = *this;
|
||||
for (int i = 0;i < j;i++)
|
||||
++d;
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> & QxtBdbHashIterator<KEY, VAL>::operator ++ () /*prefix*/
|
||||
{
|
||||
if (!isValid())
|
||||
return *this;
|
||||
|
||||
if (!qxt_d().db->get((void*)0, 0, 0, 0, DB_NEXT, qxt_d().dbc))
|
||||
{
|
||||
qxt_d().invalidate();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHashIterator<KEY, VAL>::operator ++ (int) /*postfix*/
|
||||
{
|
||||
if (!isValid())
|
||||
return *this;
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> d = *this;
|
||||
this->operator++();
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> & QxtBdbHashIterator<KEY, VAL>::operator += (int j)
|
||||
{
|
||||
// if j is negative it should subtract as apposed to do nothing
|
||||
if(j < 0)
|
||||
return this->operator-=(j*(-1));
|
||||
|
||||
for (int i = 0;i < j;i++)
|
||||
this->operator++();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHashIterator<KEY, VAL>::operator - (int j) const
|
||||
{
|
||||
// if j is negative, then we should add as opposed to do noting... I really need to learn to spell "opposed" correctly more regularly... hmm..
|
||||
if(j < 0)
|
||||
return this->operator+(j*(-1));
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> d = *this;
|
||||
for (int i = 0;i < j;i++)
|
||||
--d;
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> & QxtBdbHashIterator<KEY, VAL>::operator -- () /*prefix*/
|
||||
{
|
||||
if (!isValid())
|
||||
return *this;
|
||||
|
||||
if (!qxt_d().db->get((void*)0, 0, 0, 0, DB_PREV, qxt_d().dbc))
|
||||
qxt_d().invalidate();
|
||||
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHashIterator<KEY, VAL>::operator -- (int) /*postfix*/
|
||||
{
|
||||
if (!isValid())
|
||||
return *this;
|
||||
|
||||
QxtBdbHashIterator<KEY, VAL> d = *this;
|
||||
this->operator--();
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> & QxtBdbHashIterator<KEY, VAL>::operator -= (int j)
|
||||
{
|
||||
// if j is negative, we should add
|
||||
if(j < 0)
|
||||
return this->operator+=(j*(-1));
|
||||
|
||||
for (int i = 0;i < j;i++)
|
||||
this->operator--();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL> QxtBdbHashIterator<KEY, VAL>::erase()
|
||||
{
|
||||
BerkeleyDB::DBC * newdbc;
|
||||
qxt_d().dbc->c_dup(qxt_d().dbc, &newdbc, DB_POSITION);
|
||||
QxtBdbHashIterator<KEY, VAL> d(newdbc, qxt_d().db);
|
||||
qxt_d().dbc->del(qxt_d().dbc, NULL);
|
||||
++d;
|
||||
|
||||
qxt_d().invalidate();
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class KEY, class VAL>
|
||||
QxtBdbHashIterator<KEY, VAL>::QxtBdbHashIterator(BerkeleyDB::DBC* dbc, QxtBdb * p)
|
||||
{
|
||||
qxt_d = new QxtBdbHashIteratorPrivate;
|
||||
qxt_d().dbc = dbc;
|
||||
qxt_d().db = p;
|
||||
meta_id_key = qMetaTypeId<KEY>();
|
||||
meta_id_val = qMetaTypeId<VAL>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,247 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtBerkeley module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtbdbtree.h"
|
||||
|
||||
/*!
|
||||
\class QxtBdbTree
|
||||
\inmodule QxtBerkeley
|
||||
\brief The QxtBdbTree class is a template berkeley container for tree structured data
|
||||
|
||||
The template argument must be registered with the Qt meta system.
|
||||
You may not touch the file while a QxtBdbTree instance is running on it.
|
||||
|
||||
Example usage:
|
||||
\code
|
||||
QxtBdbTree<QString> db("test.db");
|
||||
db.root().append("fooooo").append("bla");
|
||||
db.dumpTree(); //try this if you are unsure, how the data will look like
|
||||
\endcode
|
||||
|
||||
There is an extensive example in /examples/berkeley/xmlstorage
|
||||
|
||||
All functions of this class are thread safe.
|
||||
Calling open() multiple times is undefined.
|
||||
An iterator may only be used from one thread at once, but you can have multiple iterators.
|
||||
|
||||
TODO: {implicitshared}
|
||||
\sa QxtBdbTreeIterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTree<T>::QxtBdbTree()
|
||||
Constructs an invalid QxtBdbTree
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTree<T>::QxtBdbTree (QString file)
|
||||
Constructs a QxtBdbTree, and opens the \a file specified as its database.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbTree<T>::open (QString file)
|
||||
Opens the specified \a file.
|
||||
|
||||
Returns \c true on success and \c false on failure.
|
||||
\bold {Note:} a sanity check is performed before opening the file.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtBdbTree<T>::clear()
|
||||
Erase all records. This does not delete the underlying file.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbTree<T>::flush()
|
||||
Flushes the underlying DB file. All changes are synced to disk.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTree<T>::root() const
|
||||
Returns the rootnode, which is, similar to QAbstractItemModel, invalid and has no data itself.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtBdbTree<T>::dumpTree() const
|
||||
Outputs the contents of the database as flat file, and as iterateable tree onto qDebug().
|
||||
This function assumes, the class used for template initialisation implements the QDebug<< operator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QxtBdbTreeIterator
|
||||
\inmodule QxtBerkeley
|
||||
\brief The QxtBdbTreeIterator class provides a tree iterator on QxtBdbtree
|
||||
|
||||
TODO: {implicitshared}
|
||||
\sa QxtBdbTree
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T>::QxtBdbTreeIterator()
|
||||
Constructs an invalid QxtBdbTreeIterator
|
||||
|
||||
It's an error to use this to iterate, access data, etc..
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T>::~QxtBdbTreeIterator()
|
||||
Destructs the iterator.
|
||||
|
||||
The underlying cursors will be closed.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T>::QxtBdbTreeIterator(const QxtBdbTreeIterator<T> & other)
|
||||
Copies the \a other iterator.
|
||||
|
||||
The underlying cursor is duped, meaning the position will be copied, but the copy can be used independently.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator= ( const QxtBdbTreeIterator<T> & other )
|
||||
Copies the \a other iterator.
|
||||
|
||||
The underlying cursor is duped, meaning the position will be copied, but the copy can be used independently
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbTreeIterator<T>::isValid() const
|
||||
Returns \c true if the iterator seems to point to a valid location.
|
||||
|
||||
Calls to value() might fail anyway (but not crash), in case of concurrent access.
|
||||
If you want to be 100% sure value() will return valid data, while using multiple threads, then you have to track changes yourself.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T>::operator T() const
|
||||
\sa value()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn T QxtBdbTreeIterator<T>::value() const
|
||||
Returns the value, the iterator is currently pointing to.
|
||||
It is an error to call value() when isValid() returns \c false.
|
||||
In case an database error ocures, like the item been deleted, value() will return a default constructed T.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::parent () const
|
||||
Returns the parent of this item, or an invalid QxtBdbTreeIterator if this is the root item.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::next () const
|
||||
Returns the next sibling of this item, or an invalid QxtBdbTreeIterator if this is the last one.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::previous () const
|
||||
Returns the previous sibling of this item, or an invalid QxtBdbTreeIterator if this is the last one.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::child () const
|
||||
Returns the first child of this item, or an invalid QxtBdbTreeIterator if there are none.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator + ( int j ) const
|
||||
Returns an iterator, \a j items next to this one.
|
||||
If there is no such item, the returned iterator is invalid.
|
||||
\sa next()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator ++ ()
|
||||
This prefix operator increments the item by one.
|
||||
If there are no more items, the iterator becomes invalid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator ++ (int)
|
||||
This postfix operator makes a copy of the item, then increments itself and returns the copy.
|
||||
If there are no more items, the iterator becomes invalid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator += ( int j )
|
||||
Increments the item by \a j.
|
||||
If there are no more items, the iterator becomes invalid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator - ( int j ) const
|
||||
Returns an iterator, \a j previous next to this one.
|
||||
If there is no such item, the returnediterator is invalid.
|
||||
\sa previous()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator -- ()
|
||||
This prefix operator decrements the item by one.
|
||||
If there are no more items, the iterator becomes invalid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator -- (int)
|
||||
This postfix operator makes a copy of the item, then decrements itself and returns the copy.
|
||||
If there are no more items, the iterator becomes invalid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator -= ( int j )
|
||||
Decrements the item by \a j.
|
||||
If there are no more items, the iterator becomes invalid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::append (const T & item )
|
||||
Appends an \a item to the children of this one, and returns an iterator to it.
|
||||
If insertion fails, an invalid iterator is returned.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator::erase()
|
||||
TODO returns
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtBdbTreeIterator::invalidate()
|
||||
TODO
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn quint64 QxtBdbTreeIterator::level() const
|
||||
TODO returns
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtBdbTreeIterator<T> QxtBdbTreeIterator::prepend(const T& t)
|
||||
TODO \a t
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtBdbTreeIterator::setValue(T value)
|
||||
TODO \a value
|
||||
*/
|
@ -1,848 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtBerkeley module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QxtBdbTree_H_Guard_pyxvby
|
||||
#define QxtBdbTree_H_Guard_pyxvby
|
||||
|
||||
#include <qxtsharedprivate.h>
|
||||
#include <QVariant>
|
||||
#include <QPair>
|
||||
#include <QDebug>
|
||||
#include "qxtbdb.h"
|
||||
|
||||
|
||||
template<class T>
|
||||
class QxtBdbTreeIterator;
|
||||
|
||||
|
||||
template<class T>
|
||||
class QxtBdbTree
|
||||
{
|
||||
public:
|
||||
QxtBdbTree();
|
||||
QxtBdbTree(QString file);
|
||||
bool open(QString file);
|
||||
void clear();
|
||||
bool flush();
|
||||
QxtBdbTreeIterator<T> root() const;
|
||||
|
||||
void dumpTree() const;
|
||||
|
||||
|
||||
private:
|
||||
int meta_id;
|
||||
QxtSharedPrivate<QxtBdb> qxt_d;
|
||||
void debugprintchildren(QxtBdbTreeIterator<T> it) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTree<T>::QxtBdbTree()
|
||||
{
|
||||
meta_id = qMetaTypeId<T>();
|
||||
qxt_d = new QxtBdb;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTree<T>::QxtBdbTree(QString file)
|
||||
{
|
||||
meta_id = qMetaTypeId<T>();
|
||||
qxt_d = new QxtBdb;
|
||||
open(file);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool QxtBdbTree<T>::open(QString file)
|
||||
{
|
||||
BerkeleyDB::u_int32_t f;
|
||||
qxt_d().db->get_flags(qxt_d().db, &f);
|
||||
f |= DB_DUP;
|
||||
qxt_d().db->set_flags(qxt_d().db, f);
|
||||
bool r = qxt_d().open(file, QxtBdb::CreateDatabase | QxtBdb::LockFree);
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void QxtBdbTree<T>::clear()
|
||||
{
|
||||
if (!qxt_d().isOpen)
|
||||
return;
|
||||
|
||||
BerkeleyDB::u_int32_t x;
|
||||
qxt_d().db->truncate(qxt_d().db, NULL, &x, 0);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool QxtBdbTree<T>::flush()
|
||||
{
|
||||
return qxt_d().flush();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTree<T>::root() const
|
||||
{
|
||||
QxtBdbTreeIterator<T> r(0, const_cast<QxtBdb*>(&qxt_d()));
|
||||
r.root = true;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
void QxtBdbTree<T>::debugprintchildren(QxtBdbTreeIterator<T> it) const
|
||||
{
|
||||
it = it.child();
|
||||
while (it.isValid())
|
||||
{
|
||||
QByteArray p;
|
||||
for (quint64 x = 0; x < it.level();x++)
|
||||
{
|
||||
p += " |";
|
||||
}
|
||||
qDebug() << p.data() << "-" << it.value();
|
||||
debugprintchildren(it);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|-n1
|
||||
|-n2
|
||||
| |-n3
|
||||
|-n1
|
||||
| |-n1
|
||||
| | |-n3
|
||||
| | | -n2
|
||||
|
||||
*/
|
||||
|
||||
|
||||
template<class T>
|
||||
void QxtBdbTree<T>::dumpTree() const
|
||||
{
|
||||
BerkeleyDB::DBC *cursor;
|
||||
qxt_d().db->cursor(qxt_d().db, NULL, &cursor, 0);
|
||||
if (!qxt_d().get((void*)0, 0, 0, 0, DB_FIRST, cursor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QxtBdbTreeIterator<T> k(cursor, const_cast<QxtBdb*>(&qxt_d()));
|
||||
qDebug() << "\r\nQxtBdbTree<" << QMetaType::typeName(qMetaTypeId<T>()) << ">::dumpTree()\r\n";
|
||||
qDebug() << "Level\t \t Value";
|
||||
|
||||
Q_FOREVER
|
||||
{
|
||||
qDebug() << k.level() << " \t->\t" << k.value();
|
||||
if (!qxt_d().get((void*)0, 0, 0, 0, DB_NEXT, cursor))
|
||||
break;
|
||||
}
|
||||
qDebug() << "\r\n";
|
||||
|
||||
qDebug() << "Iterate";
|
||||
debugprintchildren(root());
|
||||
qDebug() << "\r\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
class QxtBdbTreeIterator
|
||||
{
|
||||
public:
|
||||
QxtBdbTreeIterator();
|
||||
~QxtBdbTreeIterator();
|
||||
QxtBdbTreeIterator(const QxtBdbTreeIterator<T> & other);
|
||||
QxtBdbTreeIterator<T> & operator= (const QxtBdbTreeIterator<T> & other);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
operator T() const;
|
||||
T value() const;
|
||||
bool setValue(T);
|
||||
|
||||
|
||||
QxtBdbTreeIterator<T> parent() const;
|
||||
QxtBdbTreeIterator<T> next() const;
|
||||
QxtBdbTreeIterator<T> previous() const;
|
||||
QxtBdbTreeIterator<T> child() const;
|
||||
|
||||
|
||||
QxtBdbTreeIterator<T> operator + (int j) const;
|
||||
QxtBdbTreeIterator<T> & operator ++ ();
|
||||
QxtBdbTreeIterator<T> operator ++ (int);
|
||||
QxtBdbTreeIterator<T> & operator += (int j);
|
||||
|
||||
QxtBdbTreeIterator<T> operator - (int j) const;
|
||||
QxtBdbTreeIterator<T> & operator -- ();
|
||||
QxtBdbTreeIterator<T> operator -- (int);
|
||||
QxtBdbTreeIterator<T> & operator -= (int j);
|
||||
|
||||
|
||||
QxtBdbTreeIterator<T> append(const T & t);
|
||||
QxtBdbTreeIterator<T> prepend(const T & t);
|
||||
QxtBdbTreeIterator<T> erase();
|
||||
|
||||
protected:
|
||||
quint64 level() const;
|
||||
void invalidate()
|
||||
{
|
||||
if (dbc)
|
||||
dbc->c_close(dbc);
|
||||
dbc = 0;
|
||||
}
|
||||
private:
|
||||
friend class QxtBdbTree<T>;
|
||||
QxtBdbTreeIterator(BerkeleyDB::DBC*, QxtBdb * p);
|
||||
QxtBdbTreeIterator<T> croot() const;
|
||||
|
||||
|
||||
int meta_id;
|
||||
QxtBdb * db;
|
||||
BerkeleyDB::DBC *dbc;
|
||||
|
||||
bool root;
|
||||
|
||||
|
||||
/*won't work. no support in bdb*/
|
||||
bool operator== (const QxtBdbTreeIterator<T> & other) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool operator!= (const QxtBdbTreeIterator<T> & other) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T>::QxtBdbTreeIterator()
|
||||
{
|
||||
dbc = 0;
|
||||
db = 0;
|
||||
root = false;
|
||||
meta_id = qMetaTypeId<T>();
|
||||
}
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T>::~QxtBdbTreeIterator()
|
||||
{
|
||||
invalidate();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T>::QxtBdbTreeIterator(const QxtBdbTreeIterator<T> & other)
|
||||
{
|
||||
dbc = 0;
|
||||
db = 0;
|
||||
root = false;
|
||||
meta_id = qMetaTypeId<T>();
|
||||
|
||||
db = other.db;
|
||||
root = other.root;
|
||||
|
||||
|
||||
if (other.dbc)
|
||||
{
|
||||
other.dbc->c_dup(other.dbc, &dbc, DB_POSITION);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T>::QxtBdbTreeIterator(BerkeleyDB::DBC* dbc, QxtBdb * p)
|
||||
{
|
||||
this->dbc = dbc;
|
||||
db = p;
|
||||
root = false;
|
||||
meta_id = qMetaTypeId<T>();
|
||||
}
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::croot() const
|
||||
{
|
||||
QxtBdbTreeIterator<T> k = *this;
|
||||
k.invalidate();
|
||||
k.root = true;
|
||||
return k;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator= (const QxtBdbTreeIterator<T> & other)
|
||||
{
|
||||
invalidate();
|
||||
|
||||
db = other.db;
|
||||
root = other.root;
|
||||
|
||||
|
||||
if (other.dbc)
|
||||
{
|
||||
other.dbc->c_dup(other.dbc, &dbc, DB_POSITION);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool QxtBdbTreeIterator<T>::isValid() const
|
||||
{
|
||||
if (root)
|
||||
return true;
|
||||
|
||||
return (dbc != 0 && db != 0);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T>::operator T() const
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T QxtBdbTreeIterator<T>::value() const
|
||||
{
|
||||
|
||||
if (!dbc)
|
||||
{
|
||||
qWarning("QxtBdbTreeIterator<T>::value() on invalid iterator ");
|
||||
return T();
|
||||
}
|
||||
|
||||
BerkeleyDB::DBT dbkey, dbvalue;
|
||||
memset(&dbkey, 0, sizeof(BerkeleyDB::DBT));
|
||||
memset(&dbvalue, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
dbvalue.ulen = 0;
|
||||
dbvalue.flags = DB_DBT_USERMEM;
|
||||
|
||||
dbkey.ulen = 0;
|
||||
dbkey.flags = DB_DBT_USERMEM;
|
||||
|
||||
int ret = dbc->c_get(dbc, &dbkey, &dbvalue, DB_CURRENT);
|
||||
if (ret != DB_BUFFER_SMALL)
|
||||
return T();
|
||||
|
||||
|
||||
dbvalue.ulen = dbvalue.size;
|
||||
dbvalue.data =::malloc(dbvalue.size);
|
||||
|
||||
dbkey.ulen = dbkey.size;
|
||||
dbkey.data =::malloc(dbkey.size);
|
||||
|
||||
ret = dbc->c_get(dbc, &dbkey, &dbvalue, DB_CURRENT);
|
||||
T t = QxtBdb::qxtMetaLoad<T>((quint64*)dbvalue.data + 1, dbvalue.size - sizeof(quint64));
|
||||
::free(dbkey.data);
|
||||
::free(dbvalue.data);
|
||||
|
||||
if (ret != 0)
|
||||
return T();
|
||||
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
bool QxtBdbTreeIterator<T>::setValue(T t)
|
||||
{
|
||||
if (!dbc)
|
||||
{
|
||||
qWarning("QxtBdbTreeIterator<T>::setValue() on invalid iterator ");
|
||||
return false;
|
||||
}
|
||||
BerkeleyDB::DBT dbkey, dbvalue;
|
||||
::memset(&dbkey, 0, sizeof(BerkeleyDB::DBT));
|
||||
::memset(&dbvalue, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
char uselesszero = 0;
|
||||
dbkey.data = &uselesszero;
|
||||
dbkey.size = sizeof(char);
|
||||
dbkey.ulen = 0;
|
||||
dbkey.flags = DB_DBT_USERMEM;
|
||||
|
||||
quint64 mylevel = level();
|
||||
QByteArray d = QxtBdb::qxtMetaSave<T>(t);
|
||||
|
||||
|
||||
dbvalue.size = sizeof(quint64) + d.size();
|
||||
dbvalue.ulen = dbvalue.size;
|
||||
dbvalue.data =::malloc(dbvalue.size);
|
||||
::memcpy(dbvalue.data, &mylevel, sizeof(quint64));
|
||||
::memcpy((quint64*)dbvalue.data + 1, d.data(), d.size());
|
||||
dbvalue.flags = DB_DBT_USERMEM;
|
||||
|
||||
int ret = 234525;
|
||||
ret = dbc->c_put(dbc, &dbkey, &dbvalue, DB_CURRENT);
|
||||
::free(dbvalue.data);
|
||||
|
||||
if (ret != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::parent() const
|
||||
{
|
||||
if (root)
|
||||
return croot();
|
||||
if (!dbc)
|
||||
return QxtBdbTreeIterator<T>();
|
||||
|
||||
QxtBdbTreeIterator<T> d(*this);
|
||||
quint64 lvl = level();
|
||||
|
||||
Q_FOREVER
|
||||
{
|
||||
#if DB_VERSION_MINOR > 5
|
||||
|
||||
if (!d.db->get((void*)0, 0, 0, 0, DB_PREV_DUP, d.dbc))
|
||||
#else
|
||||
if (!d.db->get((void*)0, 0, 0, 0, DB_PREV, d.dbc))
|
||||
#endif
|
||||
return croot();
|
||||
if (d.level() == lvl - 1)
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::next() const
|
||||
{
|
||||
if (root)
|
||||
return QxtBdbTreeIterator<T>();
|
||||
return QxtBdbTreeIterator<T>(*this) + 1;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::previous() const
|
||||
{
|
||||
if (root)
|
||||
return QxtBdbTreeIterator<T>();
|
||||
return QxtBdbTreeIterator<T>(*this) - 1;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::child() const
|
||||
{
|
||||
QxtBdbTreeIterator<T> d(*this);
|
||||
|
||||
|
||||
if (root)
|
||||
{
|
||||
BerkeleyDB::DBC *cursor;
|
||||
db->db->cursor(db->db, NULL, &cursor, 0);
|
||||
d = QxtBdbTreeIterator<T>(cursor, db);
|
||||
|
||||
if (!d.db->get((void*)0, 0, 0, 0, DB_FIRST, d.dbc))
|
||||
{
|
||||
return QxtBdbTreeIterator<T>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!dbc)
|
||||
return QxtBdbTreeIterator<T>();
|
||||
|
||||
|
||||
quint64 lvl = level();
|
||||
if (!d.db->get((void*)0, 0, 0, 0, DB_NEXT_DUP, d.dbc))
|
||||
{
|
||||
return QxtBdbTreeIterator<T>();
|
||||
}
|
||||
if (d.level() != lvl + 1)
|
||||
return QxtBdbTreeIterator<T>();
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator + (int j) const
|
||||
{
|
||||
if(j < 0)
|
||||
return this->operator-(j*(-1));
|
||||
|
||||
QxtBdbTreeIterator<T> d(*this);
|
||||
for (int i = 0;i < j;i++)
|
||||
++d;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator ++ ()
|
||||
{
|
||||
if (root)
|
||||
{
|
||||
invalidate();
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (!dbc)
|
||||
return *this;
|
||||
|
||||
quint64 before = level();
|
||||
Q_FOREVER
|
||||
{
|
||||
|
||||
if (!db->get((void*)0, 0, 0, 0, DB_NEXT_DUP, dbc))
|
||||
{
|
||||
invalidate();
|
||||
break;
|
||||
}
|
||||
if (before == level())
|
||||
break;
|
||||
if (before > level())
|
||||
{
|
||||
invalidate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator ++ (int)
|
||||
{
|
||||
QxtBdbTreeIterator<T> d(*this);
|
||||
operator++();
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator += (int j)
|
||||
{
|
||||
if(j < 0)
|
||||
return this->operator-=(j*(-1));
|
||||
|
||||
for (int i = 0;i < j;i++)
|
||||
operator++();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator - (int j) const
|
||||
{
|
||||
if(j < 0)
|
||||
return this->operator+(j*(-1));
|
||||
|
||||
QxtBdbTreeIterator<T> d(*this);
|
||||
for (int i = 0;i < j;i++)
|
||||
--d;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator -- ()
|
||||
{
|
||||
if (root)
|
||||
return *this;
|
||||
|
||||
if (!dbc)
|
||||
return *this;
|
||||
|
||||
|
||||
int lvl = level();
|
||||
|
||||
|
||||
#if DB_VERSION_MINOR > 5
|
||||
do
|
||||
{
|
||||
if (!db->get((void*)0, 0, 0, 0, DB_PREV_DUP, dbc))
|
||||
{
|
||||
invalidate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (lvl != level());
|
||||
#else
|
||||
do
|
||||
{
|
||||
if (!db->get((void*)0, 0, 0, 0, DB_PREV, dbc))
|
||||
{
|
||||
invalidate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (lvl != level());
|
||||
#endif
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::operator -- (int)
|
||||
{
|
||||
QxtBdbTreeIterator<T> d(*this);
|
||||
operator--();
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> & QxtBdbTreeIterator<T>::operator -= (int j)
|
||||
{
|
||||
if(j < 0)
|
||||
return this->operator+=(j*(-1));
|
||||
|
||||
for (int i = 0;i < j;i++)
|
||||
operator--();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::append(const T & t)
|
||||
{
|
||||
Q_ASSERT(isValid());
|
||||
BerkeleyDB::DBT dbkey, dbvalue;
|
||||
::memset(&dbkey, 0, sizeof(BerkeleyDB::DBT));
|
||||
::memset(&dbvalue, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
char uselesszero = 0;
|
||||
dbkey.data = &uselesszero;
|
||||
dbkey.size = sizeof(char);
|
||||
dbkey.ulen = 0;
|
||||
dbkey.flags = DB_DBT_USERMEM;
|
||||
|
||||
|
||||
quint64 newlevel = level() + 1;
|
||||
|
||||
|
||||
QByteArray d = QxtBdb::qxtMetaSave<T>(t);
|
||||
|
||||
|
||||
dbvalue.size = sizeof(quint64) + d.size();
|
||||
dbvalue.ulen = dbvalue.size;
|
||||
dbvalue.data =::malloc(dbvalue.size);
|
||||
::memcpy(dbvalue.data, &newlevel, sizeof(quint64));
|
||||
::memcpy((quint64*)dbvalue.data + 1, d.data(), d.size());
|
||||
dbvalue.flags = DB_DBT_USERMEM;
|
||||
|
||||
int ret = 234525;
|
||||
|
||||
|
||||
QxtBdbTreeIterator<T> e = *this;
|
||||
if (dbc)
|
||||
{
|
||||
while (e.db->get((void*)0, 0, 0, 0, DB_NEXT_DUP, e.dbc))
|
||||
{
|
||||
if (e.level() <= level())
|
||||
{
|
||||
#if DB_VERSION_MINOR > 5
|
||||
e.db->get((void*)0, 0, 0, 0, DB_PREV_DUP, e.dbc);
|
||||
#else
|
||||
e.db->get((void*)0, 0, 0, 0, DB_PREV, e.dbc);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = dbc->c_put(e.dbc, &dbkey, &dbvalue, DB_AFTER);
|
||||
}
|
||||
else if (root)
|
||||
{
|
||||
ret = db->db->put(db->db, NULL, &dbkey, &dbvalue, NULL);
|
||||
BerkeleyDB::DBC *cursor;
|
||||
db->db->cursor(db->db, NULL, &cursor, 0);
|
||||
if (db->get((void*)0, 0, 0, 0, DB_LAST, cursor))
|
||||
e = QxtBdbTreeIterator<T>(cursor, db);
|
||||
|
||||
}
|
||||
::free(dbvalue.data);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
qWarning("QxtBdbTreeIterator::append failed %i", ret);
|
||||
return QxtBdbTreeIterator<T>();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::prepend(const T & t)
|
||||
{
|
||||
if (!dbc)
|
||||
return QxtBdbTreeIterator<T>();
|
||||
QxtBdbTreeIterator<T> e(*this);
|
||||
|
||||
BerkeleyDB::DBT dbkey, dbvalue;
|
||||
::memset(&dbkey, 0, sizeof(BerkeleyDB::DBT));
|
||||
::memset(&dbvalue, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
char uselesszero = 0;
|
||||
dbkey.data = &uselesszero;
|
||||
dbkey.size = sizeof(char);
|
||||
dbkey.ulen = 0;
|
||||
dbkey.flags = DB_DBT_USERMEM;
|
||||
|
||||
|
||||
quint64 newlevel = level();
|
||||
|
||||
|
||||
QByteArray d = QxtBdb::qxtMetaSave<T>(t);
|
||||
|
||||
|
||||
dbvalue.size = sizeof(quint64) + d.size();
|
||||
dbvalue.ulen = dbvalue.size;
|
||||
dbvalue.data =::malloc(dbvalue.size);
|
||||
::memcpy(dbvalue.data, &newlevel, sizeof(quint64));
|
||||
::memcpy((quint64*)dbvalue.data + 1, d.data(), d.size());
|
||||
dbvalue.flags = DB_DBT_USERMEM;
|
||||
|
||||
int ret = 234525;
|
||||
ret = e.dbc->c_put(e.dbc, &dbkey, &dbvalue, DB_BEFORE);
|
||||
::free(dbvalue.data);
|
||||
|
||||
if (ret != 0)
|
||||
return QxtBdbTreeIterator<T>();
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
quint64 QxtBdbTreeIterator<T>::level() const
|
||||
{
|
||||
if (!dbc)
|
||||
return 0;
|
||||
|
||||
BerkeleyDB::DBT dbkey, dbvalue;
|
||||
memset(&dbkey, 0, sizeof(BerkeleyDB::DBT));
|
||||
memset(&dbvalue, 0, sizeof(BerkeleyDB::DBT));
|
||||
|
||||
dbvalue.size = 0;
|
||||
dbvalue.size = 0;
|
||||
dbvalue.ulen = 0;
|
||||
dbvalue.flags = DB_DBT_USERMEM;
|
||||
|
||||
|
||||
dbkey.ulen = 0;
|
||||
dbkey.flags = DB_DBT_USERMEM;
|
||||
|
||||
int ret = dbc->c_get(dbc, &dbkey, &dbvalue, DB_CURRENT);
|
||||
if (ret != DB_BUFFER_SMALL)
|
||||
qFatal("QxtBdbTreeIterator::level() %s", qPrintable(QxtBdb::dbErrorCodeToString(ret)));
|
||||
dbvalue.ulen = dbvalue.size;
|
||||
dbvalue.data =::malloc(dbvalue.size);
|
||||
|
||||
dbkey.ulen = dbkey.size;
|
||||
dbkey.data =::malloc(dbkey.size);
|
||||
|
||||
ret = dbc->c_get(dbc, &dbkey, &dbvalue, DB_CURRENT);
|
||||
|
||||
quint64 lvl;
|
||||
::memcpy(&lvl, dbvalue.data, sizeof(quint64));
|
||||
::free(dbkey.data);
|
||||
::free(dbvalue.data);
|
||||
|
||||
if (ret != 0)
|
||||
return 0;
|
||||
|
||||
return lvl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtBdbTreeIterator<T> QxtBdbTreeIterator<T>::erase()
|
||||
{
|
||||
Q_ASSERT(isValid());
|
||||
quint64 before = level();
|
||||
Q_FOREVER
|
||||
{
|
||||
|
||||
int ret = dbc->c_del(dbc, 0);
|
||||
if (ret != 0)
|
||||
{
|
||||
qWarning("QxtBdbTreeIterator<T>::erase() failed %s", qPrintable(QxtBdb::dbErrorCodeToString(ret)));
|
||||
return QxtBdbTreeIterator<T>();
|
||||
}
|
||||
|
||||
|
||||
if (!db->get((void*)0, 0, 0, 0, DB_NEXT_DUP, dbc))
|
||||
return *this;
|
||||
if (level() <= before)
|
||||
return *this;
|
||||
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,32 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtBerkeley module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTBERKELEY_H_INCLUDED
|
||||
#define QXTBERKELEY_H_INCLUDED
|
||||
|
||||
#include "qxtbdb.h"
|
||||
#include "qxtbdbhash.h"
|
||||
#include "qxtbdbtree.h"
|
||||
|
||||
#endif // QXTBERKELEY_H_INCLUDED
|
@ -1,114 +0,0 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
|
||||
HEADERS += qxtabstractconnectionmanager.h
|
||||
HEADERS += qxtabstractsignalserializer.h
|
||||
HEADERS += qxtalgorithms.h
|
||||
HEADERS += qxtboundcfunction.h
|
||||
HEADERS += qxtboundfunction.h
|
||||
HEADERS += qxtboundfunctionbase.h
|
||||
HEADERS += qxtcore.h
|
||||
HEADERS += qxtcommandoptions.h
|
||||
HEADERS += qxtcsvmodel.h
|
||||
HEADERS += qxtdaemon.h
|
||||
HEADERS += qxtdatastreamsignalserializer.h
|
||||
HEADERS += qxtdeplex.h
|
||||
HEADERS += qxtdeplex_p.h
|
||||
HEADERS += qxterror.h
|
||||
HEADERS += qxtfifo.h
|
||||
HEADERS += qxtglobal.h
|
||||
HEADERS += qxthmac.h
|
||||
HEADERS += qxtjson.h
|
||||
HEADERS += qxtjob.h
|
||||
HEADERS += qxtjob_p.h
|
||||
HEADERS += qxtlinesocket.h
|
||||
HEADERS += qxtlinesocket_p.h
|
||||
HEADERS += qxtlinkedtree.h
|
||||
HEADERS += qxtlocale.h
|
||||
HEADERS += qxtlocale_data_p.h
|
||||
HEADERS += qxtlogger.h
|
||||
HEADERS += qxtlogger_p.h
|
||||
HEADERS += qxtloggerengine.h
|
||||
HEADERS += qxtlogstream.h
|
||||
HEADERS += qxtlogstream_p.h
|
||||
HEADERS += qxtmetaobject.h
|
||||
HEADERS += qxtmetatype.h
|
||||
HEADERS += qxtmodelserializer.h
|
||||
HEADERS += qxtmultisignalwaiter.h
|
||||
HEADERS += qxtnamespace.h
|
||||
HEADERS += qxtnull.h
|
||||
HEADERS += qxtnullable.h
|
||||
HEADERS += qxtpairlist.h
|
||||
HEADERS += qxtpimpl.h
|
||||
HEADERS += qxtpipe.h
|
||||
HEADERS += qxtpipe_p.h
|
||||
HEADERS += qxtpointerlist.h
|
||||
HEADERS += qxtsharedprivate.h
|
||||
HEADERS += qxtsignalgroup.h
|
||||
HEADERS += qxtsignalwaiter.h
|
||||
HEADERS += qxtslotjob.h
|
||||
HEADERS += qxtslotjob_p.h
|
||||
HEADERS += qxtslotmapper.h
|
||||
HEADERS += qxtstdio.h
|
||||
HEADERS += qxtstdio_p.h
|
||||
HEADERS += qxtstdstreambufdevice.h
|
||||
HEADERS += qxttimer.h
|
||||
HEADERS += qxttypelist.h
|
||||
HEADERS += qxtrpcservice.h
|
||||
HEADERS += qxtrpcservice_p.h
|
||||
|
||||
SOURCES += qxtabstractconnectionmanager.cpp
|
||||
SOURCES += qxtcommandoptions.cpp
|
||||
SOURCES += qxtcsvmodel.cpp
|
||||
SOURCES += qxtdaemon.cpp
|
||||
SOURCES += qxtdatastreamsignalserializer.cpp
|
||||
SOURCES += qxtdeplex.cpp
|
||||
SOURCES += qxterror.cpp
|
||||
SOURCES += qxtfifo.cpp
|
||||
SOURCES += qxtglobal.cpp
|
||||
SOURCES += qxthmac.cpp
|
||||
SOURCES += qxtlocale.cpp
|
||||
SOURCES += qxtjson.cpp
|
||||
SOURCES += qxtjob.cpp
|
||||
SOURCES += qxtlinesocket.cpp
|
||||
SOURCES += qxtlinkedtree.cpp
|
||||
SOURCES += qxtlogger.cpp
|
||||
SOURCES += qxtloggerengine.cpp
|
||||
SOURCES += qxtlogstream.cpp
|
||||
SOURCES += qxtmetaobject.cpp
|
||||
SOURCES += qxtmodelserializer.cpp
|
||||
SOURCES += qxtmultisignalwaiter.cpp
|
||||
SOURCES += qxtnull.cpp
|
||||
SOURCES += qxtpipe.cpp
|
||||
SOURCES += qxtpointerlist.cpp
|
||||
SOURCES += qxtsignalgroup.cpp
|
||||
SOURCES += qxtsignalwaiter.cpp
|
||||
SOURCES += qxtslotjob.cpp
|
||||
SOURCES += qxtslotmapper.cpp
|
||||
SOURCES += qxtstdio.cpp
|
||||
SOURCES += qxtstdstreambufdevice.cpp
|
||||
SOURCES += qxttimer.cpp
|
||||
SOURCES += qxtrpcservice.cpp
|
||||
|
||||
!symbian {
|
||||
# QxtSerialDevice and QxtFileLock
|
||||
# are disabled for Symbian pending implementation
|
||||
|
||||
HEADERS += qxtfilelock.h
|
||||
HEADERS += qxtfilelock_p.h
|
||||
|
||||
SOURCES += qxtfilelock.cpp
|
||||
|
||||
unix {
|
||||
HEADERS += qxtserialdevice.h
|
||||
HEADERS += qxtserialdevice_p.h
|
||||
|
||||
SOURCES += qxtfilelock_unix.cpp
|
||||
SOURCES += qxtserialdevice.cpp
|
||||
SOURCES += qxtserialdevice_unix.cpp
|
||||
}
|
||||
|
||||
win32 {
|
||||
SOURCES += qxtfilelock_win.cpp
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = QxtCore
|
||||
|
||||
DEFINES += QXTCORE_LIBRARY
|
||||
include(../../../../openpilotgcslibrary.pri)
|
||||
|
||||
DEFINES += BUILD_QXT_CORE
|
||||
|
||||
include(core.pri)
|
||||
include(logengines/logengines.pri)
|
||||
#include(../qxtbase.pri)
|
@ -1,18 +0,0 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
|
||||
# interfaces
|
||||
HEADERS += $$PWD/qxtabstractfileloggerengine.h $$PWD/qxtabstractiologgerengine.h
|
||||
SOURCES += $$PWD/qxtabstractfileloggerengine.cpp $$PWD/qxtabstractiologgerengine.cpp
|
||||
|
||||
# Basic STD Logger Engine
|
||||
HEADERS += $$PWD/qxtbasicstdloggerengine.h
|
||||
SOURCES += $$PWD/qxtbasicstdloggerengine.cpp
|
||||
|
||||
# Basic File Logger Engine
|
||||
HEADERS += $$PWD/qxtbasicfileloggerengine.h
|
||||
SOURCES += $$PWD/qxtbasicfileloggerengine.cpp
|
||||
|
||||
# XML File Logger Engine
|
||||
HEADERS += $$PWD/qxtxmlfileloggerengine.h
|
||||
SOURCES += $$PWD/qxtxmlfileloggerengine.cpp
|
@ -1,166 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtabstractfileloggerengine.h"
|
||||
|
||||
/*!
|
||||
\class QxtAbstractFileLoggerEngine
|
||||
\brief The QxtAbstractFileLoggerEngine class is the base class of file logger engines.
|
||||
\inmodule QxtCore
|
||||
|
||||
\sa QxtLogger
|
||||
*/
|
||||
|
||||
class QxtAbstractFileLoggerEnginePrivate : public QxtPrivate<QxtAbstractFileLoggerEngine>
|
||||
{
|
||||
QXT_DECLARE_PUBLIC(QxtAbstractFileLoggerEngine)
|
||||
|
||||
public:
|
||||
QString logFile;
|
||||
QIODevice::OpenMode mode;
|
||||
};
|
||||
|
||||
/*!
|
||||
Constructs a QxtAbstractFileLoggerEngine with \a fileName and open \a mode.
|
||||
*/
|
||||
QxtAbstractFileLoggerEngine::QxtAbstractFileLoggerEngine(const QString &fileName, QIODevice::OpenMode mode)
|
||||
: QxtAbstractIOLoggerEngine(0)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtAbstractFileLoggerEngine);
|
||||
qxt_d().mode = mode;
|
||||
setLogFileName(fileName);
|
||||
}
|
||||
|
||||
/*!
|
||||
Destructs the file logger engine.
|
||||
*/
|
||||
QxtAbstractFileLoggerEngine::~QxtAbstractFileLoggerEngine()
|
||||
{
|
||||
killLoggerEngine();
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtAbstractFileLoggerEngine::initLoggerEngine()
|
||||
{
|
||||
// Are we already logging to a file? If so, close it and disable logging.
|
||||
killLoggerEngine();
|
||||
|
||||
// If the file exists, check if we can write to it. If we can, we append!
|
||||
// If the file doesn't exits, try to create it.
|
||||
// If we can't write to a file, disable this plugin.
|
||||
if (qxt_d().logFile.isEmpty()) return; // if there's no filename, disable the engine until one is given
|
||||
|
||||
setDevice(new QFile(qxt_d().logFile));
|
||||
if (!device()->open(qxt_d().mode)
|
||||
|| !device()->isWritable())
|
||||
{
|
||||
killLoggerEngine();
|
||||
return;
|
||||
}
|
||||
|
||||
enableLogging();
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtAbstractFileLoggerEngine::killLoggerEngine()
|
||||
{
|
||||
if (device() != 0)
|
||||
{
|
||||
if (device()->isOpen()) device()->close();
|
||||
delete device();
|
||||
setDevice(0);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtAbstractFileLoggerEngine::isInitialized() const
|
||||
{
|
||||
return (device() != 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtAbstractFileLoggerEngine::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> &messages)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case QxtLogger::ErrorLevel:
|
||||
writeToFile("Error", messages);
|
||||
break;
|
||||
case QxtLogger::WarningLevel:
|
||||
writeToFile("Warning", messages);
|
||||
break;
|
||||
case QxtLogger::CriticalLevel:
|
||||
writeToFile("Critical", messages);
|
||||
break;
|
||||
case QxtLogger::FatalLevel:
|
||||
writeToFile("Fatal", messages);
|
||||
break;
|
||||
case QxtLogger::TraceLevel:
|
||||
writeToFile("Trace", messages);
|
||||
break;
|
||||
case QxtLogger::DebugLevel:
|
||||
writeToFile("Debug", messages);
|
||||
break;
|
||||
case QxtLogger::InfoLevel:
|
||||
writeToFile("Info", messages);
|
||||
break;
|
||||
default:
|
||||
writeToFile(QString(), messages);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the log \a fileName.
|
||||
*/
|
||||
void QxtAbstractFileLoggerEngine::setLogFileName(const QString &fileName)
|
||||
{
|
||||
qxt_d().logFile = fileName;
|
||||
initLoggerEngine();
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the log file name.
|
||||
*/
|
||||
QString QxtAbstractFileLoggerEngine::logFileName() const
|
||||
{
|
||||
return qxt_d().logFile;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn virtual void QxtAbstractFileLoggerEngine::writeToFile( const QString &level, const QVariantList &messages ) = 0
|
||||
|
||||
Writes \a messages to file with given \a level.
|
||||
|
||||
This function is called by QxtAbstractFileLoggerEngine. Reimplement this function when creating a subclass of QxtAbstractFileLoggerEngine.
|
||||
*/
|
@ -1,55 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTABSTRACTFILELOGGERENGINE_H
|
||||
#define QXTABSTRACTFILELOGGERENGINE_H
|
||||
|
||||
#include "qxtabstractiologgerengine.h"
|
||||
#include "qxtglobal.h"
|
||||
|
||||
class QxtAbstractFileLoggerEnginePrivate;
|
||||
|
||||
class QXT_CORE_EXPORT QxtAbstractFileLoggerEngine : public QxtAbstractIOLoggerEngine
|
||||
{
|
||||
QXT_DECLARE_PRIVATE(QxtAbstractFileLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtAbstractFileLoggerEngine(const QString &fileName, QIODevice::OpenMode mode);
|
||||
~QxtAbstractFileLoggerEngine();
|
||||
|
||||
virtual void initLoggerEngine();
|
||||
virtual void killLoggerEngine();
|
||||
virtual bool isInitialized() const;
|
||||
|
||||
virtual void writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> &messages);
|
||||
|
||||
void setLogFileName(const QString &fileName);
|
||||
QString logFileName() const;
|
||||
|
||||
protected:
|
||||
virtual void writeToFile(const QString &level, const QVariantList &messages) = 0;
|
||||
};
|
||||
|
||||
#endif // QXTABSTRACTFILELOGGERENGINE_H
|
@ -1,74 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtabstractiologgerengine.h"
|
||||
|
||||
/*!
|
||||
\class QxtAbstractIOLoggerEngine
|
||||
\brief The QxtAbstractIOLoggerEngine class is the base class of IO logger engines.
|
||||
\inmodule QxtCore
|
||||
|
||||
\sa QxtLogger
|
||||
*/
|
||||
|
||||
class QxtAbstractIOLoggerEnginePrivate : public QxtPrivate<QxtAbstractIOLoggerEngine>
|
||||
{
|
||||
QXT_DECLARE_PUBLIC(QxtAbstractIOLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtAbstractIOLoggerEnginePrivate();
|
||||
|
||||
QIODevice *io_device;
|
||||
};
|
||||
|
||||
QxtAbstractIOLoggerEnginePrivate::QxtAbstractIOLoggerEnginePrivate()
|
||||
: io_device(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a QxtAbstractIOLoggerEngine with \a device.
|
||||
*/
|
||||
QxtAbstractIOLoggerEngine::QxtAbstractIOLoggerEngine(QIODevice *device)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtAbstractFileLoggerEngine);
|
||||
setDevice(device);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the IO \a device.
|
||||
*/
|
||||
void QxtAbstractIOLoggerEngine::setDevice(QIODevice *device)
|
||||
{
|
||||
qxt_d().io_device = device;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the IO device.
|
||||
*/
|
||||
QIODevice *QxtAbstractIOLoggerEngine::device() const
|
||||
{
|
||||
return qxt_d().io_device;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTABSTRACTIOLOGGERENGINE_H
|
||||
#define QXTABSTRACTIOLOGGERENGINE_H
|
||||
|
||||
#include "qxtloggerengine.h"
|
||||
#include "qxtglobal.h"
|
||||
|
||||
class QxtAbstractIOLoggerEnginePrivate;
|
||||
|
||||
class QXT_CORE_EXPORT QxtAbstractIOLoggerEngine : public QxtLoggerEngine
|
||||
{
|
||||
QXT_DECLARE_PRIVATE(QxtAbstractIOLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtAbstractIOLoggerEngine(QIODevice *device = 0);
|
||||
|
||||
void setDevice(QIODevice *device);
|
||||
QIODevice* device() const;
|
||||
};
|
||||
|
||||
#endif // QXTABSTRACTIOLOGGERENGINE_H
|
@ -1,102 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtbasicfileloggerengine.h"
|
||||
#include <QDateTime>
|
||||
|
||||
/*!
|
||||
\class QxtBasicFileLoggerEngine
|
||||
\brief The QxtBasicFileLoggerEngine class provides a basic file logger engine.
|
||||
\inmodule QxtCore
|
||||
|
||||
Example basic file log output:
|
||||
\code
|
||||
[22:38:33.159] [Error] Unknown error
|
||||
[22:51:43.488] [Debug] What's going on?
|
||||
Hi there!
|
||||
\endcode
|
||||
|
||||
\sa QxtLogger
|
||||
*/
|
||||
|
||||
class QxtBasicFileLoggerEnginePrivate : public QxtPrivate<QxtBasicFileLoggerEngine>
|
||||
{
|
||||
public:
|
||||
QXT_DECLARE_PUBLIC(QxtBasicFileLoggerEngine)
|
||||
QString dateFormat;
|
||||
};
|
||||
|
||||
/*!
|
||||
Constructs a basic file logger engine with \a fileName.
|
||||
*/
|
||||
QxtBasicFileLoggerEngine::QxtBasicFileLoggerEngine(const QString &fileName)
|
||||
: QxtAbstractFileLoggerEngine(fileName, QIODevice::ReadWrite | QIODevice::Append | QIODevice::Unbuffered)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtBasicFileLoggerEngine);
|
||||
qxt_d().dateFormat = "hh:mm:ss.zzz";
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the date format in use by this logger engine.
|
||||
\sa QDateTime::toString()
|
||||
*/
|
||||
QString QxtBasicFileLoggerEngine::dateFormat() const
|
||||
{
|
||||
return qxt_d().dateFormat;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the date \a format used by this logger engine.
|
||||
\sa QDateTime::toString()
|
||||
*/
|
||||
void QxtBasicFileLoggerEngine::setDateFormat(const QString& format)
|
||||
{
|
||||
qxt_d().dateFormat = format;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtBasicFileLoggerEngine::writeToFile(const QString &level, const QVariantList &messages)
|
||||
{
|
||||
if (messages.isEmpty()) return;
|
||||
QString header = '[' + QDateTime::currentDateTime().toString(qxt_d().dateFormat) + "] [" + level + "] ";
|
||||
QString padding;
|
||||
QIODevice* file = device();
|
||||
Q_ASSERT(file);
|
||||
file->write(header.toUtf8());
|
||||
for (int i = 0; i < header.size(); i++) padding.append(" ");
|
||||
int count = 0;
|
||||
Q_FOREACH(const QVariant& out, messages)
|
||||
{
|
||||
if (!out.isNull())
|
||||
{
|
||||
if (count != 0) file->write(padding.toUtf8());
|
||||
file->write(out.toString().toUtf8());
|
||||
file->write("\n");
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTBASICFILELOGGERENGINE_H
|
||||
#define QXTBASICFILELOGGERENGINE_H
|
||||
|
||||
#include "qxtloggerengine.h"
|
||||
#include "qxtabstractfileloggerengine.h"
|
||||
#include <QTextStream>
|
||||
#include <QFile>
|
||||
|
||||
/*******************************************************************************
|
||||
QBasicSTDLoggerEngine
|
||||
The basic logger engine included with QxtLogger.
|
||||
*******************************************************************************/
|
||||
|
||||
class QxtBasicFileLoggerEnginePrivate;
|
||||
class QXT_CORE_EXPORT QxtBasicFileLoggerEngine : public QxtAbstractFileLoggerEngine
|
||||
{
|
||||
public:
|
||||
QxtBasicFileLoggerEngine(const QString &fileName = QString());
|
||||
|
||||
public:
|
||||
QString dateFormat() const;
|
||||
void setDateFormat(const QString& format);
|
||||
|
||||
protected:
|
||||
virtual void writeToFile(const QString &level, const QVariantList &messages);
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtBasicFileLoggerEngine)
|
||||
};
|
||||
|
||||
#endif // QXTBASICFILELOGGERENGINE_H
|
@ -1,236 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtbasicstdloggerengine.h"
|
||||
#include <QTextStream>
|
||||
#include <QTime>
|
||||
|
||||
#define QXT_REQUIRED_LEVELS (QxtLogger::WarningLevel | QxtLogger::ErrorLevel | QxtLogger::CriticalLevel | QxtLogger::FatalLevel)
|
||||
|
||||
/*!
|
||||
\class QxtBasicSTDLoggerEngine
|
||||
\brief The QxtBasicSTDLoggerEngine class provides a basic STD logger engine.
|
||||
\inmodule QxtCore
|
||||
|
||||
Example basic STD log output:
|
||||
\code
|
||||
[22:38:33.159] [Error] Unknown error
|
||||
[22:51:43.488] [Debug] What's going on?
|
||||
Hi there!
|
||||
\endcode
|
||||
|
||||
\sa QxtLogger
|
||||
*/
|
||||
|
||||
class QxtBasicSTDLoggerEnginePrivate : public QxtPrivate<QxtBasicSTDLoggerEngine>
|
||||
{
|
||||
QXT_DECLARE_PUBLIC(QxtBasicSTDLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtBasicSTDLoggerEnginePrivate();
|
||||
|
||||
QTextStream *errstream, *outstream;
|
||||
};
|
||||
|
||||
QxtBasicSTDLoggerEnginePrivate::QxtBasicSTDLoggerEnginePrivate()
|
||||
{
|
||||
errstream = new QTextStream(stderr);
|
||||
outstream = new QTextStream(stdout);
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructor.
|
||||
*/
|
||||
QxtBasicSTDLoggerEngine::QxtBasicSTDLoggerEngine()
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtBasicSTDLoggerEngine);
|
||||
#ifndef QT_NO_DEBUG
|
||||
setLogLevelsEnabled(QXT_REQUIRED_LEVELS);
|
||||
#else
|
||||
setLogLevelsEnabled(QXT_REQUIRED_LEVELS | QxtLogger::DebugLevel);
|
||||
#endif
|
||||
enableLogging();
|
||||
}
|
||||
|
||||
/*!
|
||||
Destructor.
|
||||
*/
|
||||
QxtBasicSTDLoggerEngine::~QxtBasicSTDLoggerEngine()
|
||||
{
|
||||
if (qxt_d().errstream)
|
||||
{
|
||||
qxt_d().errstream->flush();
|
||||
delete qxt_d().errstream;
|
||||
qxt_d().errstream = 0;
|
||||
}
|
||||
if (qxt_d().outstream)
|
||||
{
|
||||
qxt_d().outstream->flush();
|
||||
delete qxt_d().outstream;
|
||||
qxt_d().errstream = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtBasicSTDLoggerEngine::initLoggerEngine()
|
||||
{
|
||||
return; // Should work out of the box!
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtBasicSTDLoggerEngine::killLoggerEngine()
|
||||
{
|
||||
return; // I do nothing.
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtBasicSTDLoggerEngine::isInitialized() const
|
||||
{
|
||||
return qxt_d().errstream && qxt_d().outstream;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the stderr stream.
|
||||
*/
|
||||
QTextStream* QxtBasicSTDLoggerEngine::stdErrStream() const
|
||||
{
|
||||
return qxt_d().errstream;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the stdout stream.
|
||||
*/
|
||||
QTextStream* QxtBasicSTDLoggerEngine::stdOutStream() const
|
||||
{
|
||||
return qxt_d().outstream;
|
||||
}
|
||||
|
||||
/*!
|
||||
Enables \a level if \a enable is \c true, disables otherwise.
|
||||
*/
|
||||
void QxtBasicSTDLoggerEngine::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable)
|
||||
{
|
||||
QxtLoggerEngine::setLogLevelsEnabled(level | QXT_REQUIRED_LEVELS, enable);
|
||||
if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QXT_REQUIRED_LEVELS);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtBasicSTDLoggerEngine::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> &msgs)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case QxtLogger::ErrorLevel:
|
||||
writeToStdErr("Error", msgs);
|
||||
break;
|
||||
case QxtLogger::WarningLevel:
|
||||
writeToStdOut("Warning", msgs);
|
||||
break;
|
||||
case QxtLogger::CriticalLevel:
|
||||
writeToStdErr("Critical", msgs);
|
||||
break;
|
||||
case QxtLogger::FatalLevel:
|
||||
writeToStdErr("!!FATAL!!", msgs);
|
||||
break;
|
||||
case QxtLogger::TraceLevel:
|
||||
writeToStdOut("Trace", msgs);
|
||||
break;
|
||||
case QxtLogger::DebugLevel:
|
||||
writeToStdErr("DEBUG", msgs);
|
||||
break;
|
||||
case QxtLogger::InfoLevel:
|
||||
writeToStdOut("INFO", msgs);
|
||||
break;
|
||||
default:
|
||||
writeToStdOut("", msgs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
A helper function that actually writes \a msgs to stderr with given \a level.
|
||||
|
||||
This function is called by QxtBasicSTDLoggerEngine. Reimplement this function when creating a subclass of QxtBasicSTDLoggerEngine.
|
||||
*/
|
||||
void QxtBasicSTDLoggerEngine::writeToStdErr(const QString &level, const QList<QVariant> &msgs)
|
||||
{
|
||||
if (msgs.isEmpty()) return;
|
||||
QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] [" + level + "] ";
|
||||
QString padding;
|
||||
QTextStream* errstream = stdErrStream();
|
||||
Q_ASSERT(errstream);
|
||||
*errstream << header;
|
||||
for (int i = 0; i < header.size(); i++) padding.append(" ");
|
||||
int count = 0;
|
||||
Q_FOREACH(const QVariant& out, msgs)
|
||||
{
|
||||
if (!out.isNull())
|
||||
{
|
||||
if (count != 0) *errstream << padding;
|
||||
*errstream << out.toString();// << '\n';
|
||||
}
|
||||
count++;
|
||||
}
|
||||
*errstream << endl;
|
||||
}
|
||||
|
||||
/*!
|
||||
A helper function that actually writes \a msgs to stdout with given \a level.
|
||||
|
||||
This function is called by QxtBasicSTDLoggerEngine. Reimplement this function when creating a subclass of QxtBasicSTDLoggerEngine.
|
||||
*/
|
||||
void QxtBasicSTDLoggerEngine::writeToStdOut(const QString& level, const QList<QVariant> &msgs)
|
||||
{
|
||||
/* Message format...
|
||||
[time] [error level] First message.....
|
||||
second message
|
||||
third message
|
||||
*/
|
||||
if (msgs.isEmpty()) return;
|
||||
QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] [" + level + "] ";
|
||||
QString padding;
|
||||
QTextStream* outstream = stdOutStream();
|
||||
Q_ASSERT(outstream);
|
||||
*outstream << header;
|
||||
for (int i = 0; i < header.size(); i++) padding.append(' ');
|
||||
int count = 0;
|
||||
Q_FOREACH(const QVariant& out, msgs)
|
||||
{
|
||||
if (!out.isNull())
|
||||
{
|
||||
if (count != 0) *outstream << padding;
|
||||
*outstream << out.toString();// << '\n';
|
||||
}
|
||||
count++;
|
||||
}
|
||||
*outstream << endl;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTBASICSTDLOGGERENGINE_H
|
||||
#define QXTBASICSTDLOGGERENGINE_H
|
||||
|
||||
#include "qxtloggerengine.h"
|
||||
#include "qxtglobal.h"
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QTextStream)
|
||||
class QxtBasicSTDLoggerEnginePrivate;
|
||||
|
||||
/*******************************************************************************
|
||||
QBasicSTDLoggerEngine
|
||||
The basic logger engine included with QxtLogger.
|
||||
*******************************************************************************/
|
||||
class QXT_CORE_EXPORT QxtBasicSTDLoggerEngine : public QxtLoggerEngine
|
||||
{
|
||||
QXT_DECLARE_PRIVATE(QxtBasicSTDLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtBasicSTDLoggerEngine();
|
||||
~QxtBasicSTDLoggerEngine();
|
||||
|
||||
void initLoggerEngine();
|
||||
void killLoggerEngine();
|
||||
void writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> &messages);
|
||||
void setLogLevelEnabled(QxtLogger::LogLevels level, bool enable = true);
|
||||
|
||||
bool isInitialized() const;
|
||||
|
||||
QTextStream* stdErrStream() const;
|
||||
QTextStream* stdOutStream() const;
|
||||
|
||||
protected:
|
||||
virtual void writeToStdErr(const QString& str_level, const QList<QVariant> &msgs);
|
||||
virtual void writeToStdOut(const QString& str_level, const QList<QVariant> &msgs);
|
||||
};
|
||||
|
||||
#endif // QXTBASICSTDLOGGERENGINE_H
|
@ -1,158 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtxmlfileloggerengine.h"
|
||||
#include <QTime>
|
||||
|
||||
/*!
|
||||
\class QxtXmlFileLoggerEngine
|
||||
\brief The QxtXmlFileLoggerEngine class provides an XML file logger engine.
|
||||
\inmodule QxtCore
|
||||
|
||||
Example XML log output:
|
||||
\code
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<log>
|
||||
<entry type="Error" time="22:38:33.159159">
|
||||
<message>Unknown error</message>
|
||||
</entry>
|
||||
<entry type="Debug" time="22:51:43.488488">
|
||||
<message>What's going on?</message>
|
||||
<message>Hi there</message>
|
||||
</entry>
|
||||
</log>
|
||||
\endcode
|
||||
|
||||
\sa QxtLogger
|
||||
*/
|
||||
|
||||
class QxtXmlFileLoggerEnginePrivate : public QxtPrivate<QxtXmlFileLoggerEngine>
|
||||
{
|
||||
QXT_DECLARE_PUBLIC(QxtXmlFileLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtXmlFileLoggerEnginePrivate();
|
||||
QString tab;
|
||||
};
|
||||
|
||||
QxtXmlFileLoggerEnginePrivate::QxtXmlFileLoggerEnginePrivate()
|
||||
: tab(" ")
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs an XML file logger engine with \a fileName.
|
||||
*/
|
||||
QxtXmlFileLoggerEngine::QxtXmlFileLoggerEngine(const QString& fileName)
|
||||
: QxtAbstractFileLoggerEngine(fileName, QIODevice::ReadWrite | QIODevice::Unbuffered)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtXmlFileLoggerEngine);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtXmlFileLoggerEngine::initLoggerEngine()
|
||||
{
|
||||
QxtAbstractFileLoggerEngine::initLoggerEngine();
|
||||
|
||||
// Mkay, we have an open file. We need to check that it's all valid.
|
||||
// at the end of this block of code, we either can't log, or the carat is ready for writing.
|
||||
/*
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<log>
|
||||
<entry type="Error" time="sometime">
|
||||
<message>What's going on?</message>
|
||||
<message?Hi there</message>
|
||||
</entry>
|
||||
</log>
|
||||
*/
|
||||
QIODevice* file = device();
|
||||
Q_ASSERT(file);
|
||||
if (file->size() == 0)
|
||||
{
|
||||
file->write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||
file->write("<log>\n");
|
||||
file->write("</log>");
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray data = file->read(64);
|
||||
if (!data.startsWith(QByteArray("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<log>")))
|
||||
{
|
||||
QFile* ptr_fileTarget = static_cast<QFile*>(file);
|
||||
qxtLog->warning(QString(" is not a valid XML log file.").prepend(ptr_fileTarget->fileName()));
|
||||
killLoggerEngine();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtXmlFileLoggerEngine::writeToFile(const QString &level, const QVariantList &messages)
|
||||
{
|
||||
QIODevice* ptr_fileTarget = device();
|
||||
Q_ASSERT(ptr_fileTarget);
|
||||
ptr_fileTarget->seek(ptr_fileTarget->size() - 6);
|
||||
ptr_fileTarget->write(qxt_d().tab.toUtf8());
|
||||
ptr_fileTarget->write("<entry type=\"");
|
||||
ptr_fileTarget->write(level.toUtf8());
|
||||
ptr_fileTarget->write("\" time=\"");
|
||||
ptr_fileTarget->write(QTime::currentTime().toString("hh:mm:ss.zzzz").toUtf8());
|
||||
ptr_fileTarget->write("\">");
|
||||
ptr_fileTarget->write("\n");
|
||||
Q_FOREACH(const QVariant& m, messages)
|
||||
{
|
||||
ptr_fileTarget->write(qxt_d().tab.toUtf8());
|
||||
ptr_fileTarget->write(qxt_d().tab.toUtf8());
|
||||
ptr_fileTarget->write("<message>");
|
||||
ptr_fileTarget->write(toXmlSafeString(m.toString()).toUtf8());
|
||||
ptr_fileTarget->write("</message>\n");
|
||||
}
|
||||
|
||||
ptr_fileTarget->write(qxt_d().tab.toUtf8());
|
||||
ptr_fileTarget->write("</entry>");
|
||||
ptr_fileTarget->write("\n");
|
||||
ptr_fileTarget->write("</log>");
|
||||
}
|
||||
|
||||
/*!
|
||||
Replaces reserved characters from \a raw with corresponding entities.
|
||||
*/
|
||||
QString QxtXmlFileLoggerEngine::toXmlSafeString(const QString &raw)
|
||||
{
|
||||
/* Reserved characters:
|
||||
< <
|
||||
& &
|
||||
> <
|
||||
' '
|
||||
" "
|
||||
|
||||
Convert ampersands first, then the rest.
|
||||
*/
|
||||
return QByteArray(raw.toUtf8()).replace('&', "&").replace('<', "<").replace('>', ">").replace('\'', "'").replace('"', """);
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTXMLFILELOGGERENGINE_H
|
||||
#define QXTXMLFILELOGGERENGINE_H
|
||||
|
||||
#include "qxtloggerengine.h"
|
||||
#include "qxtabstractfileloggerengine.h"
|
||||
#include <QTextStream>
|
||||
#include <QFile>
|
||||
|
||||
class QxtXmlFileLoggerEnginePrivate;
|
||||
|
||||
class QXT_CORE_EXPORT QxtXmlFileLoggerEngine : public QxtAbstractFileLoggerEngine
|
||||
{
|
||||
QXT_DECLARE_PRIVATE(QxtXmlFileLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtXmlFileLoggerEngine(const QString& fileName = QString());
|
||||
|
||||
virtual void initLoggerEngine();
|
||||
|
||||
protected:
|
||||
virtual void writeToFile(const QString &level, const QVariantList &messages);
|
||||
static QString toXmlSafeString(const QString& unformatted); // because we're using 4.2, this was added in 4.4
|
||||
};
|
||||
|
||||
#endif // QXTXMLFILELOGGERENGINE_H
|
@ -1,133 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtabstractconnectionmanager.h"
|
||||
#include <QHash>
|
||||
#include <QtDebug>
|
||||
|
||||
/*!
|
||||
* \class QxtAbstractConnectionManager
|
||||
* \inmodule QxtCore
|
||||
* \brief The QxtAbstractConnectionManager class is an interface for classes that maintain connection pools
|
||||
*
|
||||
* QxtAbstractConnectionManager is a standardized interface for accepting and tracking
|
||||
* incoming connections.
|
||||
*
|
||||
* Each incoming connection is assigned an arbitrary, opaque client ID number. This
|
||||
* number can be used to retrieve the QIODevice associated with it. A list of IDs
|
||||
* for all current connections can be retrieved with the clients() function.
|
||||
*
|
||||
* As an abstract class, QxtAbstractConnectionManager cannot be used on its own.
|
||||
* Subclasses must implement isAcceptingConnections() to indicate the current listening
|
||||
* status of the connection manager and removeConnection() to perform necessary clean-up
|
||||
* of an established connection before disconnecting. Finally, a subclass must invoke
|
||||
* addConnection() after a new incoming connection has been established and prepared.
|
||||
*
|
||||
* \sa QxtTcpConnectionManager
|
||||
*/
|
||||
|
||||
class QxtAbstractConnectionManagerPrivate : public QxtPrivate<QxtAbstractConnectionManager>
|
||||
{
|
||||
public:
|
||||
QHash<quint64, QIODevice*> clients;
|
||||
|
||||
QXT_DECLARE_PUBLIC(QxtAbstractConnectionManager)
|
||||
};
|
||||
|
||||
/*!
|
||||
* Constructs a QxtAbstractConnectionManager object with the specified \a parent.
|
||||
*/
|
||||
QxtAbstractConnectionManager::QxtAbstractConnectionManager(QObject* parent) : QObject(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtAbstractConnectionManager);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destructs the connection manager.
|
||||
*/
|
||||
QxtAbstractConnectionManager::~QxtAbstractConnectionManager()
|
||||
{
|
||||
// virtual for subclasses, no need for implementation
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the number of connected clients.
|
||||
*/
|
||||
int QxtAbstractConnectionManager::clientCount() const
|
||||
{
|
||||
return qxt_d().clients.count();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns a list of client IDs for all connected clients.
|
||||
*/
|
||||
QList<quint64> QxtAbstractConnectionManager::clients() const
|
||||
{
|
||||
return qxt_d().clients.keys();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the QIODevice for the requested \a clientID.
|
||||
*/
|
||||
QIODevice* QxtAbstractConnectionManager::client(quint64 clientID) const
|
||||
{
|
||||
return qxt_d().clients.value(clientID, NULL);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Disconnects the connection with the specified \a clientID.
|
||||
*
|
||||
* Implementations should invoke this function when the connection should no longer be
|
||||
* used; for instance, when the QIODevice object is destroyed or the connection has been
|
||||
* closed. Code that uses the connection manager service should invoke this function to
|
||||
* close a connection on demand.
|
||||
*/
|
||||
void QxtAbstractConnectionManager::disconnect(quint64 clientID)
|
||||
{
|
||||
QIODevice* device = qxt_d().clients.value(clientID, 0);
|
||||
if (!device)
|
||||
{
|
||||
qWarning() << "QxtAbstractConnectionManager::disconnect: client ID not in use";
|
||||
return;
|
||||
}
|
||||
qxt_d().clients.remove(clientID);
|
||||
emit disconnected(device, clientID);
|
||||
removeConnection(device, clientID);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Begins managing a connection. Each \a device must have a unique, non-zero \a clientID, but
|
||||
* beyond this constraint implementations may use any convenient value. Implementations
|
||||
* should invoke this function after establishing a usable connection and performing any
|
||||
* desired initial negotiation.
|
||||
*
|
||||
* This function will emit the newConnection signal after the internal data structures have
|
||||
* been suitably updated.
|
||||
*/
|
||||
void QxtAbstractConnectionManager::addConnection(QIODevice* device, quint64 clientID)
|
||||
{
|
||||
qxt_d().clients[clientID] = device;
|
||||
emit newConnection(device, clientID);
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTABSTRACTCONNECTIONMANAGER_H
|
||||
#define QXTABSTRACTCONNECTIONMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <qxtglobal.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QIODevice)
|
||||
|
||||
class QxtAbstractConnectionManagerPrivate;
|
||||
class QXT_CORE_EXPORT QxtAbstractConnectionManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtAbstractConnectionManager(QObject* parent);
|
||||
virtual ~QxtAbstractConnectionManager();
|
||||
|
||||
int clientCount() const;
|
||||
QList<quint64> clients() const;
|
||||
QIODevice* client(quint64 clientID) const;
|
||||
|
||||
/*!
|
||||
* Returns true if the connection manager is currently accepting connections.
|
||||
* Returns false otherwise.
|
||||
*/
|
||||
virtual bool isAcceptingConnections() const = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
/*!
|
||||
* Indicates that the specified device, with the specified client ID, is ready for use.
|
||||
*/
|
||||
void newConnection(QIODevice* device, quint64 clientID);
|
||||
|
||||
/*!
|
||||
* Indicates that the device with the specified client ID has been disconnected.
|
||||
*/
|
||||
void disconnected(QIODevice* device, quint64 clientID);
|
||||
|
||||
public Q_SLOTS:
|
||||
void disconnect(quint64 clientID);
|
||||
|
||||
protected:
|
||||
void addConnection(QIODevice* device, quint64 clientID);
|
||||
|
||||
/*!
|
||||
* Stops managing a connection. This function is invoked by disconnect().
|
||||
* Implementations should perform whatever steps are necessary to close the connection
|
||||
* and clean up any internal data structures, including deleting the QIODevice object.
|
||||
*/
|
||||
virtual void removeConnection(QIODevice* device, quint64 clientID) = 0;
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtAbstractConnectionManager)
|
||||
};
|
||||
|
||||
#endif
|
@ -1,120 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTABSTRACTSIGNALSERIALIZER_H
|
||||
#define QXTABSTRACTSIGNALSERIALIZER_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QByteArray>
|
||||
|
||||
/*!
|
||||
* \class QxtAbstractSignalSerializer
|
||||
* \inmodule QxtCore
|
||||
* \brief The QxtAbstractSignalSerializer class provides an interface for classes that convert signals to a binary form.
|
||||
*
|
||||
* QxtAbstractSignalSerializer is an abstract interface used by, for example, QxtRPCService to convert signals into a
|
||||
* serialized binary format suitable for storing or transmitting over an I/O device.
|
||||
*
|
||||
* Qxt provides a default implementation in the form of QxtDataStreamSignalSerializer, which is generally sufficient for
|
||||
* most applications. Implement other subclasses of QxtAbstractSignalSerializer to allow QxtRPCService and similar tools
|
||||
* to integrate with existing protocols.
|
||||
*/
|
||||
|
||||
class QXT_CORE_EXPORT QxtAbstractSignalSerializer
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* The first half of QxtAbstractSignalSerializer::DeserializedData is the name of the deserialized signal. The
|
||||
* second half is an array of QVariants containing the parameters of the signal.
|
||||
*/
|
||||
typedef QPair<QString, QList<QVariant> > DeserializedData;
|
||||
|
||||
/*!
|
||||
* Destroys the QxtAbstractSignalSerializer.
|
||||
*/
|
||||
virtual ~QxtAbstractSignalSerializer() {}
|
||||
|
||||
/*!
|
||||
* Serializes a signal into a form suitable for sending to an I/O device.
|
||||
*/
|
||||
virtual QByteArray serialize(const QString& fn, const QVariant& p1 = QVariant(), const QVariant& p2 = QVariant(),
|
||||
const QVariant& p3 = QVariant(), const QVariant& p4 = QVariant(),
|
||||
const QVariant& p5 = QVariant(), const QVariant& p6 = QVariant(),
|
||||
const QVariant& p7 = QVariant(), const QVariant& p8 = QVariant()) const = 0;
|
||||
|
||||
/*!
|
||||
* Deserializes binary data into a signal name and a list of parameters. When implementing this function, be sure
|
||||
* to remove the processed portion of the data from the reference parameter.
|
||||
* Return QxtAbstractSignalSerializer::NoOp() if the deserialized data does not invoke a signal.
|
||||
* Return QxtAbstractSignalSerializer::ProtocolError() if the protocol has been violated and the connection should
|
||||
* be severed.
|
||||
*/
|
||||
virtual DeserializedData deserialize(QByteArray& data) = 0;
|
||||
|
||||
/*!
|
||||
* Indicates whether the data currently in the buffer can be deserialized.
|
||||
*/
|
||||
virtual bool canDeserialize(const QByteArray& buffer) const = 0;
|
||||
|
||||
/*!
|
||||
* Returns an object that indicates that the deserialized data does not invoke a signal.
|
||||
*/
|
||||
static inline DeserializedData NoOp()
|
||||
{
|
||||
static DeserializedData rv = qMakePair(QString(), QList<QVariant>());
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns an object that indicates that the deserialized data indicates a fatal protocol error.
|
||||
*/
|
||||
static inline DeserializedData ProtocolError()
|
||||
{
|
||||
static DeserializedData rv = qMakePair(QString(), QList<QVariant>() << QVariant());
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Checks to see if the provided object does not invoke a signal.
|
||||
*/
|
||||
static inline bool isNoOp(const DeserializedData& value)
|
||||
{
|
||||
return value.first.isEmpty() && value.second.isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Checks to see if the provided object indicates a fatal protocol error.
|
||||
*/
|
||||
static inline bool isProtocolError(const DeserializedData& value)
|
||||
{
|
||||
return value.first.isEmpty() && !value.second.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -1,80 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTALGORITHMS_H
|
||||
#define QXTALGORITHMS_H
|
||||
|
||||
template<typename InputIterator, typename LessThan>
|
||||
InputIterator qxtMinimum(InputIterator begin, InputIterator end, LessThan lessThan)
|
||||
{
|
||||
InputIterator iter = begin, rv = begin;
|
||||
while ((++iter) != end)
|
||||
{
|
||||
if (lessThan(*iter, *rv)) rv = iter;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
template<typename InputIterator>
|
||||
InputIterator qxtMinimum(InputIterator begin, InputIterator end)
|
||||
{
|
||||
InputIterator iter = begin, rv = begin;
|
||||
while ((++iter) != end)
|
||||
{
|
||||
if ((*iter) < (*rv)) rv = iter;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
typename Container::const_iterator qxtMinimum(const Container& container)
|
||||
{
|
||||
return qxtMinimum(container.begin(), container.end());
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename GreaterThan>
|
||||
InputIterator qxtMaximum(InputIterator begin, InputIterator end, GreaterThan greaterThan)
|
||||
{
|
||||
return qxtMinimum(begin, end, greaterThan);
|
||||
}
|
||||
|
||||
template<typename InputIterator>
|
||||
InputIterator qxtMaximum(InputIterator begin, InputIterator end)
|
||||
{
|
||||
InputIterator iter = begin, rv = begin;
|
||||
while ((++iter) != end)
|
||||
{
|
||||
if ((*iter) > (*rv)) rv = iter;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
typename Container::const_iterator qxtMaximum(const Container& container)
|
||||
{
|
||||
return qxtMinimum(container.begin(), container.end());
|
||||
}
|
||||
|
||||
#endif
|
@ -1,633 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTBOUNDCFUNCTION_H
|
||||
#define QXTBOUNDCFUNCTION_H
|
||||
|
||||
#include <qxtboundfunctionbase.h>
|
||||
#include <qxtmetatype.h>
|
||||
#include <qxtglobal.h>
|
||||
#include <QtDebug>
|
||||
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
|
||||
#define QXT_RETURN(fp) *reinterpret_cast<RETURN*>(returnValue.data()) = (*reinterpret_cast<FUNCTION>(fp))
|
||||
#define QXT_INVOKE(fp) (*reinterpret_cast<FUNCTION>(fp))
|
||||
#define QXT_PARAM(i) *reinterpret_cast<T ## i *>(p ## i .data())
|
||||
|
||||
template < typename RETURN, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void,
|
||||
typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void, typename T10 = void >
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9), QXT_PARAM(10));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, void, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)();
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)();
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3, T4);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9);
|
||||
bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template < typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void,
|
||||
typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void, typename T10 = void >
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9), QXT_PARAM(10));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<void, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)();
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)();
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, void, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3, T4);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, void, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3, T4, T5);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, void, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, void, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, T8, void, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, void> : public QxtGenericFunctionPointer
|
||||
{
|
||||
public:
|
||||
typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9);
|
||||
bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
QXT_10_UNUSED;
|
||||
QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
|
||||
};
|
||||
|
||||
template < typename RETURN = void, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void,
|
||||
typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void, typename T10 = void >
|
||||
class /*QXT_CORE_EXPORT*/ QxtBoundCFunction : public QxtBoundFunctionBase
|
||||
{
|
||||
public:
|
||||
QxtGenericFunctionPointer funcPtr;
|
||||
|
||||
QxtBoundCFunction(QObject* parent, QxtGenericFunctionPointer funcPointer, QGenericArgument* params[10], QByteArray types[10]) : QxtBoundFunctionBase(parent, params, types), funcPtr(funcPointer)
|
||||
{
|
||||
// initializers only, thanks to template magic
|
||||
}
|
||||
|
||||
virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument))
|
||||
{
|
||||
if (type != Qt::AutoConnection && type != Qt::DirectConnection)
|
||||
{
|
||||
qWarning() << "QxtBoundCFunction::invoke: Cannot invoke non-Qt functions using a queued connection";
|
||||
return false;
|
||||
}
|
||||
return reinterpret_cast<qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>*>(&funcPtr)->invoke(returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
class /*QXT_CORE_EXPORT*/ QxtBoundCFunction<void, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : public QxtBoundFunctionBase
|
||||
{
|
||||
public:
|
||||
QxtGenericFunctionPointer funcPtr;
|
||||
|
||||
QxtBoundCFunction(QObject* parent, QxtGenericFunctionPointer funcPointer, QGenericArgument* params[10], QByteArray types[10]) : QxtBoundFunctionBase(parent, params, types), funcPtr(funcPointer)
|
||||
{
|
||||
// initializers only, thanks to template magic
|
||||
}
|
||||
|
||||
virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument))
|
||||
{
|
||||
Q_UNUSED(returnValue);
|
||||
if (type != Qt::AutoConnection && type != Qt::DirectConnection)
|
||||
{
|
||||
qWarning() << "QxtBoundCFunction::invoke: Cannot invoke non-Qt functions using a queued connection";
|
||||
return false;
|
||||
}
|
||||
return reinterpret_cast<qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>*>(&funcPtr)->invoke(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
};
|
||||
|
||||
#undef QXT_RETURN
|
||||
#undef QXT_INVOKE
|
||||
#undef QXT_PARAM
|
||||
#endif
|
||||
|
||||
namespace QxtMetaObject
|
||||
{
|
||||
/*!
|
||||
* \relates QxtMetaObject
|
||||
* \sa QxtMetaObject::connect
|
||||
* \sa qxtFuncPtr
|
||||
* \sa QxtBoundFunction
|
||||
* \sa QXT_BIND
|
||||
*
|
||||
* Creates a binding to the provided C/C++ function using the provided parameter list.
|
||||
* Use the qxtFuncPtr function to wrap a bare function pointer for use in this function.
|
||||
* Use the Q_ARG macro to specify constant parameters, or use the QXT_BIND macro to
|
||||
* relay a parameter from a connected signal or passed via the QxtBoundFunction::invoke()
|
||||
* method.
|
||||
*
|
||||
* The first template parameter must match the return type of the function, or
|
||||
* void if the function does not return a value. The remaining template parameters must
|
||||
* match the types of the function's parameters. If any type does not match, this
|
||||
* function returns NULL.
|
||||
*
|
||||
* The returned QxtBoundFunction will not have a parent. Assigning a parent using
|
||||
* QObject::setParent() is strongly recommended to avoid memory leaks.
|
||||
*/
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QXT_IMPL_10ARGS(QGenericArgument))
|
||||
{
|
||||
// Make sure the template parameters make a function pointer equivalent to the one passed in
|
||||
if (funcPointer.typeName != typeid(typename qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::FUNCTION).name())
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: parameter list mismatch, check template arguments";
|
||||
return 0;
|
||||
}
|
||||
|
||||
QGenericArgument* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (args[i]->name() == 0) break; // done
|
||||
if (QByteArray(args[i]->name()) == "QxtBoundArgument")
|
||||
{
|
||||
Q_ASSERT_X((quintptr)(args[i]->data()) > 0 && (quintptr)(args[i]->data()) <= 10, "QXT_BIND", "invalid argument number");
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray types[10];
|
||||
types[0] = QxtMetaType<T1>::name();
|
||||
types[1] = QxtMetaType<T2>::name();
|
||||
types[2] = QxtMetaType<T3>::name();
|
||||
types[3] = QxtMetaType<T4>::name();
|
||||
types[4] = QxtMetaType<T5>::name();
|
||||
types[5] = QxtMetaType<T6>::name();
|
||||
types[6] = QxtMetaType<T7>::name();
|
||||
types[7] = QxtMetaType<T8>::name();
|
||||
types[8] = QxtMetaType<T9>::name();
|
||||
types[9] = QxtMetaType<T10>::name();
|
||||
|
||||
return new QxtBoundCFunction<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(0, funcPointer, args, types);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \relates QxtMetaObject
|
||||
* \sa QxtMetaObject::connect
|
||||
* \sa qxtFuncPtr
|
||||
* \sa QxtBoundFunction
|
||||
*
|
||||
* Creates a binding to the provided C/C++ function using the provided parameter list.
|
||||
* Use the qxtFuncPtr function to wrap a bare function pointer for use in this function.
|
||||
* The type of each argument is deduced from the type of the QVariant. This function
|
||||
* cannot bind positional arguments; see the overload using QGenericArgument.
|
||||
*
|
||||
* The first template parameter must match the return type of the function, or
|
||||
* void if the function does not return a value. The remaining template parameters must
|
||||
* match the types of the function's parameters. If any type does not match, this
|
||||
* function returns NULL.
|
||||
*
|
||||
* The returned QxtBoundFunction will not have a parent. Assigning a parent using
|
||||
* QObject::setParent() is strongly recommended to avoid memory leaks.
|
||||
*/
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QXT_IMPL_10ARGS(QVariant))
|
||||
{
|
||||
QVariant* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
|
||||
return QxtMetaObject::bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(funcPointer, QXT_VAR_ARG(1), QXT_VAR_ARG(2), QXT_VAR_ARG(3), QXT_VAR_ARG(4),
|
||||
QXT_VAR_ARG(5), QXT_VAR_ARG(6), QXT_VAR_ARG(7), QXT_VAR_ARG(8), QXT_VAR_ARG(9), QXT_VAR_ARG(10));
|
||||
}
|
||||
|
||||
// The following overloads exist because C++ doesn't support default parameters in function templates
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
template <typename RETURN>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer)
|
||||
{
|
||||
return bind<RETURN, void, void, void, void, void, void, void, void, void, void>(funcPointer,
|
||||
QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1)
|
||||
{
|
||||
return bind<RETURN, T1, void, void, void, void, void, void, void, void, void>(funcPointer,
|
||||
p1, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2)
|
||||
{
|
||||
return bind<RETURN, T1, T2, void, void, void, void, void, void, void, void>(funcPointer,
|
||||
p1, p2, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, void, void, void, void, void, void, void>(funcPointer,
|
||||
p1, p2, p3, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, void, void, void, void, void, void>(funcPointer,
|
||||
p1, p2, p3, p4, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, void, void, void, void, void>(funcPointer,
|
||||
p1, p2, p3, p4, p5, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5, QGenericArgument p6)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, void, void, void, void>(funcPointer,
|
||||
p1, p2, p3, p4, p5, p6, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5, QGenericArgument p6, QGenericArgument p7)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, void, void, void>(funcPointer,
|
||||
p1, p2, p3, p4, p5, p6, p7, QGenericArgument(), QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5,
|
||||
QGenericArgument p6, QGenericArgument p7, QGenericArgument p8)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, QGenericArgument(), QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5,
|
||||
QGenericArgument p6, QGenericArgument p7, QGenericArgument p8, QGenericArgument p9)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, p9, QGenericArgument());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1)
|
||||
{
|
||||
return bind<RETURN, T1, void, void, void, void, void, void, void, void, void>(funcPointer, p1, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2)
|
||||
{
|
||||
return bind<RETURN, T1, T2, void, void, void, void, void, void, void, void>(funcPointer, p1, p2, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, void, void, void, void, void, void, void>(funcPointer, p1, p2, p3, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, void, void, void, void, void, void>(funcPointer, p1, p2, p3, p4, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, void, void, void, void, void>(funcPointer, p1, p2, p3, p4, p5, QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, void, void, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, QVariant(), QVariant(), QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6, QVariant p7)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, void, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, QVariant(), QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6, QVariant p7, QVariant p8)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, QVariant(), QVariant());
|
||||
}
|
||||
|
||||
template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6, QVariant p7, QVariant p8, QVariant p9)
|
||||
{
|
||||
return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, p9, QVariant());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
@ -1,264 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTBOUNDFUNCTION_H
|
||||
#define QXTBOUNDFUNCTION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaObject>
|
||||
#include <QGenericArgument>
|
||||
#include <qxtmetaobject.h>
|
||||
#include <qxtnull.h>
|
||||
#include <QThread>
|
||||
#include <QtDebug>
|
||||
|
||||
/*!
|
||||
\class QxtBoundFunction
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief Binds parameters to a function call
|
||||
|
||||
* A bound function is very similar to what the C++ FAQ Lite refers to as "functionoids."
|
||||
* (http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.10)
|
||||
* It is similar in use to a function pointer, but allows any or all parameters to be
|
||||
* pre-filled with constant values. The remaining parameters are specified when the
|
||||
* function is invoked, for instance, by a Qt signal connection.
|
||||
*
|
||||
* By far, the most common expected use is to provide a parameter to a slot when the
|
||||
* signal doesn't have offer one. Many developers new to Qt try to write code like this:
|
||||
* \code
|
||||
* connect(button, SIGNAL(clicked()), lineEdit, SLOT(setText("Hello, world")));
|
||||
* \endcode
|
||||
* Experienced Qt developers will immediately spot the flaw here. The typical solution
|
||||
* is to create a short, one-line wrapper slot that invokes the desired function. Some
|
||||
* clever developers may even use QSignalMapper to handle slots that only need one
|
||||
* int or QString parameter.
|
||||
*
|
||||
* QxtBoundFunction enables the previous connect statement to be written like this:
|
||||
* \code
|
||||
* connect(button, SIGNAL(clicked()), QxtMetaObject::bind(lineEdit, SLOT(setText(QString)), Q_ARG(QString, "Hello, world!")));
|
||||
* \code
|
||||
* This accomplishes the same result without having to create a new slot, or worse,
|
||||
* an entire object, just to pass a constant value.
|
||||
*
|
||||
* Additionally, through the use of the QXT_BIND macro, parameters from the signal
|
||||
* can be rearranged, skipped, or passed alongside constant arguments provided
|
||||
* with the Q_ARG macro. This can be used to provide stateful callbacks to a
|
||||
* generic function, for example.
|
||||
*
|
||||
* Many kinds of functions can be bound. The most common binding applies to
|
||||
* Qt signals and slots, but standard C/C++ functions can be bound as well.
|
||||
* Future development may add the ability to bind to C++ member functions,
|
||||
* and developers can make custom QxtBoundFunction subclasses for even more
|
||||
* flexibility if necessary.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class QXT_CORE_EXPORT QxtBoundFunction : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/*!
|
||||
* Invokes the bound function and returns a value.
|
||||
*
|
||||
* The template parameter should be the return type of the invoked function. This overload accepts
|
||||
* QVariant parameters and will guess the data type of each parameter based on the type of the QVariant.
|
||||
*/
|
||||
template <class T>
|
||||
inline QxtNullable<T> invoke(QXT_PROTO_10ARGS(QVariant))
|
||||
{
|
||||
if (!parent() || QThread::currentThread() == parent()->thread())
|
||||
return invoke<T>(Qt::DirectConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
#if QT_VERSION >= 0x040300
|
||||
return invoke<T>(Qt::BlockingQueuedConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
#else
|
||||
qWarning() << "QxtBoundFunction::invoke: Cannot return a value using a queued connection";
|
||||
return QxtNull();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Invokes the bound function and returns a value.
|
||||
*
|
||||
* The template parameter should be the return type of the invoked function. This overload accepts
|
||||
* QGenericArgument parameters, expressed using the Q_ARG() macro.
|
||||
*/
|
||||
template <class T>
|
||||
QxtNullable<T> invoke(Qt::ConnectionType type, QVariant p1, QXT_PROTO_9ARGS(QVariant))
|
||||
{
|
||||
if (type == Qt::QueuedConnection)
|
||||
{
|
||||
qWarning() << "QxtBoundFunction::invoke: Cannot return a value using a queued connection";
|
||||
return QxtNull();
|
||||
}
|
||||
T retval;
|
||||
// I know this is a totally ugly function call
|
||||
if (invoke(type, QGenericReturnArgument(qVariantFromValue<T>(*reinterpret_cast<T*>(0)).typeName(), reinterpret_cast<void*>(&retval)),
|
||||
p1, p2, p3, p4, p5, p6, p7, p8, p9, p10))
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QxtNull();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Invokes the bound function, discarding the return value.
|
||||
*
|
||||
* This overload accepts QVariant parameters and will guess the data type of each
|
||||
* parameter based on the type of the QVariant.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
inline bool invoke(QVariant p1, QXT_PROTO_9ARGS(QVariant))
|
||||
{
|
||||
return invoke(Qt::AutoConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
/*!
|
||||
* Invokes the bound function, discarding the return value.
|
||||
*
|
||||
* This overload accepts QVariant parameters and will guess the data type of each
|
||||
* parameter based on the type of the QVariant. It also allows you to specify the
|
||||
* connection type, allowing the bound function to be invoked across threads using
|
||||
* the Qt event loop.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
bool invoke(Qt::ConnectionType, QVariant p1, QXT_PROTO_9ARGS(QVariant));
|
||||
|
||||
/*!
|
||||
* Invokes the bound function, discarding the return value.
|
||||
*
|
||||
* This overload accepts QGenericArgument parameters, expressed using the Q_ARG()
|
||||
* macro.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
inline bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
return invoke(Qt::AutoConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
/*!
|
||||
* Invokes the bound function, discarding the return value.
|
||||
*
|
||||
* This overload accepts QGenericArgument parameters, expressed using the Q_ARG()
|
||||
* macro. It also allows you to specify the connection type, allowing the bound
|
||||
* function to be invoked across threads using the Qt event loop.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
inline bool invoke(Qt::ConnectionType type, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
return invoke(type, QGenericReturnArgument(), p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Invokes the bound function and assigns the return value to a parameter passed by reference.
|
||||
*
|
||||
* Use the Q_RETURN_ARG() macro to pass a reference to an assignable object of the function's
|
||||
* return type. When the function completes, its return value will be stored in that object.
|
||||
*
|
||||
* This overload accepts QVariant parameters and will guess the data type of each
|
||||
* parameter based on the type of the QVariant.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
inline bool invoke(QGenericReturnArgument returnValue, QVariant p1, QXT_PROTO_9ARGS(QVariant))
|
||||
{
|
||||
return invoke(Qt::AutoConnection, returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
/*!
|
||||
* Invokes the bound function and assigns the return value to a parameter passed by reference.
|
||||
*
|
||||
* Use the Q_RETURN_ARG() macro to pass a reference to an assignable object of the function's
|
||||
* return type. When the function completes, its return value will be stored in that object.
|
||||
*
|
||||
* This overload accepts QVariant parameters and will guess the data type of each
|
||||
* parameter based on the type of the QVariant. It also allows you to specify the
|
||||
* connection type, allowing the bound function to be invoked across threads using
|
||||
* the Qt event loop.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
bool invoke(Qt::ConnectionType type, QGenericReturnArgument returnValue, QVariant p1, QXT_PROTO_9ARGS(QVariant));
|
||||
|
||||
/*!
|
||||
* Invokes the bound function and assigns the return value to a parameter passed by reference.
|
||||
*
|
||||
* Use the Q_RETURN_ARG() macro to pass a reference to an assignable object of the function's
|
||||
* return type. When the function completes, its return value will be stored in that object.
|
||||
*
|
||||
* This overload accepts QGenericArgument parameters, expressed using the Q_ARG()
|
||||
* macro.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
inline bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
|
||||
{
|
||||
return invoke(Qt::AutoConnection, returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
/*!
|
||||
* Invokes the bound function and assigns the return value to a parameter passed by reference.
|
||||
*
|
||||
* Use the Q_RETURN_ARG() macro to pass a reference to an assignable object of the function's
|
||||
* return type. When the function completes, its return value will be stored in that object.
|
||||
*
|
||||
* This overload accepts QGenericArgument parameters, expressed using the Q_ARG()
|
||||
* macro. It also allows you to specify the connection type, allowing the bound
|
||||
* function to be invoked across threads using the Qt event loop.
|
||||
*
|
||||
* This function returns true if the invocation was successful, otherwise it
|
||||
* returns false.
|
||||
*/
|
||||
bool invoke(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument));
|
||||
|
||||
protected:
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
QxtBoundFunction(QObject* parent = 0);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Performs the work of invoking the bound function.
|
||||
*
|
||||
* This function is pure virtual. The various QxtMetaObject::bind() functions return opaque subclasses
|
||||
* of QxtBoundFunction. If you wish to create a new kind of bound function, reimplement this function to
|
||||
* perform the invocation and assign the function's return value, if any, to the returnValue parameter.
|
||||
*
|
||||
* This function should return true if the invocation is successful and false if an error occurs.
|
||||
*/
|
||||
virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument)) = 0;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,61 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
// This file exists for the convenience of QxtBoundCFunction.
|
||||
// It is not part of the public API and is subject to change.
|
||||
//
|
||||
// We mean it.
|
||||
|
||||
#ifndef QXTBOUNDFUNCTIONBASE_H
|
||||
#define QXTBOUNDFUNCTIONBASE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaObject>
|
||||
#include <QGenericArgument>
|
||||
#include <qxtmetaobject.h>
|
||||
#include <qxtboundfunction.h>
|
||||
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
|
||||
#define QXT_10_UNUSED Q_UNUSED(p1) Q_UNUSED(p2) Q_UNUSED(p3) Q_UNUSED(p4) Q_UNUSED(p5) Q_UNUSED(p6) Q_UNUSED(p7) Q_UNUSED(p8) Q_UNUSED(p9) Q_UNUSED(p10)
|
||||
|
||||
class QXT_CORE_EXPORT QxtBoundFunctionBase : public QxtBoundFunction
|
||||
{
|
||||
public:
|
||||
QByteArray bindTypes[10];
|
||||
QGenericArgument arg[10], p[10];
|
||||
void* data[10];
|
||||
|
||||
QxtBoundFunctionBase(QObject* parent, QGenericArgument* params[10], QByteArray types[10]);
|
||||
virtual ~QxtBoundFunctionBase();
|
||||
|
||||
int qt_metacall(QMetaObject::Call _c, int _id, void **_a);
|
||||
bool invokeBase(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument));
|
||||
};
|
||||
|
||||
#define QXT_ARG(i) ((argCount>i)?QGenericArgument(p ## i .typeName(), p ## i .constData()):QGenericArgument())
|
||||
#define QXT_VAR_ARG(i) (p ## i .isValid())?QGenericArgument(p ## i .typeName(), p ## i .constData()):QGenericArgument()
|
||||
#endif
|
||||
#endif
|
@ -1,914 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtcommandoptions.h"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QIODevice>
|
||||
#include <QtDebug>
|
||||
#include <QDir>
|
||||
|
||||
/*!
|
||||
\class QxtCommandOptions
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtCommandOptions class is a Parser for command-line options
|
||||
|
||||
This class is used by applications that need to accept command-line arguments. It can
|
||||
also automatically generate help text, which keeps it from accidentally falling out of
|
||||
sync with the supported options, and it can produce warnings for common errors.
|
||||
|
||||
It accepts Windows-style ("/option"), UNIX-style ("-option"), and GNU-style
|
||||
("--option") options. By default, QxtCommandOptions uses Windows-style options
|
||||
(QxtCommandOptions::Slash) on Windows and GNU-style options (QxtCommandOptions::DoubleDash)
|
||||
on UNIX and Mac. When using GNU-style options, single-character option names only
|
||||
require a single leading dash and can be grouped together, for example, "-abc".
|
||||
|
||||
Any parameter that does not start with the option prefix is considered a positional
|
||||
parameter. Most applications treat positional parameters as filenames. When using
|
||||
GNU- or UNIX-style options, use a double dash ("--") alone to force the remaining
|
||||
parameters to be interpreted as positional parameters.
|
||||
|
||||
To use QxtCommandOptions, first add the supported options using the add() and alias()
|
||||
methods, then process the command line using the parse() method, and finally retrieve
|
||||
the processed options using the positional(), count(), value() and/or parameters()
|
||||
methods.
|
||||
|
||||
Mutually-exclusive options can be specified by using the \a group parameter to add().
|
||||
Only one option in a group will be accepted on the command line; if multiple options
|
||||
are provided, only the last one takes effect.
|
||||
|
||||
Some options may accept an optional or required parameter. Depending on the value
|
||||
of the paramStyle() property, the parameter may be separated from the option by
|
||||
an equals sign ("/option=value") or by a space ("-option value"). By default,
|
||||
Windows uses an equals sign and UNIX and Mac accept both an equals sign and a
|
||||
space. Optional parameters always require an equals sign. Note that, when using
|
||||
GNU-style options, single-character options cannot have optional parameters.
|
||||
|
||||
A simple archiving application might use code similar to this:
|
||||
\code
|
||||
QxtCommandOptions options;
|
||||
options.add("compress", "create a new archive");
|
||||
options.alias("compress", "c");
|
||||
options.add("extract", "extract files from an archive");
|
||||
options.alias("extract", "x");
|
||||
options.add("level", "set the compression level (0-9)", QxtCommandOptions::Required);
|
||||
options.alias("level", "l");
|
||||
options.add("verbose", "show more information about the process; specify twice for more detail", QxtCommandOptions::AllowMultiple);
|
||||
options.alias("verbose", "v");
|
||||
options.add("help", "show this help text");
|
||||
options.alias("help", "h");
|
||||
options.parse(QCoreApplication::arguments());
|
||||
if(options.count("help") || options.showUnrecognizedWarning()) {
|
||||
options.showUsage();
|
||||
return -1;
|
||||
}
|
||||
bool verbose = options.count("verbose");
|
||||
int level = 5;
|
||||
if(options.count("level")) {
|
||||
level = options.value("level").toInt();
|
||||
}
|
||||
\endcode
|
||||
|
||||
\sa QCoreApplication::arguments()
|
||||
*/
|
||||
|
||||
static const char* qxt_qt_options[] =
|
||||
{
|
||||
"=style", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the application GUI style"),
|
||||
"=stylesheet", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the application stylesheet"),
|
||||
"=session", QT_TRANSLATE_NOOP("QxtCommandOptions", "restores the application from an earlier session"),
|
||||
"widgetcount", QT_TRANSLATE_NOOP("QxtCommandOptions", "displays debugging information about widgets"),
|
||||
"reverse", QT_TRANSLATE_NOOP("QxtCommandOptions", "use right-to-left layout"),
|
||||
#ifdef QT_DEBUG
|
||||
"nograb", QT_TRANSLATE_NOOP("QxtCommandOptions", "never grab the mouse or keyboard"),
|
||||
#endif
|
||||
#if defined(QT_DEBUG) && defined(Q_WS_X11)
|
||||
"dograb", QT_TRANSLATE_NOOP("QxtCommandOptions", "grab the mouse/keyboard even in a debugger"),
|
||||
"sync", QT_TRANSLATE_NOOP("QxtCommandOptions", "run in synchronous mode for debugging"),
|
||||
#endif
|
||||
#ifdef Q_WS_WIN
|
||||
"direct3d", QT_TRANSLATE_NOOP("QxtCommandOptions", "use Direct3D by default"),
|
||||
#endif
|
||||
#ifdef Q_WS_X11
|
||||
"=display", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the X11 display"),
|
||||
"=geometry", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the geometry of the first window"),
|
||||
"=font", "",
|
||||
"=fn", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the default font"),
|
||||
"=background", "",
|
||||
"=bg", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the default background color"),
|
||||
"=foreground", "",
|
||||
"=fg", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the default foreground color"),
|
||||
"=button", "",
|
||||
"=btn", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the default button color"),
|
||||
"=name", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the application name"),
|
||||
"=title", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the application title"),
|
||||
"=visual", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the X11 visual type"),
|
||||
"=ncols", QT_TRANSLATE_NOOP("QxtCommandOptions", "limit the number of colors on an 8-bit display"),
|
||||
"cmap", QT_TRANSLATE_NOOP("QxtCommandOptions", "use a private color map"),
|
||||
"=im", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the input method server"),
|
||||
"noxim", QT_TRANSLATE_NOOP("QxtCommandOptions", "disable the X Input Method"),
|
||||
"=inputstyle", QT_TRANSLATE_NOOP("QxtCommandOptions", "sets the style used by the input method"),
|
||||
#endif
|
||||
0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* This function is used to check to see if a parameter
|
||||
* is used by Qt.
|
||||
*/
|
||||
static int isQtOption(const QString& param)
|
||||
{
|
||||
// Qt options all start with a single dash regardless of platform
|
||||
if (param.length() < 2) return 0;
|
||||
if (param[0] != '-') return 0;
|
||||
if (param[1] == '-') return 0;
|
||||
#ifdef Q_OS_MAC
|
||||
if (param.left(5) == "-psn_") return 1;
|
||||
#endif
|
||||
QString name = param.mid(1), value;
|
||||
bool hasEquals;
|
||||
|
||||
// Separate the option and the value, if present
|
||||
if (name.indexOf('=') != -1)
|
||||
{
|
||||
value = param.section('=', 1);
|
||||
name = param.section('=', 0, 0);
|
||||
hasEquals = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "";
|
||||
hasEquals = false;
|
||||
}
|
||||
|
||||
const char* option;
|
||||
bool optionHasValue;
|
||||
for (int i = 0; qxt_qt_options[i]; i += 2)
|
||||
{
|
||||
option = qxt_qt_options[i];
|
||||
// In the table above, options that require parameters start with =
|
||||
if (option[0] == '=')
|
||||
{
|
||||
optionHasValue = true;
|
||||
option = option + 1; // pointer math to skip =
|
||||
}
|
||||
else
|
||||
{
|
||||
optionHasValue = false;
|
||||
}
|
||||
|
||||
// The return value indicates how many parameters to skip
|
||||
if (name == option)
|
||||
{
|
||||
if (optionHasValue) return 2;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Storage structure for option data
|
||||
struct QxtCommandOption
|
||||
{
|
||||
QStringList names; // aliases accepted at the command line
|
||||
QString canonicalName; // name used for alias()/count()/value()
|
||||
QString desc; // documentation string
|
||||
QStringList values; // values passed on command line
|
||||
QxtCommandOptions::ParamTypes paramType; // flags
|
||||
quint16 group; // mutual exclusion group
|
||||
};
|
||||
|
||||
class QxtCommandOptionsPrivate : public QxtPrivate<QxtCommandOptions>
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(QxtCommandOptions)
|
||||
public:
|
||||
QXT_DECLARE_PUBLIC(QxtCommandOptions)
|
||||
|
||||
QList<QxtCommandOption> options;
|
||||
QHash<QString, QxtCommandOption*> lookup; // cache structure to simplify processing
|
||||
QHash<int, QList<QxtCommandOption*> > groups; // cache structure to simplify processing
|
||||
QxtCommandOptions::FlagStyle flagStyle;
|
||||
QxtCommandOptions::ParamStyle paramStyle;
|
||||
QStringList positional; // prefixless parameters
|
||||
QStringList unrecognized; // prefixed parameters not in recognized options
|
||||
QStringList missingParams; // parameters with required values missing
|
||||
int screenWidth;
|
||||
bool parsed;
|
||||
|
||||
QxtCommandOption* findOption(const QString& name);
|
||||
const QxtCommandOption* findOption(const QString& name) const;
|
||||
void setOption(QxtCommandOption* option, const QString& value = QString());
|
||||
void parse(const QStringList& params);
|
||||
};
|
||||
|
||||
/* Looks up an option in qxt_d().options by canonical name */
|
||||
QxtCommandOption* QxtCommandOptionsPrivate::findOption(const QString& name)
|
||||
{
|
||||
// The backwards loop will find what we're looking for more quickly in the
|
||||
// typical use case, where you add aliases immediately after adding the option.
|
||||
for (int i = options.count() - 1; i >= 0; --i)
|
||||
{
|
||||
if (options[i].canonicalName == name) return &options[i];
|
||||
}
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("option \"%1\" not found").arg(name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Looks up an option in qxt_d().options by canonical name
|
||||
* This is a const overload for const functions */
|
||||
const QxtCommandOption* QxtCommandOptionsPrivate::findOption(const QString& name) const
|
||||
{
|
||||
// The backwards loop will find what we're looking for more quickly in the
|
||||
// typical use case, where you add aliases immediately after adding the option.
|
||||
for (int i = options.count() - 1; i >= 0; --i)
|
||||
{
|
||||
if (options[i].canonicalName == name) return &(options.at(i));
|
||||
}
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("option \"%1\" not found").arg(name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Constructs a QxtCommandOptions object.
|
||||
*/
|
||||
QxtCommandOptions::QxtCommandOptions()
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtCommandOptions);
|
||||
qxt_d().screenWidth = 80;
|
||||
qxt_d().parsed = false;
|
||||
#ifdef Q_OS_WIN
|
||||
setFlagStyle(Slash);
|
||||
setParamStyle(Equals);
|
||||
#else
|
||||
setFlagStyle(DoubleDash);
|
||||
setParamStyle(SpaceAndEquals);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Sets which prefix is used to identify options. The default value is Slash on Windows
|
||||
* and DoubleDash on all other platforms.
|
||||
*
|
||||
* Note that Qt's built-in options (see QApplication) always use a single dash,
|
||||
* regardless of this setting.
|
||||
*/
|
||||
void QxtCommandOptions::setFlagStyle(FlagStyle style)
|
||||
{
|
||||
qxt_d().flagStyle = style;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Gets which prefix is used to identify options.
|
||||
*/
|
||||
QxtCommandOptions::FlagStyle QxtCommandOptions::flagStyle() const
|
||||
{
|
||||
return qxt_d().flagStyle;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Sets which value separator is used for options that accept parameters.
|
||||
* The default value is Equals on Windows and SpaceAndEquals on all other
|
||||
* platforms.
|
||||
*
|
||||
* Single-letter options with optional parameters in DoubleDash mode
|
||||
* always use an equals sign, regardless of this setting.
|
||||
*
|
||||
* Qt's built-in options always behave as SpaceAndEquals, regardless of
|
||||
* this setting.
|
||||
*/
|
||||
void QxtCommandOptions::setParamStyle(ParamStyle style)
|
||||
{
|
||||
qxt_d().paramStyle = style;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Sets which value separator is used for options that accept parameters.
|
||||
*/
|
||||
QxtCommandOptions::ParamStyle QxtCommandOptions::paramStyle() const
|
||||
{
|
||||
return qxt_d().paramStyle;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Sets the width of the screen, in characters. This is used for word-wrapping
|
||||
* the automatically-generated help text to the size of the screen. The default
|
||||
* value is 80 characters. Pass 0 to disable word-wrapping.
|
||||
*/
|
||||
void QxtCommandOptions::setScreenWidth(quint16 width)
|
||||
{
|
||||
qxt_d().screenWidth = width;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Gets the width of the screen, in characters.
|
||||
*/
|
||||
quint16 QxtCommandOptions::screenWidth() const
|
||||
{
|
||||
return qxt_d().screenWidth;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Adds a section separator. Section separators are only used in generating
|
||||
* help text, and can be used to visually separate related groups of
|
||||
* options.
|
||||
*/
|
||||
void QxtCommandOptions::addSection(const QString& name)
|
||||
{
|
||||
QxtCommandOption option;
|
||||
option.canonicalName.clear();
|
||||
option.desc = name;
|
||||
qxt_d().options.append(option);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Adds an option to the parser.
|
||||
*
|
||||
* The name parameter defines the name that will be used by the alias(),
|
||||
* count(), value(), and parameters() methods. Additional names for the
|
||||
* same option can be defined using the alias() method.
|
||||
*
|
||||
* The group parameter, if used, defines a set of mutually-exclusive options.
|
||||
* If more than one option in the same group is passed on the command line,
|
||||
* only the last one takes effect.
|
||||
*/
|
||||
void QxtCommandOptions::add(const QString& name, const QString& desc, ParamTypes paramType, int group)
|
||||
{
|
||||
QxtCommandOption option;
|
||||
option.canonicalName = name;
|
||||
option.desc = desc;
|
||||
option.paramType = paramType;
|
||||
option.group = group;
|
||||
qxt_d().options.append(option);
|
||||
if (group != -1)
|
||||
qxt_d().groups[group].append(&(qxt_d().options.last()));
|
||||
// Connect the canonical name to a usable name
|
||||
alias(name, name);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Provides an alias for an option. An alias is another name for the option that can be
|
||||
* given on the command line. Aliases cannot be used as parameters to alias(), count()
|
||||
* or value() nor can single-letter aliases be created for options with an optional value.
|
||||
*
|
||||
* The from parameter must be a name has previously been added with the add() method.
|
||||
*/
|
||||
void QxtCommandOptions::alias(const QString& from, const QString& to)
|
||||
{
|
||||
QxtCommandOption* option = qxt_d().findOption(from);
|
||||
if (!option) return; // findOption outputs the warning
|
||||
option->names.append(to);
|
||||
qxt_d().lookup[to] = option;
|
||||
if (option->paramType & ValueOptional && qxt_d().flagStyle == DoubleDash && to.length() == 1)
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("Short options cannot have optional parameters"));
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the positional parameters from the command line, that is, the arguments that
|
||||
* do not begin with the option prefix.
|
||||
*
|
||||
* \sa flagStyle()
|
||||
*/
|
||||
QStringList QxtCommandOptions::positional() const
|
||||
{
|
||||
if (!qxt_d().parsed)
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("positional() called before parse()"));
|
||||
return qxt_d().positional;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the options that could not be parsed.
|
||||
*
|
||||
* An argument is unrecognized if it begins with the option prefix but was never
|
||||
* defined using the add() or alias() methods, or if it requires a value but the
|
||||
* user did not provide one.
|
||||
*/
|
||||
QStringList QxtCommandOptions::unrecognized() const
|
||||
{
|
||||
if (!qxt_d().parsed)
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("unrecognized() called before parse()"));
|
||||
return qxt_d().unrecognized + qxt_d().missingParams;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the number of times an option was passed on the command line.
|
||||
*
|
||||
* This function will only return 0 or 1 for options that were not created with the
|
||||
* QxtCommandOptions::AllowMultiple flag set.
|
||||
*/
|
||||
int QxtCommandOptions::count(const QString& name) const
|
||||
{
|
||||
if (!qxt_d().parsed)
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("count() called before parse()"));
|
||||
const QxtCommandOption* option = qxt_d().findOption(name);
|
||||
if (!option) return 0; // findOption outputs the warning
|
||||
return option->values.count();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the value or values for an option passed on the command line.
|
||||
*
|
||||
* If the option was not passed on the command line, this function returns a null QVariant.
|
||||
* If the option was created with the QxtCommandOptions::AllowMultiple flag, and the option
|
||||
* was passed more than once, this function returns a QStringList containing the values.
|
||||
* Otherwise, this function returns the last (or only) value given to the option on the
|
||||
* command line. When an option allowing an optional value is provided on the command
|
||||
* line and for which no value is provided, an empty but non-null QString will be returned
|
||||
* in the QVariant.
|
||||
*/
|
||||
QVariant QxtCommandOptions::value(const QString& name) const
|
||||
{
|
||||
if (!qxt_d().parsed)
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("value() called before parse()"));
|
||||
const QxtCommandOption* option = qxt_d().findOption(name);
|
||||
if (!option) return QVariant(); // findOption outputs the warning
|
||||
int ct = option->values.count();
|
||||
if (ct == 0) return QVariant();
|
||||
if (ct == 1) return option->values.first();
|
||||
return option->values;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns all of the recognized options passed on the command line.
|
||||
*/
|
||||
QMultiHash<QString, QVariant> QxtCommandOptions::parameters() const
|
||||
{
|
||||
if (!qxt_d().parsed)
|
||||
qWarning() << qPrintable(QString("QxtCommandOptions: ") + tr("parameters() called before parse()"));
|
||||
QMultiHash<QString, QVariant> params;
|
||||
int ct;
|
||||
foreach(const QxtCommandOption& option, qxt_d().options)
|
||||
{
|
||||
ct = option.values.count();
|
||||
if (!ct)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (!(option.paramType & (ValueOptional | ValueRequired)))
|
||||
{
|
||||
// Valueless options are really a true/false flag
|
||||
params.insert(option.canonicalName, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(const QVariant& value, option.values)
|
||||
params.insert(option.canonicalName, value);
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/*!
|
||||
* This is an overloaded member function, provided for convenience.
|
||||
*
|
||||
* Process a set of command-line options. This overload accepts a number of
|
||||
* arguments and a pointer to the list of arguments.
|
||||
*
|
||||
* Note that parse() may be invoked multiple times to handle arguments from
|
||||
* more than one source.
|
||||
*/
|
||||
void QxtCommandOptions::parse(int argc, char** argv)
|
||||
{
|
||||
QStringList args;
|
||||
for (int i = 0; i < argc; i++)
|
||||
args << argv[i];
|
||||
parse(args);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Process a set of command-line options. This overload accepts a QStringList
|
||||
* containing the command-line options, such as the one returned by
|
||||
* QCoreApplication::arguments().
|
||||
*
|
||||
* Note that parse() may be invoked multiple times to handle arguments from
|
||||
* more than one source.
|
||||
*
|
||||
* \sa QCoreApplication::arguments()
|
||||
*/
|
||||
void QxtCommandOptions::parse(QStringList params)
|
||||
{
|
||||
qxt_d().parse(params);
|
||||
qxt_d().parsed = true;
|
||||
}
|
||||
|
||||
/* Update the internal data structures with an option from the command line. */
|
||||
void QxtCommandOptionsPrivate::setOption(QxtCommandOption* option, const QString& value)
|
||||
{
|
||||
if (groups.contains(option->group))
|
||||
{
|
||||
// Clear mutually-exclusive options
|
||||
QList<QxtCommandOption*>& others = groups[option->group];
|
||||
foreach(QxtCommandOption* other, others)
|
||||
{
|
||||
if (other != option) other->values.clear();
|
||||
}
|
||||
}
|
||||
// Clear all previous values if multiples are not accepted
|
||||
if (!(option->paramType & QxtCommandOptions::AllowMultiple))
|
||||
option->values.clear();
|
||||
option->values.append(value);
|
||||
}
|
||||
|
||||
/* Do the work of parsing the command line */
|
||||
void QxtCommandOptionsPrivate::parse(const QStringList& params)
|
||||
{
|
||||
int pos = 1; // 0 is the application name
|
||||
int ct = params.count();
|
||||
int skip = 0;
|
||||
bool endFlags = false;
|
||||
bool notUnrecognized, hasEquals;
|
||||
QString name, param, value;
|
||||
|
||||
while (pos < ct)
|
||||
{
|
||||
// Ignore Qt built-in options
|
||||
while ((skip = isQtOption(params[pos])))
|
||||
{
|
||||
pos += skip;
|
||||
if (pos >= ct)
|
||||
return;
|
||||
}
|
||||
|
||||
param = params[pos];
|
||||
pos++;
|
||||
|
||||
if (!endFlags && ((flagStyle == QxtCommandOptions::Slash && param[0] == '/') ||
|
||||
(flagStyle != QxtCommandOptions::Slash && param[0] == '-')))
|
||||
{
|
||||
// tagged argument
|
||||
if (param.length() == 1)
|
||||
{
|
||||
// "-" or "/" alone can't possibly match a flag, so use positional.
|
||||
positional.append(param);
|
||||
continue;
|
||||
}
|
||||
notUnrecognized = false;
|
||||
|
||||
if (flagStyle != QxtCommandOptions::Slash && param == "--")
|
||||
{
|
||||
// End of parameters flag
|
||||
endFlags = true;
|
||||
}
|
||||
else if (flagStyle == QxtCommandOptions::DoubleDash && param[1] != '-')
|
||||
{
|
||||
// Handle short-form options
|
||||
int len = param.length();
|
||||
QxtCommandOption* option;
|
||||
for (int i = 1; i < len; i++)
|
||||
{
|
||||
QString ch(param[i]);
|
||||
if (ch == "-")
|
||||
{
|
||||
endFlags = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
option = lookup.value(ch, 0);
|
||||
if (!option)
|
||||
{
|
||||
// single-letter flag has no known equivalent
|
||||
unrecognized.append(QString("-") + param[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option->paramType & QxtCommandOptions::ValueRequired)
|
||||
{
|
||||
// Check for required parameters
|
||||
// Short options can't have optional parameters
|
||||
if (pos >= params.count())
|
||||
{
|
||||
missingParams.append(param);
|
||||
break;
|
||||
}
|
||||
value = params[pos];
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
setOption(option, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Break apart a value
|
||||
if (param.indexOf('=') != -1)
|
||||
{
|
||||
value = param.section('=', 1);
|
||||
param = param.section('=', 0, 0);
|
||||
hasEquals = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "";
|
||||
hasEquals = false;
|
||||
}
|
||||
|
||||
if (flagStyle == QxtCommandOptions::DoubleDash)
|
||||
name = param.mid(2);
|
||||
else
|
||||
name = param.mid(1);
|
||||
|
||||
QxtCommandOption* option = lookup.value(name, 0);
|
||||
if (!option)
|
||||
{
|
||||
unrecognized.append(param);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option->paramType & QxtCommandOptions::ValueRequired && !hasEquals)
|
||||
{
|
||||
// Check for parameters
|
||||
if (pos >= params.count())
|
||||
{
|
||||
missingParams.append(param);
|
||||
break;
|
||||
}
|
||||
value = params[pos];
|
||||
pos++;
|
||||
}
|
||||
else if ((paramStyle & QxtCommandOptions::Space)
|
||||
&& (option->paramType & QxtCommandOptions::ValueOptional)
|
||||
&& !hasEquals)
|
||||
{
|
||||
if (pos < params.count())
|
||||
{
|
||||
if (!((flagStyle == QxtCommandOptions::Slash && params.at(pos)[0] == '/') ||
|
||||
(flagStyle != QxtCommandOptions::Slash && params.at(pos)[0] == '-')))
|
||||
{
|
||||
value = params[pos];
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setOption(option, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// positional argument
|
||||
positional.append(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* This is an overloaded member function, provided for convenience.
|
||||
*
|
||||
* Outputs a warning about any unrecognized options to the provided device, or
|
||||
* standard error by default. The device must already be opened for writing.
|
||||
*
|
||||
* This function returns true if any warnings were output, or false otherwise.
|
||||
*
|
||||
* If a QCoreApplication or a subclass of QCoreApplication has been instantiated,
|
||||
* this function uses QCoreApplication::applicationFilePath() to get the name
|
||||
* of the executable to include in the message.
|
||||
*
|
||||
* \sa QCoreApplication::applicationFilePath()
|
||||
*/
|
||||
bool QxtCommandOptions::showUnrecognizedWarning(QIODevice* device) const
|
||||
{
|
||||
if (!device)
|
||||
{
|
||||
QTextStream stream(stderr);
|
||||
return showUnrecognizedWarning(*&stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream stream(device);
|
||||
return showUnrecognizedWarning(*&stream);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the automatically-generated warning text about any unrecognized options.
|
||||
*
|
||||
* If a QCoreApplication or a subclass of QCoreApplication has been instantiated,
|
||||
* this function uses QCoreApplication::applicationFilePath() to get the name
|
||||
* of the executable to include in the message.
|
||||
*
|
||||
* \sa QCoreApplication::applicationFilePath()
|
||||
*/
|
||||
QString QxtCommandOptions::getUnrecognizedWarning() const
|
||||
{
|
||||
QString usage;
|
||||
QTextStream stream(&usage);
|
||||
showUnrecognizedWarning(*&stream);
|
||||
return usage;
|
||||
}
|
||||
|
||||
/*!
|
||||
* This is an overloaded member function, provided for convenience.
|
||||
*
|
||||
* Outputs a warning about any unrecognized options to the provided stream.
|
||||
*
|
||||
* This function returns true if any warnings were output, or false otherwise.
|
||||
*
|
||||
* If a QCoreApplication or a subclass of QCoreApplication has been instantiated,
|
||||
* this function uses QCoreApplication::applicationFilePath() to get the name
|
||||
* of the executable to include in the message.
|
||||
*
|
||||
* \sa QCoreApplication::applicationFilePath()
|
||||
*/
|
||||
bool QxtCommandOptions::showUnrecognizedWarning(QTextStream& stream) const
|
||||
{
|
||||
if (!qxt_d().unrecognized.count() && !qxt_d().missingParams.count()) return false;
|
||||
|
||||
QString name;
|
||||
if (QCoreApplication::instance())
|
||||
name = QDir(QCoreApplication::applicationFilePath()).dirName();
|
||||
if (name.isEmpty())
|
||||
name = "QxtCommandOptions";
|
||||
|
||||
if (qxt_d().unrecognized.count())
|
||||
stream << name << ": " << tr("unrecognized parameters: ") << qxt_d().unrecognized.join(" ") << endl;
|
||||
|
||||
foreach(const QString& param, qxt_d().missingParams)
|
||||
stream << name << ": " << tr("%1 requires a parameter").arg(param) << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* This is an overloaded member function, provided for convenience.
|
||||
*
|
||||
* Outputs automatically-generated usage text for the accepted options to the provided
|
||||
* device, or standard error by default. The device must already be opened for writing.
|
||||
*
|
||||
* Pass true to showQtOptions to output usage text for the options recognized by
|
||||
* QApplication.
|
||||
*
|
||||
* \sa QApplication
|
||||
*/
|
||||
void QxtCommandOptions::showUsage(bool showQtOptions, QIODevice* device) const
|
||||
{
|
||||
if (!device)
|
||||
{
|
||||
QTextStream stream(stdout);
|
||||
showUsage(showQtOptions, *&stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream stream(device);
|
||||
showUsage(showQtOptions, *&stream);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the automatically-generated usage text for the accepted options.
|
||||
*/
|
||||
QString QxtCommandOptions::getUsage(bool showQtOptions) const
|
||||
{
|
||||
QString usage;
|
||||
QTextStream stream(&usage);
|
||||
showUsage(showQtOptions, *&stream);
|
||||
return usage;
|
||||
}
|
||||
|
||||
/*!
|
||||
* This is an overloaded member function, provided for convenience.
|
||||
*
|
||||
* Outputs automatically-generated usage text for the accepted options to the provided
|
||||
* stream.
|
||||
*
|
||||
* Pass true to showQtOptions to output usage text for the options recognized by
|
||||
* QApplication.
|
||||
*
|
||||
* \sa QApplication
|
||||
*/
|
||||
void QxtCommandOptions::showUsage(bool showQtOptions, QTextStream& stream) const
|
||||
{
|
||||
QStringList names;
|
||||
QStringList descs;
|
||||
int maxNameLength = 0;
|
||||
QString name;
|
||||
|
||||
foreach(const QxtCommandOption& option, qxt_d().options)
|
||||
{
|
||||
// Don't generate usage for undocumented parameters
|
||||
if (option.paramType & Undocumented) continue;
|
||||
|
||||
foreach(const QString& n, option.names)
|
||||
{
|
||||
if (name.length()) name += ", ";
|
||||
if (qxt_d().flagStyle == Slash)
|
||||
name += '/';
|
||||
else if (qxt_d().flagStyle == DoubleDash && n.length() > 1)
|
||||
name += "--";
|
||||
else
|
||||
name += '-';
|
||||
name += n;
|
||||
if (option.paramType & (ValueOptional | ValueRequired))
|
||||
{
|
||||
if (option.paramType & ValueOptional)
|
||||
name += "[=x]";
|
||||
else if (qxt_d().paramStyle == SpaceAndEquals)
|
||||
name += "[=]x";
|
||||
else if (qxt_d().paramStyle == Equals)
|
||||
name += "=x";
|
||||
else
|
||||
name += " x";
|
||||
}
|
||||
}
|
||||
|
||||
// The maximum name length is used for formatting the output columns
|
||||
if (name.length() > maxNameLength)
|
||||
maxNameLength = name.length();
|
||||
names.append(name);
|
||||
descs.append(option.desc);
|
||||
name = "";
|
||||
}
|
||||
|
||||
if (showQtOptions)
|
||||
{
|
||||
// Add a section header
|
||||
names.append(QString());
|
||||
descs.append("Common Qt Options");
|
||||
|
||||
// Parse through qxt_qt_options
|
||||
const char* option;
|
||||
bool optionHasValue;
|
||||
for (int i = 0; qxt_qt_options[i]; i += 2)
|
||||
{
|
||||
option = qxt_qt_options[i];
|
||||
|
||||
if (option[0] == '=')
|
||||
{
|
||||
// The option takes a parameter
|
||||
optionHasValue = true;
|
||||
option = option + 1; // pointer math to skip the =
|
||||
}
|
||||
else
|
||||
{
|
||||
optionHasValue = false;
|
||||
}
|
||||
|
||||
// Concatenate on the option alias
|
||||
if (!name.isEmpty()) name += ", ";
|
||||
name += '-';
|
||||
name += option;
|
||||
if (optionHasValue) name += "[=]x";
|
||||
|
||||
if (qxt_qt_options[i+1][0] != 0)
|
||||
{
|
||||
// The last alias for the option has the description
|
||||
if (name.length() > maxNameLength)
|
||||
maxNameLength = name.length();
|
||||
names.append(name);
|
||||
descs.append(qxt_qt_options[i+1]);
|
||||
name = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ct = names.count();
|
||||
QString line, wrap(maxNameLength + 3, ' ');
|
||||
for (int i = 0; i < ct; i++)
|
||||
{
|
||||
if (names[i].isEmpty())
|
||||
{
|
||||
// Section headers have no name entry
|
||||
stream << endl << descs[i] << ":" << endl;
|
||||
continue;
|
||||
}
|
||||
line = ' ' + names[i] + QString(maxNameLength - names[i].length() + 2, ' ');
|
||||
foreach(const QString& word, descs[i].split(' ', QString::SkipEmptyParts))
|
||||
{
|
||||
if (qxt_d().screenWidth > 0 && line.length() + word.length() >= qxt_d().screenWidth)
|
||||
{
|
||||
stream << line << endl;
|
||||
line = wrap;
|
||||
}
|
||||
line += word + ' ';
|
||||
}
|
||||
stream << line << endl;
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTCOMMANDOPTIONS_H
|
||||
#define QXTCOMMANDOPTIONS_H
|
||||
#include <qxtglobal.h>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
#include <QCoreApplication> // for Q_DECLARE_TR_FUNCTIONS
|
||||
#include <QMultiHash>
|
||||
#include <QFlags>
|
||||
class QxtCommandOptionsPrivate;
|
||||
QT_FORWARD_DECLARE_CLASS(QTextStream)
|
||||
QT_FORWARD_DECLARE_CLASS(QIODevice)
|
||||
|
||||
|
||||
class QXT_CORE_EXPORT QxtCommandOptions
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(QxtCommandOptions)
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \enum QxtCommandOptions::FlagStyle
|
||||
* This enum type defines which type of option prefix is used.
|
||||
* Slash is the default on Windows.
|
||||
* DoubleDash is the default on all other platforms.
|
||||
*/
|
||||
enum FlagStyle
|
||||
{
|
||||
DoubleDash, /*!< Two dashes (GNU-style) */
|
||||
SingleDash, /*!< One dash (UNIX-style) */
|
||||
Slash /*!< Forward slash (Windows-style) */
|
||||
};
|
||||
/*!
|
||||
* \enum QxtCommandOptions::ParamStyle
|
||||
* This enum type defines what syntax is used for options that
|
||||
* require parameters. Equals is the default on Windows.
|
||||
* SpaceAndEquals is the default on all other platforms.
|
||||
*/
|
||||
enum ParamStyle
|
||||
{
|
||||
Space = 1, /*!< Space ("-option value") */
|
||||
Equals = 2, /*!< Equals sign ("/option=value") */
|
||||
SpaceAndEquals = 3 /*!< Accept either */
|
||||
};
|
||||
/*!
|
||||
* \enum QxtCommandOptions::ParamType
|
||||
* \flags QxtCommandOptions::ParamTypes
|
||||
* This enum type is used to specify flags that control the
|
||||
* interpretation of an option.
|
||||
*
|
||||
* The ParamTypes type is a typedef for QFlags<ParamType>. It stores
|
||||
* an OR combination of ParamType values.
|
||||
*/
|
||||
enum ParamType
|
||||
{
|
||||
NoValue = 0, /*!< The option does not accept a value. */
|
||||
ValueOptional = 1, /*!< The option may accept a value. */
|
||||
ValueRequired = 2, /*!< The option requires a value. */
|
||||
Optional = ValueOptional, /*!< The option may accept a value. Deprecated in favor of ValueOptional. */
|
||||
Required = ValueRequired, /*!< The option requires a value. Deprecated in favor of ValueRequired. */
|
||||
AllowMultiple = 4, /*!< The option may be passed multiple times. */
|
||||
Undocumented = 8 /*!< The option is not output in the help text. */
|
||||
};
|
||||
Q_DECLARE_FLAGS(ParamTypes, ParamType)
|
||||
|
||||
QxtCommandOptions();
|
||||
|
||||
void setFlagStyle(FlagStyle style);
|
||||
FlagStyle flagStyle() const;
|
||||
void setParamStyle(ParamStyle style);
|
||||
ParamStyle paramStyle() const;
|
||||
void setScreenWidth(quint16 width);
|
||||
quint16 screenWidth() const;
|
||||
|
||||
void addSection(const QString& name);
|
||||
void add(const QString& name, const QString& desc = QString(), ParamTypes paramType = NoValue, int group = -1);
|
||||
void alias(const QString& from, const QString& to);
|
||||
|
||||
QStringList positional() const;
|
||||
QStringList unrecognized() const;
|
||||
int count(const QString& name) const;
|
||||
QVariant value(const QString& name) const;
|
||||
QMultiHash<QString, QVariant> parameters() const;
|
||||
|
||||
void parse(int argc, char** argv);
|
||||
void parse(QStringList params);
|
||||
|
||||
void showUsage(bool showQtOptions = false, QIODevice* device = 0) const;
|
||||
void showUsage(bool showQtOptions, QTextStream& stream) const;
|
||||
QString getUsage(bool showQtOptions = false) const;
|
||||
|
||||
bool showUnrecognizedWarning(QIODevice* device = 0) const;
|
||||
bool showUnrecognizedWarning(QTextStream& stream) const;
|
||||
QString getUnrecognizedWarning() const;
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtCommandOptions)
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QxtCommandOptions::ParamTypes)
|
||||
|
||||
#endif // QXTCOMMANDOPTIONS_H
|
@ -1,79 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTCORE_H_INCLUDED
|
||||
#define QXTCORE_H_INCLUDED
|
||||
|
||||
#include "qxtabstractfileloggerengine.h"
|
||||
#include "qxtabstractconnectionmanager.h"
|
||||
#include "qxtabstractiologgerengine.h"
|
||||
#include "qxtabstractsignalserializer.h"
|
||||
#include "qxtalgorithms.h"
|
||||
#include "qxtbasicfileloggerengine.h"
|
||||
#include "qxtbasicstdloggerengine.h"
|
||||
#include "qxtboundcfunction.h"
|
||||
#include "qxtboundfunction.h"
|
||||
#include "qxtboundfunctionbase.h"
|
||||
#include "qxtcommandoptions.h"
|
||||
#include "qxtcsvmodel.h"
|
||||
#include "qxtdaemon.h"
|
||||
#include "qxtdatastreamsignalserializer.h"
|
||||
#include "qxtdeplex.h"
|
||||
#include "qxterror.h"
|
||||
#include "qxtfifo.h"
|
||||
#include "qxtfilelock.h"
|
||||
#include "qxtglobal.h"
|
||||
#include "qxthmac.h"
|
||||
#include "qxtjson.h"
|
||||
#include "qxtjob.h"
|
||||
#include "qxtlinesocket.h"
|
||||
#include "qxtlinkedtree.h"
|
||||
#include "qxtlogger.h"
|
||||
#include "qxtloggerengine.h"
|
||||
#include "qxtlogstream.h"
|
||||
#include "qxtlocale.h"
|
||||
#include "qxtmetaobject.h"
|
||||
#include "qxtmetatype.h"
|
||||
#include "qxtmodelserializer.h"
|
||||
#include "qxtmultisignalwaiter.h"
|
||||
#include "qxtnamespace.h"
|
||||
#include "qxtnull.h"
|
||||
#include "qxtnullable.h"
|
||||
#include "qxtpairlist.h"
|
||||
#include "qxtpimpl.h"
|
||||
#include "qxtpipe.h"
|
||||
#include "qxtpointerlist.h"
|
||||
#include "qxtrpcservice.h"
|
||||
#include "qxtsharedprivate.h"
|
||||
#include "qxtsignalgroup.h"
|
||||
#include "qxtsignalwaiter.h"
|
||||
#include "qxtslotjob.h"
|
||||
#include "qxtslotmapper.h"
|
||||
#include "qxtstdio.h"
|
||||
#include "qxtstdstreambufdevice.h"
|
||||
#include "qxttimer.h"
|
||||
#include "qxttypelist.h"
|
||||
#include "qxtxmlfileloggerengine.h"
|
||||
|
||||
#endif // QXTCORE_H_INCLUDED
|
@ -1,426 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\class QxtCsvModel
|
||||
\inmodule QxtCore
|
||||
\brief The QxtCsvModel class provides a QAbstractTableModel for CSV Files
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtCsvModel::QxtCsvModel(QObject *parent = 0);
|
||||
Constructs a new QxtCsvModel with \a parent
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtCsvModel::~QxtCsvModel();
|
||||
Destructor
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtCsvModel::QxtCsvModel(QIODevice *file, QObject *parent=0, bool withHeader = false, QChar separator= ',')
|
||||
constructs a QxtCsvModel from a QIODevice \a file as source
|
||||
\a withHeader specifies if the data on the device contains a header or not.
|
||||
\a separator is the separator to use for the columns. most widely used separators are ',' '\\t' ';'
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtCsvModel::QxtCsvModel(const QString filename, QObject *parent = 0, bool withHeader = false, QChar separator = ',')
|
||||
constructs a QxtCsvModel from \a filename as source
|
||||
\a withHeader specifies if the data in the file contains a header or not.
|
||||
\a separator is the separator to use for the columns. most widely used separators are ',' '\\t' ';'
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtCsvModel::setSource(QIODevice *file, bool withHeader = false, QChar separator = ',');
|
||||
reads the cvs data from \a file
|
||||
\a withHeader specifies if the data on the device contains a header or not.
|
||||
\a separator is the separator to use for the columns. most widely used separators are ',' '\\t' ';'
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void QxtCsvModel::setSource(const QString filename, bool withHeader = false, QChar separator = ',');
|
||||
reads the cvs data from \a filename
|
||||
\a withHeader specifies if the data in the file contains a header or not.
|
||||
\a separator is the separator to use for the columns. most widely used separators are ',' '\\t' ';'
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
\fn void QxtCsvModel::toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',');
|
||||
writes the cvs data to \a file
|
||||
\a withHeader specifies if to write the header or not
|
||||
\a separator is the separator to use for the columns. most widely used separators are ',' '\\t' ';'
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void QxtCsvModel::toCSV(const QString filename, bool withHeader = false, QChar separator = ',');
|
||||
writes the cvs data to \a filename
|
||||
\a withHeader specifies if to write the header or not
|
||||
\a separator is the separator to use for the columns. most widely used separators are ',' '\\t' ';'
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "qxtcsvmodel.h"
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
class QxtCsvModelPrivate : public QxtPrivate<QxtCsvModel>
|
||||
{
|
||||
public:
|
||||
QxtCsvModelPrivate() : csvData(), header(), maxColumn(0)
|
||||
{}
|
||||
QXT_DECLARE_PUBLIC(QxtCsvModel)
|
||||
|
||||
QStringList csvData;
|
||||
QStringList header;
|
||||
int maxColumn;
|
||||
};
|
||||
|
||||
QxtCsvModel::QxtCsvModel(QObject *parent) : QAbstractTableModel(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtCsvModel);
|
||||
}
|
||||
|
||||
QxtCsvModel::QxtCsvModel(QIODevice *file, QObject *parent, bool withHeader, QChar separator) : QAbstractTableModel(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtCsvModel);
|
||||
setSource(file, withHeader, separator);
|
||||
}
|
||||
|
||||
QxtCsvModel::QxtCsvModel(const QString filename, QObject *parent, bool withHeader, QChar separator) : QAbstractTableModel(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtCsvModel);
|
||||
QFile src(filename);
|
||||
setSource(&src, withHeader, separator);
|
||||
}
|
||||
|
||||
QxtCsvModel::~QxtCsvModel()
|
||||
{}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
int QxtCsvModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if (parent.row() != -1 && parent.column() != -1) return 0;
|
||||
return qxt_d().csvData.count();
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
int QxtCsvModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
if (parent.row() != -1 && parent.column() != -1) return 0;
|
||||
return qxt_d().maxColumn;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
QVariant QxtCsvModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (index.parent() != QModelIndex()) return QVariant();
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole)
|
||||
return qxt_d().csvData[index.row()].section(QChar(1), index.column(), index.column());
|
||||
else
|
||||
{
|
||||
//QVariant v;
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
QVariant QxtCsvModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (section < qxt_d().header.count() && orientation == Qt::Horizontal && (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole))
|
||||
{
|
||||
return qxt_d().header[section];
|
||||
}
|
||||
else
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
void QxtCsvModel::setSource(const QString filename, bool withHeader, QChar separator)
|
||||
{
|
||||
QFile src(filename);
|
||||
setSource(&src, withHeader, separator);
|
||||
}
|
||||
|
||||
void QxtCsvModel::setSource(QIODevice *file, bool withHeader, QChar separator)
|
||||
{
|
||||
QxtCsvModelPrivate* d_ptr = &qxt_d();
|
||||
QString l;
|
||||
int size;
|
||||
bool isQuoted, headerSet = false;
|
||||
if (!file->isOpen()) file->open(QIODevice::ReadOnly);
|
||||
if (withHeader)
|
||||
d_ptr->maxColumn = 0;
|
||||
else
|
||||
d_ptr->maxColumn = d_ptr->header.size();
|
||||
d_ptr->csvData.clear();
|
||||
while (!file->atEnd())
|
||||
{
|
||||
l = file->readLine();
|
||||
l.remove('\n');
|
||||
l.remove('\r');
|
||||
size = l.length();
|
||||
isQuoted = false;
|
||||
for (int i = 0;i < size;i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
if (l[i] == '"' && l[i-1] != '\\') isQuoted = !isQuoted;
|
||||
else if (!isQuoted && l[i] == separator) l[i] = QChar(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (l[i] == '"') isQuoted = !isQuoted;
|
||||
else if (!isQuoted && l[i] == separator) l[i] = QChar(1);
|
||||
}
|
||||
}
|
||||
if (l.count(QChar(1)) + 1 > d_ptr->maxColumn) d_ptr->maxColumn = l.count(QChar(1)) + 1;
|
||||
if (withHeader && !headerSet)
|
||||
{
|
||||
d_ptr->header = l.split(QChar(1));
|
||||
headerSet = true;
|
||||
}
|
||||
else
|
||||
d_ptr->csvData.append(l);
|
||||
}
|
||||
file->close();
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QxtCsvModel::setHeaderData(const QStringList data)
|
||||
{
|
||||
qxt_d().header = data;
|
||||
emit headerDataChanged(Qt::Horizontal, 0, data.count());
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::setData(const QModelIndex& index, const QVariant& data, int role)
|
||||
{
|
||||
if (index.parent() != QModelIndex()) return false;
|
||||
|
||||
QString before, after;
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole)
|
||||
{
|
||||
if (index.row() >= rowCount() || index.column() >= columnCount() || index.row() < 0 || index.column() < 0) return false;
|
||||
if (index.column() != 0)
|
||||
before = qxt_d().csvData[index.row()].section(QChar(1), 0, index.column() - 1) + QChar(1);
|
||||
else
|
||||
before = "";
|
||||
after = qxt_d().csvData[index.row()].section(QChar(1), index.column() + 1);
|
||||
qxt_d().csvData[index.row()] = before + data.toString() + QChar(1) + after;
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::insertRow(int row, const QModelIndex& parent)
|
||||
{
|
||||
return insertRows(row, 1, parent);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||
{
|
||||
if (parent != QModelIndex() || row < 0) return false;
|
||||
emit beginInsertRows(parent, row, row + count);
|
||||
QxtCsvModelPrivate& d_ptr = qxt_d();
|
||||
if (row >= rowCount())
|
||||
{
|
||||
for (int i = 0;i < count;i++) d_ptr.csvData << "";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0;i < count;i++) d_ptr.csvData.insert(row, "");
|
||||
}
|
||||
emit endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::removeRow(int row, const QModelIndex& parent)
|
||||
{
|
||||
return removeRows(row, 1, parent);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||
{
|
||||
if (parent != QModelIndex() || row < 0) return false;
|
||||
if (row >= rowCount()) return false;
|
||||
if (row + count >= rowCount()) count = rowCount() - row;
|
||||
emit beginRemoveRows(parent, row, row + count);
|
||||
QxtCsvModelPrivate& d_ptr = qxt_d();
|
||||
for (int i = 0;i < count;i++)
|
||||
d_ptr.csvData.removeAt(row);
|
||||
emit endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::insertColumn(int col, const QModelIndex& parent)
|
||||
{
|
||||
return insertColumns(col, 1, parent);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::insertColumns(int col, int count, const QModelIndex& parent)
|
||||
{
|
||||
if (parent != QModelIndex() || col < 0) return false;
|
||||
emit beginInsertColumns(parent, col, col + count);
|
||||
QxtCsvModelPrivate& d_ptr = qxt_d();
|
||||
if (col < columnCount())
|
||||
{
|
||||
QString before, after;
|
||||
for (int i = 0;i < rowCount();i++)
|
||||
{
|
||||
if (col > 0)
|
||||
before = d_ptr.csvData[i].section(QChar(1), 0, col - 1) + QChar(1);
|
||||
else
|
||||
before = "";
|
||||
after = d_ptr.csvData[i].section(QChar(1), col);
|
||||
d_ptr.csvData[i] = before + QString(count, QChar(1)) + after;
|
||||
}
|
||||
}
|
||||
for (int i = 0;i < count;i++)
|
||||
d_ptr.header.insert(col, "");
|
||||
d_ptr.maxColumn += count;
|
||||
emit endInsertColumns();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::removeColumn(int col, const QModelIndex& parent)
|
||||
{
|
||||
return removeColumns(col, 1, parent);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtCsvModel::removeColumns(int col, int count, const QModelIndex& parent)
|
||||
{
|
||||
if (parent != QModelIndex() || col < 0) return false;
|
||||
if (col >= columnCount()) return false;
|
||||
if (col + count >= columnCount()) count = columnCount() - col;
|
||||
emit beginRemoveColumns(parent, col, col + count);
|
||||
QxtCsvModelPrivate& d_ptr = qxt_d();
|
||||
QString before, after;
|
||||
for (int i = 0;i < rowCount();i++)
|
||||
{
|
||||
if (col > 0)
|
||||
before = d_ptr.csvData[i].section(QChar(1), 0, col - 1) + QChar(1);
|
||||
else
|
||||
before = "";
|
||||
after = d_ptr.csvData[i].section(QChar(1), col + count);
|
||||
d_ptr.csvData[i] = before + after;
|
||||
}
|
||||
for (int i = 0;i < count;i++)
|
||||
d_ptr.header.removeAt(col);
|
||||
emit endRemoveColumns();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void QxtCsvModel::toCSV(QIODevice* dest, bool withHeader, QChar separator)
|
||||
{
|
||||
QxtCsvModelPrivate& d_ptr = qxt_d();
|
||||
int row, col, rows, cols;
|
||||
rows = rowCount();
|
||||
cols = columnCount();
|
||||
QString data;
|
||||
if (!dest->isOpen()) dest->open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
if (withHeader)
|
||||
{
|
||||
data = "";
|
||||
for (col = 0; col < cols; ++col)
|
||||
{
|
||||
data += '"' + d_ptr.header.at(col) + '"';
|
||||
if (col < cols - 1) data += separator;
|
||||
}
|
||||
data += QChar(10);
|
||||
dest->write(data.toLatin1());
|
||||
}
|
||||
for (row = 0; row < rows; ++row)
|
||||
{
|
||||
data = "";
|
||||
for (col = 0; col < cols; ++col)
|
||||
{
|
||||
data += '"' + d_ptr.csvData[row].section(QChar(1), col, col) + '"';
|
||||
if (col < cols - 1) data += separator;
|
||||
}
|
||||
data += QChar(10);
|
||||
dest->write(data.toLatin1());
|
||||
}
|
||||
dest->close();
|
||||
}
|
||||
|
||||
void QxtCsvModel::toCSV(const QString filename, bool withHeader, QChar separator)
|
||||
{
|
||||
QFile dest(filename);
|
||||
toCSV(&dest, withHeader, separator);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
Qt::ItemFlags QxtCsvModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTCSVMODEL_H
|
||||
#define QXTCSVMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QVariant>
|
||||
#include <QIODevice>
|
||||
#include <QChar>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QModelIndex>
|
||||
#include <qxtglobal.h>
|
||||
|
||||
class QxtCsvModelPrivate;
|
||||
class QXT_CORE_EXPORT QxtCsvModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtCsvModel(QObject *parent = 0);
|
||||
explicit QxtCsvModel(QIODevice *file, QObject *parent = 0, bool withHeader = false, QChar separator = ',');
|
||||
explicit QxtCsvModel(const QString filename, QObject *parent = 0, bool withHeader = false, QChar separator = ',');
|
||||
~QxtCsvModel();
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole);
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
void setHeaderData(const QStringList data);
|
||||
|
||||
bool insertRow(int row, const QModelIndex& parent = QModelIndex());
|
||||
bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
||||
bool removeRow(int row, const QModelIndex& parent = QModelIndex());
|
||||
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
||||
bool insertColumn(int col, const QModelIndex& parent = QModelIndex());
|
||||
bool insertColumns(int col, int count, const QModelIndex& parent = QModelIndex());
|
||||
bool removeColumn(int col, const QModelIndex& parent = QModelIndex());
|
||||
bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex());
|
||||
|
||||
void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',');
|
||||
void setSource(const QString filename, bool withHeader = false, QChar separator = ',');
|
||||
|
||||
void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',');
|
||||
void toCSV(const QString filename, bool withHeader = false, QChar separator = ',');
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtCsvModel)
|
||||
};
|
||||
|
||||
#endif
|
@ -1,251 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\class QxtDaemon
|
||||
\inmodule QxtCore
|
||||
\brief The QxtDaemon class is a Qt-based Implementation of a Unix daemon
|
||||
|
||||
QxtDaemon will provide you with a standard UNIX daemon implementation.
|
||||
after sucessful forking it will install a messageHandler which logs all qDebug/qWarning/etc... output to /var/log/mydaemon.log
|
||||
|
||||
|
||||
example usage:
|
||||
\code
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
QxtDaemon d("exampled");
|
||||
qDebug("about to fork");
|
||||
d.daemonize();
|
||||
qDebug("forked");
|
||||
d.changeUser("nobody");
|
||||
QCoreApplication app(argc,argv);
|
||||
return app.exec();
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
|
||||
#include "qxtdaemon.h"
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <QFile>
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
|
||||
static QxtDaemon * qxt_daemon_singleton = 0;
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void QxtDaemon::signalHandler(int sig)
|
||||
{
|
||||
emit(qxt_daemon_singleton->signal(sig));
|
||||
if (sig == SIGHUP)
|
||||
{
|
||||
qDebug("hangup signal caught");
|
||||
emit(qxt_daemon_singleton->hangup());
|
||||
}
|
||||
else if (sig == SIGTERM)
|
||||
{
|
||||
qDebug("terminate signal caught");
|
||||
emit(qxt_daemon_singleton->terminate());
|
||||
QCoreApplication::exit(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void QxtDaemon::messageHandler(QtMsgType type, const char *msg)
|
||||
{
|
||||
QFile * f = qxt_daemon_singleton->logfile;
|
||||
f->write("[");
|
||||
f->write(QDateTime::currentDateTime().toString(Qt::ISODate).toLocal8Bit());
|
||||
f->write("] ");
|
||||
if (type == QtDebugMsg)
|
||||
f->write("[qDebug] ");
|
||||
else if (type == QtWarningMsg)
|
||||
f->write("[qWarning] ");
|
||||
else if (type == QtCriticalMsg)
|
||||
f->write("[qCritical] ");
|
||||
else if (type == QtFatalMsg)
|
||||
{
|
||||
f->write("[qFatal] ");
|
||||
f->write(msg);
|
||||
f->write("\n");
|
||||
f->write("aborting \n");
|
||||
f->flush();
|
||||
abort();
|
||||
}
|
||||
|
||||
f->write(msg);
|
||||
f->write("\n");
|
||||
f->flush();
|
||||
}
|
||||
|
||||
/*!
|
||||
constructs a new QxtDaemon
|
||||
the applicationName is used as a base for log and pid files
|
||||
*/
|
||||
QxtDaemon::QxtDaemon(QString name)
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
if (name.isEmpty())
|
||||
{
|
||||
qFatal("you need to set an applicationName (e.g. using QCoreApplication::setApplicationName() )");
|
||||
}
|
||||
|
||||
if (qxt_daemon_singleton)
|
||||
{
|
||||
qFatal("unable to construct more then one QxtDaemon instance");
|
||||
}
|
||||
else
|
||||
{
|
||||
qxt_daemon_singleton = this;
|
||||
m_name = name;
|
||||
logfile = new QFile("/var/log/" + m_name + ".log");
|
||||
}
|
||||
#else
|
||||
qFatal("currently QxtDaemon is only implemented on unix");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*based on work of Levent Karakas <levent at mektup dot at> May 2001*/
|
||||
/*!
|
||||
forks the current Process
|
||||
you can specify weather it will write a pidfile to /var/run/mydaemon.pid or not
|
||||
if you specify true (the default) QxtDaemon will also try to lock the pidfile. If it can't get a lock it will assume another daemon of the same name is already running and exit
|
||||
be aware that after calling this function all file descriptors are invalid. QFile will not detect the change, you have to explicitly close all files before forking.
|
||||
return true on success
|
||||
*/
|
||||
bool QxtDaemon::daemonize(bool pidfile)
|
||||
{
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
|
||||
if (!logfile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
|
||||
qFatal("cannot open logfile %s", qPrintable(logfile->fileName()));
|
||||
logfile->close();
|
||||
|
||||
|
||||
|
||||
if (pidfile)
|
||||
{
|
||||
QFile f("/var/run/" + m_name + ".pid");
|
||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
qFatal("cannot open pidfile \"/var/run/%s.pid\"", qPrintable(m_name));
|
||||
if (lockf(f.handle(), F_TEST, 0) < 0)
|
||||
qFatal("can't get a lock on \"/var/run/%s.pid\". another instance is propably already running.", qPrintable(m_name));
|
||||
f.close();
|
||||
}
|
||||
|
||||
if (!logfile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
|
||||
qFatal("cannot open logfile %s", qPrintable(logfile->fileName()));
|
||||
logfile->close();
|
||||
|
||||
int i;
|
||||
if (getppid() == 1) return true; /* already a daemon */
|
||||
i = fork();
|
||||
|
||||
|
||||
/* double fork.*/
|
||||
if (i < 0) return false; /*fork error */
|
||||
if (i > 0) exit(0); /*parent exits */
|
||||
if (i < 0) return false; /*fork error */
|
||||
if (i > 0) exit(0); /*parent exits */
|
||||
|
||||
/* child (daemon) continues */
|
||||
setsid(); /* obtain a new process group */
|
||||
|
||||
for (i = getdtablesize();i >= 0;--i) close(i); /* close all descriptors */
|
||||
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
::umask(027); /* some programmers don't understand security, so we set a sane default here */
|
||||
#endif
|
||||
::signal(SIGCHLD, SIG_IGN); /* ignore child */
|
||||
::signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
|
||||
::signal(SIGTTOU, SIG_IGN);
|
||||
::signal(SIGTTIN, SIG_IGN);
|
||||
::signal(SIGHUP, QxtDaemon::signalHandler); /* catch hangup signal */
|
||||
::signal(SIGTERM, QxtDaemon::signalHandler); /* catch kill signal */
|
||||
|
||||
if (pidfile)
|
||||
{
|
||||
int lfp =::open(qPrintable("/var/run/" + m_name + ".pid"), O_RDWR | O_CREAT, 0640);
|
||||
if (lfp < 0)
|
||||
qFatal("cannot open pidfile \"/var/run/%s.pid\"", qPrintable(m_name));
|
||||
if (lockf(lfp, F_TLOCK, 0) < 0)
|
||||
qFatal("can't get a lock on \"/var/run/%s.pid\". another instance is propably already running.", qPrintable(m_name));
|
||||
|
||||
QByteArray d = QByteArray::number(pid());
|
||||
Q_UNUSED(::write(lfp, d.constData(), d.size()));
|
||||
}
|
||||
|
||||
|
||||
assert(logfile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append));
|
||||
qInstallMsgHandler(QxtDaemon::messageHandler);
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
returns the current processId
|
||||
*/
|
||||
int QxtDaemon::pid()
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
return getpid();
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
changes the current user of this process.
|
||||
do this after forking to drop root rights.
|
||||
returns true on success
|
||||
*/
|
||||
bool QxtDaemon::changeUser(QString name)
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
///according to the posix spec, i'm not suposed to delete it. *shrug* weird
|
||||
passwd *p =::getpwnam(qPrintable(name));
|
||||
if (!p)
|
||||
return false;
|
||||
return setuid(p->pw_uid) == 0;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,63 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTDAEMON_H
|
||||
#define QXTDAEMON_H
|
||||
|
||||
#include "qxtglobal.h"
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QCoreApplication>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QFile)
|
||||
|
||||
class QXT_CORE_EXPORT QxtDaemon : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtDaemon(QString applicationName = QCoreApplication::applicationName());
|
||||
bool daemonize(bool pidfile = true);
|
||||
static int pid();
|
||||
bool changeUser(QString name);
|
||||
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
|
||||
static void messageHandler(QtMsgType type, const char *msg);
|
||||
#ifdef Q_OS_UNIX
|
||||
static void signalHandler(int signal);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QFile *logfile;
|
||||
Q_SIGNALS:
|
||||
void signal(int);
|
||||
void hangup();
|
||||
void terminate();
|
||||
};
|
||||
|
||||
#endif // QXT_DAEMON_H
|
@ -1,94 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qxtdatastreamsignalserializer.h>
|
||||
#include <QIODevice>
|
||||
#include <QDataStream>
|
||||
#include <QtGlobal>
|
||||
#include <QtDebug>
|
||||
#include <qendian.h>
|
||||
|
||||
QByteArray QxtDataStreamSignalSerializer::serialize(const QString& fn, const QVariant& p1, const QVariant& p2, const QVariant& p3,
|
||||
const QVariant& p4, const QVariant& p5, const QVariant& p6, const QVariant& p7, const QVariant& p8) const
|
||||
{
|
||||
QByteArray rv;
|
||||
QDataStream str(&rv, QIODevice::WriteOnly);
|
||||
str << fn;
|
||||
unsigned char ct = 8;
|
||||
if (!p1.isValid()) ct = 0;
|
||||
else if (!p2.isValid()) ct = 1;
|
||||
else if (!p3.isValid()) ct = 2;
|
||||
else if (!p4.isValid()) ct = 3;
|
||||
else if (!p5.isValid()) ct = 4;
|
||||
else if (!p6.isValid()) ct = 5;
|
||||
else if (!p7.isValid()) ct = 6;
|
||||
else if (!p8.isValid()) ct = 7;
|
||||
str << ct;
|
||||
if (ct-- > 0) str << p1;
|
||||
if (ct-- > 0) str << p2;
|
||||
if (ct-- > 0) str << p3;
|
||||
if (ct-- > 0) str << p4;
|
||||
if (ct-- > 0) str << p5;
|
||||
if (ct-- > 0) str << p6;
|
||||
if (ct-- > 0) str << p7;
|
||||
if (ct-- > 0) str << p8;
|
||||
char sizeData[4];
|
||||
qToLittleEndian(quint32(rv.size()), (uchar*)sizeData);
|
||||
return QByteArray(sizeData, 4) + rv;
|
||||
}
|
||||
|
||||
QxtAbstractSignalSerializer::DeserializedData QxtDataStreamSignalSerializer::deserialize(QByteArray& data)
|
||||
{
|
||||
QByteArray cmd;
|
||||
quint32 len = qFromLittleEndian<quint32>(reinterpret_cast<const uchar*>(data.constData()));
|
||||
|
||||
cmd = data.mid(4, len);
|
||||
data = data.mid(len + 4);
|
||||
if (cmd.length() == 0) return NoOp();
|
||||
|
||||
QDataStream str(cmd);
|
||||
|
||||
QString signal;
|
||||
unsigned char argCount;
|
||||
QList<QVariant> v;
|
||||
QVariant t;
|
||||
str >> signal >> argCount;
|
||||
|
||||
if (str.status() == QDataStream::ReadCorruptData) return ProtocolError();
|
||||
|
||||
for (int i = 0; i < argCount; i++)
|
||||
{
|
||||
str >> t;
|
||||
v << t;
|
||||
}
|
||||
return qMakePair(signal, v);
|
||||
}
|
||||
|
||||
bool QxtDataStreamSignalSerializer::canDeserialize(const QByteArray& buffer) const
|
||||
{
|
||||
int headerLen = qFromLittleEndian<quint32>(reinterpret_cast<const uchar*>(buffer.constData()));
|
||||
int bodyLen = quint32(buffer.length() - 4);
|
||||
return headerLen <= bodyLen;
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTDATASTREAMSIGNALSERIALIZER_H
|
||||
#define QXTDATASTREAMSIGNALSERIALIZER_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
#include <qxtabstractsignalserializer.h>
|
||||
|
||||
class QXT_CORE_EXPORT QxtDataStreamSignalSerializer : public QxtAbstractSignalSerializer
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Serializes a signal into a form suitable for sending to an I/O device.
|
||||
*/
|
||||
virtual QByteArray serialize(const QString& fn, const QVariant& p1 = QVariant(), const QVariant& p2 = QVariant(), const QVariant& p3 = QVariant(),
|
||||
const QVariant& p4 = QVariant(), const QVariant& p5 = QVariant(), const QVariant& p6 = QVariant(),
|
||||
const QVariant& p7 = QVariant(), const QVariant& p8 = QVariant()) const;
|
||||
|
||||
/*!
|
||||
* Deserializes binary data into a signal name and a list of parameters.
|
||||
*/
|
||||
virtual DeserializedData deserialize(QByteArray& data);
|
||||
|
||||
/*!
|
||||
* Indicates whether the data currently in the buffer can be deserialized.
|
||||
*/
|
||||
virtual bool canDeserialize(const QByteArray& buffer) const;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,124 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtdeplex_p.h"
|
||||
|
||||
/*!
|
||||
\class QxtDeplex
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtDeplex class puts a standard QIODevice into a QxtPipe chain
|
||||
|
||||
|
||||
|
||||
implements a normal QxtPipe with the exception that r/w operations are delegated to the device set by setDevice()
|
||||
|
||||
\sa QIODevice
|
||||
\sa QxtPipe
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtDeplex::QxtDeplex(QObject * parent)
|
||||
\brief creates a new QxtDeplex
|
||||
|
||||
|
||||
\fn QxtDeplex::QxtDeplex(QIODevice * device,QObject * parent)
|
||||
\brief creates a new QxtDeplex and delegates r/w operations to the device
|
||||
|
||||
|
||||
\fn void QxtDeplex::setDevice(QIODevice * device);
|
||||
\brief delegate r/w operations to the device
|
||||
|
||||
\fn QIODevice *QxtDeplex::device() const;
|
||||
\brief returns the device currently delegated
|
||||
|
||||
|
||||
\fn virtual void QxtDeplex::receiveData (QByteArray data, const QxtPipe * sender )
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QxtDeplex::QxtDeplex(QObject * parent): QxtPipe(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtDeplex);
|
||||
qxt_d().delegate = 0;
|
||||
setDevice(0);
|
||||
}
|
||||
QxtDeplex::QxtDeplex(QIODevice * device, QObject * parent): QxtPipe(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtDeplex);
|
||||
qxt_d().delegate = 0;
|
||||
setDevice(device);
|
||||
}
|
||||
|
||||
void QxtDeplex::setDevice(QIODevice * device)
|
||||
{
|
||||
if (qxt_d().delegate)
|
||||
{
|
||||
QObject::disconnect(qxt_d().delegate, SIGNAL(readyRead()), &qxt_d(), SLOT(readyRead()));
|
||||
QObject::disconnect(qxt_d().delegate, SIGNAL(destroyed(QObject *)), &qxt_d(), SLOT(extDestroyed(QObject *)));
|
||||
}
|
||||
qxt_d().delegate = device;
|
||||
if (qxt_d().delegate)
|
||||
{
|
||||
QObject::connect(qxt_d().delegate, SIGNAL(readyRead()), &qxt_d(), SLOT(readyRead()));
|
||||
QObject::connect(qxt_d().delegate, SIGNAL(destroyed(QObject *)), &qxt_d(), SLOT(extDestroyed(QObject *)));
|
||||
}
|
||||
}
|
||||
QIODevice *QxtDeplex::device() const
|
||||
{
|
||||
return qxt_d().delegate;
|
||||
}
|
||||
|
||||
void QxtDeplexPrivate::readyRead()
|
||||
{
|
||||
QByteArray d = static_cast<QIODevice*>(sender())->readAll();
|
||||
|
||||
qxt_p().enqueData(d);
|
||||
qxt_p().sendData(d);
|
||||
}
|
||||
|
||||
void QxtDeplexPrivate::extDestroyed(QObject *)
|
||||
{
|
||||
delegate = 0;
|
||||
}
|
||||
|
||||
|
||||
qint64 QxtDeplex::writeData(const char * a, qint64 s)
|
||||
{
|
||||
if (!qxt_d().delegate)
|
||||
return 0;
|
||||
return qxt_d().delegate->write(a, s);
|
||||
|
||||
}
|
||||
void QxtDeplex::receiveData(QByteArray data, const QxtPipe *)
|
||||
{
|
||||
if (!qxt_d().delegate)
|
||||
return;
|
||||
qxt_d().delegate->write(data);
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTDEPLEX_H
|
||||
#define QXTDEPLEX_H
|
||||
#include "qxtglobal.h"
|
||||
#include "qxtpipe.h"
|
||||
|
||||
class QxtDeplexPrivate;
|
||||
class QXT_CORE_EXPORT QxtDeplex : public QxtPipe
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtDeplex(QObject * parent = 0);
|
||||
explicit QxtDeplex(QIODevice * device, QObject * parent = 0);
|
||||
|
||||
void setDevice(QIODevice * device);
|
||||
QIODevice *device() const;
|
||||
protected:
|
||||
virtual qint64 writeData(const char * data, qint64 maxSize);
|
||||
virtual void receiveData(QByteArray data, const QxtPipe * sender);
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtDeplex)
|
||||
|
||||
};
|
||||
|
||||
#endif // QXTDEPLEX_H
|
@ -1,46 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* this is private API. it might change at any time without notice. yarly.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef QXTDEPLEX_P_H_INCLUDED
|
||||
#define QXTDEPLEX_P_H_INCLUDED
|
||||
|
||||
#include "qxtdeplex.h"
|
||||
|
||||
class QxtDeplexPrivate: public QObject, public QxtPrivate<QxtDeplex>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QXT_DECLARE_PUBLIC(QxtDeplex)
|
||||
QIODevice * delegate;
|
||||
public Q_SLOTS:
|
||||
void readyRead();
|
||||
void extDestroyed(QObject*);
|
||||
};
|
||||
|
||||
#endif // QXTDEPLEX_P_H_INCLUDED
|
@ -1,65 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxterror.h"
|
||||
|
||||
QxtError::QxtError(const char * file, long line, Qxt::ErrorCode errorcode, const char * errorString)
|
||||
{
|
||||
file_m = file;
|
||||
line_m = line;
|
||||
errorcode_m = errorcode;
|
||||
errorString_m = errorString;
|
||||
}
|
||||
|
||||
|
||||
Qxt::ErrorCode QxtError::errorCode() const
|
||||
{
|
||||
return errorcode_m;
|
||||
}
|
||||
|
||||
long QxtError::line() const
|
||||
{
|
||||
return line_m;
|
||||
}
|
||||
|
||||
const char * QxtError::file() const
|
||||
{
|
||||
return file_m;
|
||||
}
|
||||
|
||||
QxtError::operator Qxt::ErrorCode()
|
||||
{
|
||||
return errorcode_m;
|
||||
}
|
||||
/*!
|
||||
The Error String or NULL
|
||||
depending how the error was constructed.
|
||||
Be carefull with stack and temporary objects, QxtError just saves the pointer you passed, not the actual data.
|
||||
*/
|
||||
const char * QxtError::errorString() const
|
||||
{
|
||||
return errorString_m;
|
||||
}
|
||||
|
||||
|
@ -1,125 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef QXTERROR_H
|
||||
#define QXTERROR_H
|
||||
#include <qxtglobal.h>
|
||||
#include <qxtnamespace.h>
|
||||
|
||||
/*!
|
||||
\class QxtError QxtError
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief Information about Errors ocuring inside Qxt
|
||||
|
||||
*/
|
||||
|
||||
/*! \relates QxtError
|
||||
droping an error inside a function that returns QxtError
|
||||
|
||||
|
||||
short for return QxtError(__FILE__,__LINE__,x);
|
||||
*/
|
||||
#define QXT_DROP(x) return QxtError(__FILE__,__LINE__,x);
|
||||
|
||||
|
||||
/*! \relates QxtError
|
||||
droping an error inside a function that returns QxtError
|
||||
|
||||
aditionaly specifies an errorstring \n
|
||||
|
||||
short for return QxtError(__FILE__,__LINE__,x,s);
|
||||
*/
|
||||
#define QXT_DROP_S(x,s) return QxtError(__FILE__,__LINE__,x,s);
|
||||
|
||||
|
||||
/*! \relates QxtError
|
||||
droping no error inside a function that returns QxtError
|
||||
|
||||
short for return QxtError(__FILE__,__LINE__,Qxt::NoError);
|
||||
*/
|
||||
#define QXT_DROP_OK return QxtError(__FILE__,__LINE__,Qxt::NoError);
|
||||
|
||||
|
||||
/*! \relates QxtError
|
||||
forward a drop
|
||||
|
||||
|
||||
drops from this function if the call inside dropped too.
|
||||
the inner function must return or be a QxtError.
|
||||
|
||||
example
|
||||
\code
|
||||
QXT_DROP_F(critical_function());
|
||||
\endcode
|
||||
|
||||
*/
|
||||
#define QXT_DROP_F(call) {QxtError error_sds = call; if (error_sds != Qxt::NoError ) return error_sds; else (void)0; }
|
||||
|
||||
/*! \relates QxtError
|
||||
check for errors
|
||||
|
||||
example
|
||||
\code
|
||||
QXT_DROP_SCOPE(error,critical_function())
|
||||
{
|
||||
qDebug()<<error;
|
||||
QXT_DROP_F(error);
|
||||
};
|
||||
\endcode
|
||||
|
||||
short for QxtError name = call; if (name != Qxt::NoError )
|
||||
|
||||
\warning: the errors name is valid outside the scope
|
||||
*/
|
||||
#define QXT_DROP_SCOPE(name,call) QxtError name = call; if (name != Qxt::NoError )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class QXT_CORE_EXPORT QxtError
|
||||
{
|
||||
public:
|
||||
QxtError(const char * file, long line, Qxt::ErrorCode errorcode, const char * errorString = 0);
|
||||
Qxt::ErrorCode errorCode() const;
|
||||
long line() const;
|
||||
const char * file() const;
|
||||
const char * errorString() const;
|
||||
operator Qxt::ErrorCode();
|
||||
|
||||
|
||||
private:
|
||||
Qxt::ErrorCode errorcode_m;
|
||||
long line_m;
|
||||
const char * file_m;
|
||||
const char * errorString_m;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,176 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\class QxtFifo
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtFifo class provides a simple loopback QIODevice.
|
||||
|
||||
read and write to the same object
|
||||
emits a readyRead Signal.
|
||||
useful for loopback tests where QBuffer does not work.
|
||||
|
||||
\code
|
||||
QxtFifo fifo;
|
||||
QTextStream (&fifo)<<QString("foo");
|
||||
QString a;
|
||||
QTextStream(&fifo)>>a;
|
||||
qDebug()<<a;
|
||||
\endcode
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "qxtfifo.h"
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <QDebug>
|
||||
#include <QQueue>
|
||||
|
||||
#include <qatomic.h>
|
||||
|
||||
#if QT_VERSION >= 0x040400
|
||||
# include <qbasicatomic.h>
|
||||
# define QXT_EXCHANGE fetchAndStoreOrdered
|
||||
# define QXT_ADD fetchAndAddOrdered
|
||||
#else
|
||||
typedef QBasicAtomic QBasicAtomicInt;
|
||||
# define QXT_EXCHANGE exchange
|
||||
# define QXT_ADD fetchAndAdd
|
||||
#endif
|
||||
|
||||
struct QxtFifoNode {
|
||||
QxtFifoNode(const char* data, int size) : content(data, size) {
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
QByteArray content;
|
||||
QBasicAtomicPointer<QxtFifoNode> next;
|
||||
};
|
||||
|
||||
class QxtFifoPrivate : public QxtPrivate<QxtFifo> {
|
||||
public:
|
||||
QXT_DECLARE_PUBLIC(QxtFifo)
|
||||
QxtFifoPrivate() {
|
||||
head = tail = new QxtFifoNode(NULL, 0);
|
||||
available = 0;
|
||||
}
|
||||
|
||||
QBasicAtomicPointer<QxtFifoNode> head, tail;
|
||||
QBasicAtomicInt available;
|
||||
};
|
||||
|
||||
/*!
|
||||
Constructs a new QxtFifo with \a parent.
|
||||
*/
|
||||
QxtFifo::QxtFifo(QObject *parent) : QIODevice(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtFifo);
|
||||
setOpenMode(QIODevice::ReadWrite);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
qint64 QxtFifo::readData ( char * data, qint64 maxSize )
|
||||
{
|
||||
int bytes = qxt_d().available, step;
|
||||
if(!bytes) return 0;
|
||||
if(bytes > maxSize) bytes = maxSize;
|
||||
int written = bytes;
|
||||
char* writePos = data;
|
||||
QxtFifoNode* node;
|
||||
while(bytes > 0) {
|
||||
node = qxt_d().head;
|
||||
step = node->content.size();
|
||||
if(step >= bytes) {
|
||||
int rem = step - bytes;
|
||||
memcpy(writePos, node->content.constData(), bytes);
|
||||
step = bytes;
|
||||
node->content = node->content.right(rem);
|
||||
} else {
|
||||
memcpy(writePos, node->content.constData(), step);
|
||||
qxt_d().head.QXT_EXCHANGE(node->next);
|
||||
delete node;
|
||||
node = qxt_d().head;
|
||||
}
|
||||
writePos += step;
|
||||
bytes -= step;
|
||||
}
|
||||
qxt_d().available.QXT_ADD(-written);
|
||||
return written;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
qint64 QxtFifo::writeData ( const char * data, qint64 maxSize )
|
||||
{
|
||||
if(maxSize > 0) {
|
||||
if(maxSize > INT_MAX) maxSize = INT_MAX; // qint64 could easily exceed QAtomicInt, so let's play it safe
|
||||
QxtFifoNode* newData = new QxtFifoNode(data, maxSize);
|
||||
qxt_d().tail->next.QXT_EXCHANGE(newData);
|
||||
qxt_d().tail.QXT_EXCHANGE(newData);
|
||||
qxt_d().available.QXT_ADD(maxSize);
|
||||
QMetaObject::invokeMethod(this, "bytesWritten", Qt::QueuedConnection, Q_ARG(qint64, maxSize));
|
||||
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
|
||||
}
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QxtFifo::isSequential () const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
qint64 QxtFifo::bytesAvailable () const
|
||||
{
|
||||
return qxt_d().available;
|
||||
}
|
||||
|
||||
/*!
|
||||
*/
|
||||
void QxtFifo::clear()
|
||||
{
|
||||
qxt_d().available.QXT_EXCHANGE(0);
|
||||
qxt_d().tail.QXT_EXCHANGE(qxt_d().head);
|
||||
QxtFifoNode* node = qxt_d().head->next.QXT_EXCHANGE(NULL);
|
||||
while (node && node->next)
|
||||
{
|
||||
QxtFifoNode* next = node->next.QXT_EXCHANGE(NULL);
|
||||
delete node;
|
||||
node = next;
|
||||
}
|
||||
qxt_d().head->content = QByteArray();
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTFIFO_H
|
||||
#define QXTFIFO_H
|
||||
#include "qxtglobal.h"
|
||||
#include <QIODevice>
|
||||
|
||||
class QxtFifoPrivate;
|
||||
class QXT_CORE_EXPORT QxtFifo : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtFifo(QObject * parent = 0);
|
||||
virtual bool isSequential() const;
|
||||
virtual qint64 bytesAvailable() const;
|
||||
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
virtual qint64 readData(char * data, qint64 maxSize);
|
||||
virtual qint64 writeData(const char * data, qint64 maxSize);
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtFifo)
|
||||
};
|
||||
|
||||
#endif // QXTFIFO_H
|
@ -1,151 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtfilelock.h"
|
||||
#include "qxtfilelock_p.h"
|
||||
/*!
|
||||
* \class QxtFileLock
|
||||
* \inmodule QxtCore
|
||||
* \brief The QxtFileLock class provides a crossplattform way to lock a QFile.
|
||||
*
|
||||
* It supports the range locking of a file. The File will take parentship of the lock.<br>
|
||||
* The lock gets cleaned up with the QFile, and it is released when the QFile is closed.<br>
|
||||
*
|
||||
* Example usage:
|
||||
* \code
|
||||
* off_t lockstart = 0x10;
|
||||
* off_t locklength = 30
|
||||
*
|
||||
* QFile file("test.lock");
|
||||
*
|
||||
* //the lock gets deleted when file is cleaned up
|
||||
* QxtFileLock * writeLock = new QxtFileLock(&file,lockstart,locklength,QxtFileLock::WriteLock);
|
||||
* if(file.open(QIODevice::ReadWrite))
|
||||
* {
|
||||
* if(writeLock->lock())
|
||||
* {
|
||||
* // some write operations
|
||||
* writeLock->unlock();
|
||||
* }
|
||||
* else
|
||||
* //lock failed
|
||||
* }
|
||||
* \endcode
|
||||
* \bold {Note:} QxtFileLock behaves different than normal unix locks on *nix. A thread can writelock the region of a file only ONCE if it uses two different handles.
|
||||
* A different thread can not writelock a region that is owned by a other thread even if it is the SAME process.
|
||||
* \bold {Note:} On *nix this class uses fctnl to lock the file. This may not be compatible to other locking functions like flock and lockf
|
||||
* \bold {Note:} Please do not mix QxtFileLock and native file lock calls on the same QFile. The behaviour is undefined
|
||||
* \bold {Note:} QxtFileLock lives in the same thread as the passed QFile
|
||||
* \warning due to a refactoring issues of QFile this class will not work with Qt from version 4.3.0 to 4.3.2
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \fn bool QxtFileLock::lock()
|
||||
* \brief Locks the file
|
||||
* Returns \c true if succeeds, \c false otherwise.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \fn bool QxtFileLock::unlock()
|
||||
* \brief Unlocks the file.
|
||||
* Returns \c true if succeeds, \c false otherwise.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \enum QxtFileLock::Mode
|
||||
* \brief The mode of the lock
|
||||
*
|
||||
* \value ReadLock A non blocking read lock
|
||||
* \value WriteLock A non blocking write lock
|
||||
* \value ReadLockWait A blocking read lock. The lock() function will block until the lock is created.
|
||||
* \value WriteLockWait A blocking write lock. The lock() function will block until the lock is created.
|
||||
*/
|
||||
|
||||
QxtFileLockPrivate::QxtFileLockPrivate() : offset(0), length(0), mode(QxtFileLock::WriteLockWait), isLocked(false)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* Contructs a new QxtFileLock. The lock is not activated.
|
||||
* \a file the file that should be locked
|
||||
* \a offset the offset where the lock starts
|
||||
* \a length the length of the lock
|
||||
* \a mode the lockmode
|
||||
*/
|
||||
QxtFileLock::QxtFileLock(QFile *file, const off_t offset, const off_t length, const QxtFileLock::Mode mode) : QObject(file)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtFileLock);
|
||||
connect(file, SIGNAL(aboutToClose()), this, SLOT(unlock()));
|
||||
qxt_d().offset = offset;
|
||||
qxt_d().length = length;
|
||||
qxt_d().mode = mode;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destructs the file lock.
|
||||
*/
|
||||
QxtFileLock::~QxtFileLock()
|
||||
{
|
||||
unlock();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the offset of the lock
|
||||
*/
|
||||
off_t QxtFileLock::offset() const
|
||||
{
|
||||
return qxt_d().offset;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns \c true if the lock is active otherwise it returns \c false
|
||||
*/
|
||||
bool QxtFileLock::isActive() const
|
||||
{
|
||||
return qxt_d().isLocked;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the length of the lock
|
||||
*/
|
||||
off_t QxtFileLock::length() const
|
||||
{
|
||||
return qxt_d().length;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the file the lock is created on.
|
||||
*/
|
||||
QFile * QxtFileLock::file() const
|
||||
{
|
||||
return qobject_cast<QFile *>(parent());
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the mode of the lock
|
||||
*/
|
||||
QxtFileLock::Mode QxtFileLock::mode() const
|
||||
{
|
||||
return qxt_d().mode;
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTFILELOCK_H
|
||||
#define QXTFILELOCK_H
|
||||
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include "qxtglobal.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
typedef long off_t;
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
class QxtFileLockPrivate;
|
||||
|
||||
class QXT_CORE_EXPORT QxtFileLock : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
enum Mode
|
||||
{
|
||||
ReadLockWait,
|
||||
ReadLock,
|
||||
WriteLockWait,
|
||||
WriteLock
|
||||
};
|
||||
|
||||
QxtFileLock(QFile *file, const off_t offset, const off_t length, const QxtFileLock::Mode mode = WriteLockWait);
|
||||
~QxtFileLock();
|
||||
|
||||
off_t offset() const;
|
||||
off_t length() const;
|
||||
bool isActive() const;
|
||||
QFile *file() const;
|
||||
QxtFileLock::Mode mode() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
bool lock();
|
||||
bool unlock();
|
||||
|
||||
private:
|
||||
QxtFileLock(const QxtFileLock &other);
|
||||
QXT_DECLARE_PRIVATE(QxtFileLock)
|
||||
};
|
||||
|
||||
#endif // QXTFILELOCK_H
|
@ -1,48 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTFILELOCK_P_H
|
||||
#define QXTFILELOCK_P_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QLinkedList>
|
||||
#include <QPointer>
|
||||
|
||||
class QxtFileLock;
|
||||
|
||||
class QxtFileLockPrivate : public QxtPrivate<QxtFileLock>
|
||||
{
|
||||
public:
|
||||
QxtFileLockPrivate();
|
||||
QXT_DECLARE_PUBLIC(QxtFileLock)
|
||||
|
||||
off_t offset;
|
||||
off_t length;
|
||||
QxtFileLock::Mode mode;
|
||||
bool isLocked;
|
||||
};
|
||||
|
||||
#endif // QXTFILELOCK_P_H
|
@ -1,263 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtfilelock.h"
|
||||
#include "qxtfilelock_p.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
/*include pthread to make errno threadsafe*/
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <QPointer>
|
||||
#include <QMutableLinkedListIterator>
|
||||
#include <QDebug>
|
||||
|
||||
/*!
|
||||
* \internal this class is used on *nix to register all locks created by a process and to let locks on *nix act like locks on windows
|
||||
*/
|
||||
class QxtFileLockRegistry
|
||||
{
|
||||
public:
|
||||
bool registerLock(QxtFileLock *lock);
|
||||
bool removeLock(QxtFileLock *lock);
|
||||
static QxtFileLockRegistry& instance();
|
||||
|
||||
private:
|
||||
QLinkedList < QPointer<QxtFileLock> > procLocks;
|
||||
QMutex registryMutex;
|
||||
QxtFileLockRegistry();
|
||||
};
|
||||
|
||||
QxtFileLockRegistry::QxtFileLockRegistry()
|
||||
{}
|
||||
|
||||
QxtFileLockRegistry& QxtFileLockRegistry::instance()
|
||||
{
|
||||
static QxtFileLockRegistry instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal this function locks the lockregistry and checks if there is a collision between the process locks
|
||||
* \internal if there is no collision it inserts the lock into the registry and returns
|
||||
* \internal return true for success
|
||||
*/
|
||||
bool QxtFileLockRegistry::registerLock(QxtFileLock * lock)
|
||||
{
|
||||
QMutexLocker locker(&this->registryMutex);
|
||||
|
||||
QFile *fileToLock = lock ->file();
|
||||
|
||||
if (fileToLock)
|
||||
{
|
||||
struct stat fileInfo;
|
||||
if (fstat(fileToLock->handle(), &fileInfo) < 0)
|
||||
return false;
|
||||
|
||||
int newLockStart = lock ->offset();
|
||||
int newLockEnd = lock ->offset() + lock ->length();
|
||||
|
||||
QMutableLinkedListIterator< QPointer<QxtFileLock> >iterator(this->procLocks);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
QPointer<QxtFileLock> currLock = iterator.next();
|
||||
if (currLock && currLock->file() && currLock->file()->isOpen())
|
||||
{
|
||||
struct stat currFileInfo;
|
||||
|
||||
/*first check if the current lock is on the same file*/
|
||||
if (fstat(currLock->file()->handle(), &currFileInfo) < 0)
|
||||
{
|
||||
/*that should never happen because a closing file should remove all locks*/
|
||||
Q_ASSERT(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currFileInfo.st_dev == fileInfo.st_dev && currFileInfo.st_ino == fileInfo.st_ino)
|
||||
{
|
||||
/*same file, check if our locks are in conflict*/
|
||||
int currLockStart = currLock->offset();
|
||||
int currLockEnd = currLock->offset() + currLock->length();
|
||||
|
||||
/*do we have to check for threads here?*/
|
||||
if (newLockEnd >= currLockStart && newLockStart <= currLockEnd)
|
||||
{
|
||||
qDebug() << "we may have a collision";
|
||||
qDebug() << newLockEnd << " >= " << currLockStart << " && " << newLockStart << " <= " << currLockEnd;
|
||||
|
||||
/*same lock region if one of both locks are exclusive we have a collision*/
|
||||
if (lock ->mode() == QxtFileLock::WriteLockWait || lock ->mode() == QxtFileLock::WriteLock ||
|
||||
currLock->mode() == QxtFileLock::WriteLockWait || currLock->mode() == QxtFileLock::WriteLock)
|
||||
{
|
||||
qDebug() << "Okay if this is not the same thread using the same handle there is a collision";
|
||||
/*the same thread can lock the same region with the same handle*/
|
||||
|
||||
qDebug() << "! (" << lock ->thread() << " == " << currLock->thread() << " && " << lock ->file()->handle() << " == " << currLock->file()->handle() << ")";
|
||||
|
||||
if (!(lock ->thread() == currLock->thread() && lock ->file()->handle() == currLock->file()->handle()))
|
||||
{
|
||||
qDebug() << "Collision";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else //remove dead locks
|
||||
iterator.remove();
|
||||
}
|
||||
qDebug() << "The lock is okay";
|
||||
/*here we can insert the lock into the list and return*/
|
||||
procLocks.append(QPointer<QxtFileLock>(lock));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QxtFileLockRegistry::removeLock(QxtFileLock * lock)
|
||||
{
|
||||
QMutexLocker locker(&this->registryMutex);
|
||||
procLocks.removeAll(lock);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QxtFileLock::unlock()
|
||||
{
|
||||
if (file() && file()->isOpen() && isActive())
|
||||
{
|
||||
/*first remove real lock*/
|
||||
int lockmode, locktype;
|
||||
int result = -1;
|
||||
struct flock lockDesc;
|
||||
|
||||
lockmode = F_SETLK;
|
||||
locktype = F_UNLCK;
|
||||
|
||||
errno = 0;
|
||||
do
|
||||
{
|
||||
lockDesc.l_type = locktype;
|
||||
lockDesc.l_whence = SEEK_SET;
|
||||
lockDesc.l_start = qxt_d().offset;
|
||||
lockDesc.l_len = qxt_d().length;
|
||||
lockDesc.l_pid = 0;
|
||||
result = fcntl(this->file()->handle(), lockmode, &lockDesc);
|
||||
}
|
||||
while (result && errno == EINTR);
|
||||
|
||||
QxtFileLockRegistry::instance().removeLock(this);
|
||||
qxt_d().isLocked = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QxtFileLock::lock()
|
||||
{
|
||||
if (file() && file()->isOpen() && !isActive())
|
||||
{
|
||||
/*this has to block if we can get no lock*/
|
||||
|
||||
bool locked = false;
|
||||
|
||||
while (1)
|
||||
{
|
||||
locked = QxtFileLockRegistry::instance().registerLock(this);
|
||||
if (locked)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (qxt_d().mode == ReadLockWait || qxt_d().mode == WriteLockWait)
|
||||
usleep(1000 * 5);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*now get real lock*/
|
||||
int lockmode,
|
||||
locktype;
|
||||
|
||||
int result = -1;
|
||||
|
||||
struct flock lockDesc;
|
||||
|
||||
switch (qxt_d().mode)
|
||||
{
|
||||
case ReadLock:
|
||||
lockmode = F_SETLK;
|
||||
locktype = F_RDLCK;
|
||||
break;
|
||||
|
||||
case ReadLockWait:
|
||||
lockmode = F_SETLKW;
|
||||
locktype = F_RDLCK;
|
||||
break;
|
||||
|
||||
case WriteLock:
|
||||
lockmode = F_SETLK;
|
||||
locktype = F_WRLCK;
|
||||
break;
|
||||
|
||||
case WriteLockWait:
|
||||
lockmode = F_SETLKW;
|
||||
locktype = F_WRLCK;
|
||||
break;
|
||||
|
||||
default:
|
||||
QxtFileLockRegistry::instance().removeLock(this);
|
||||
return (false);
|
||||
break;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
do
|
||||
{
|
||||
lockDesc.l_type = locktype;
|
||||
lockDesc.l_whence = SEEK_SET;
|
||||
lockDesc.l_start = qxt_d().offset;
|
||||
lockDesc.l_len = qxt_d().length;
|
||||
lockDesc.l_pid = 0;
|
||||
result = fcntl(this->file()->handle(), lockmode, &lockDesc);
|
||||
}
|
||||
while (result && errno == EINTR);
|
||||
|
||||
/*we dot get the lock unregister from lockregistry and return*/
|
||||
if (result == -1)
|
||||
{
|
||||
QxtFileLockRegistry::instance().removeLock(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
qxt_d().isLocked = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtfilelock.h"
|
||||
#include "qxtfilelock_p.h"
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
|
||||
bool QxtFileLock::unlock()
|
||||
{
|
||||
if (file() && file()->isOpen() && isActive())
|
||||
{
|
||||
HANDLE w32FileHandle;
|
||||
OVERLAPPED ov1;
|
||||
|
||||
w32FileHandle = (HANDLE)_get_osfhandle(file()->handle());
|
||||
if (w32FileHandle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
memset(&ov1, 0, sizeof(ov1));
|
||||
ov1.Offset = qxt_d().offset;
|
||||
|
||||
if (UnlockFileEx(w32FileHandle, 0, qxt_d().length, 0, &ov1))
|
||||
{
|
||||
qxt_d().isLocked = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QxtFileLock::lock()
|
||||
{
|
||||
if (file() && file()->isOpen() && !isActive())
|
||||
{
|
||||
HANDLE w32FileHandle;
|
||||
OVERLAPPED ov1;
|
||||
DWORD dwflags;
|
||||
|
||||
w32FileHandle = (HANDLE)_get_osfhandle(file()->handle());
|
||||
if (w32FileHandle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
switch (qxt_d().mode)
|
||||
{
|
||||
case ReadLock:
|
||||
dwflags = LOCKFILE_FAIL_IMMEDIATELY;
|
||||
break;
|
||||
|
||||
case ReadLockWait:
|
||||
dwflags = 0;
|
||||
break;
|
||||
|
||||
case WriteLock:
|
||||
dwflags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
|
||||
break;
|
||||
|
||||
case WriteLockWait:
|
||||
dwflags = LOCKFILE_EXCLUSIVE_LOCK;
|
||||
break;
|
||||
|
||||
default:
|
||||
return (false);
|
||||
}
|
||||
|
||||
memset(&ov1, 0, sizeof(ov1));
|
||||
ov1.Offset = qxt_d().offset;
|
||||
|
||||
if (LockFileEx(w32FileHandle, dwflags, 0, qxt_d().length, 0, &ov1))
|
||||
{
|
||||
qxt_d().isLocked = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,241 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtglobal.h"
|
||||
|
||||
/*!
|
||||
\headerfile <QxtGlobal>
|
||||
\title Global Qxt Declarations
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The <QxtGlobal> header provides basic declarations and
|
||||
is included by all other Qxt headers.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\macro QXT_VERSION
|
||||
\relates <QxtGlobal>
|
||||
|
||||
This macro expands a numeric value of the form 0xMMNNPP (MM =
|
||||
major, NN = minor, PP = patch) that specifies Qxt's version
|
||||
number. For example, if you compile your application against Qxt
|
||||
0.4.0, the QXT_VERSION macro will expand to 0x000400.
|
||||
|
||||
You can use QXT_VERSION to use the latest Qt features where
|
||||
available. For example:
|
||||
\code
|
||||
#if QXT_VERSION >= 0x000400
|
||||
qxtTabWidget->setTabMovementMode(QxtTabWidget::InPlaceMovement);
|
||||
#endif
|
||||
\endcode
|
||||
|
||||
\sa QXT_VERSION_STR, qxtVersion()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\macro QXT_VERSION_STR
|
||||
\relates <QxtGlobal>
|
||||
|
||||
This macro expands to a string that specifies Qxt's version number
|
||||
(for example, "0.4.0"). This is the version against which the
|
||||
application is compiled.
|
||||
|
||||
\sa qxtVersion(), QXT_VERSION
|
||||
*/
|
||||
|
||||
/*!
|
||||
\relates <QxtGlobal>
|
||||
|
||||
Returns the version number of Qxt at run-time as a string (for
|
||||
example, "0.4.0"). This may be a different version than the
|
||||
version the application was compiled against.
|
||||
|
||||
\sa QXT_VERSION_STR
|
||||
*/
|
||||
const char* qxtVersion()
|
||||
{
|
||||
return QXT_VERSION_STR;
|
||||
}
|
||||
|
||||
/*!
|
||||
\headerfile <QxtPimpl>
|
||||
\title The Qxt private implementation
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The <QxtPimpl> header provides tools for hiding
|
||||
details of a class.
|
||||
|
||||
Application code generally doesn't have to be concerned about hiding its
|
||||
implementation details, but when writing library code it is important to
|
||||
maintain a constant interface, both source and binary. Maintaining a constant
|
||||
source interface is easy enough, but keeping the binary interface constant
|
||||
means moving implementation details into a private class. The PIMPL, or
|
||||
d-pointer, idiom is a common method of implementing this separation. QxtPimpl
|
||||
offers a convenient way to connect the public and private sides of your class.
|
||||
|
||||
\section1 Getting Started
|
||||
Before you declare the public class, you need to make a forward declaration
|
||||
of the private class. The private class must have the same name as the public
|
||||
class, followed by the word Private. For example, a class named MyTest would
|
||||
declare the private class with:
|
||||
\code
|
||||
class MyTestPrivate;
|
||||
\endcode
|
||||
|
||||
\section1 The Public Class
|
||||
Generally, you shouldn't keep any data members in the public class without a
|
||||
good reason. Functions that are part of the public interface should be declared
|
||||
in the public class, and functions that need to be available to subclasses (for
|
||||
calling or overriding) should be in the protected section of the public class.
|
||||
To connect the private class to the public class, include the
|
||||
QXT_DECLARE_PRIVATE macro in the private section of the public class. In the
|
||||
example above, the private class is connected as follows:
|
||||
\code
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(MyTest)
|
||||
\endcode
|
||||
|
||||
Additionally, you must include the QXT_INIT_PRIVATE macro in the public class's
|
||||
constructor. Continuing with the MyTest example, your constructor might look
|
||||
like this:
|
||||
\code
|
||||
MyTest::MyTest() {
|
||||
// initialization
|
||||
QXT_INIT_PRIVATE(MyTest);
|
||||
}
|
||||
\endcode
|
||||
|
||||
\section1 The Private Class
|
||||
As mentioned above, data members should usually be kept in the private class.
|
||||
This allows the memory layout of the private class to change without breaking
|
||||
binary compatibility for the public class. Functions that exist only as
|
||||
implementation details, or functions that need access to private data members,
|
||||
should be implemented here.
|
||||
|
||||
To define the private class, inherit from the template QxtPrivate class, and
|
||||
include the QXT_DECLARE_PUBLIC macro in its public section. The template
|
||||
parameter should be the name of the public class. For example:
|
||||
\code
|
||||
class MyTestPrivate : public QxtPrivate<MyTest> {
|
||||
public:
|
||||
MyTestPrivate();
|
||||
QXT_DECLARE_PUBLIC(MyTest)
|
||||
};
|
||||
\endcode
|
||||
|
||||
\section1 Accessing Private Members
|
||||
Use the qxt_d() function (actually a function-like object) from functions in
|
||||
the public class to access the private class. Similarly, functions in the
|
||||
private class can invoke functions in the public class by using the qxt_p()
|
||||
function (this one's actually a function).
|
||||
|
||||
For example, assume that MyTest has methods named getFoobar and doBaz(),
|
||||
and MyTestPrivate has a member named foobar and a method named doQuux().
|
||||
The code might resemble this example:
|
||||
\code
|
||||
int MyTest::getFoobar() {
|
||||
return qxt_d().foobar;
|
||||
}
|
||||
|
||||
void MyTestPrivate::doQuux() {
|
||||
qxt_p().doBaz(foobar);
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \macro QXT_DECLARE_PRIVATE(PUB)
|
||||
* \relates <QxtPimpl>
|
||||
* Declares that a public class has a related private class.
|
||||
*
|
||||
* This shuold be put in the private section of the public class. The parameter is the name of the public class.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \macro QXT_DECLARE_PUBLIC(PUB)
|
||||
* \relates <QxtPimpl>
|
||||
* Declares that a private class has a related public class.
|
||||
*
|
||||
* This may be put anywhere in the declaration of the private class. The parameter is the name of the public class.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \macro QXT_INIT_PRIVATE(PUB)
|
||||
* \relates <QxtPimpl>
|
||||
* Initializes resources owned by the private class.
|
||||
*
|
||||
* This should be called from the public class's constructor,
|
||||
* before qxt_d() is used for the first time. The parameter is the name of the public class.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \macro QXT_D(PUB)
|
||||
* \relates <QxtPimpl>
|
||||
* Returns a reference in the current scope named "d" to the private class.
|
||||
*
|
||||
* This function is only available in a class using \a QXT_DECLARE_PRIVATE.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \macro QXT_P(PUB)
|
||||
* \relates <QxtPimpl>
|
||||
* Creates a reference in the current scope named "q" to the public class.
|
||||
*
|
||||
* This macro only works in a class using \a QXT_DECLARE_PUBLIC.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \fn QxtPrivate<PUB>& PUB::qxt_d()
|
||||
* \relates <QxtPimpl>
|
||||
* Returns a reference to the private class.
|
||||
*
|
||||
* This function is only available in a class using \a QXT_DECLARE_PRIVATE.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \fn const QxtPrivate<PUB>& PUB::qxt_d() const
|
||||
* \relates <QxtPimpl>
|
||||
* Returns a const reference to the private class.
|
||||
*
|
||||
* This function is only available in a class using \a QXT_DECLARE_PRIVATE.
|
||||
* This overload will be automatically used in const functions.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \fn PUB& QxtPrivate::qxt_p()
|
||||
* \relates <QxtPimpl>
|
||||
* Returns a reference to the public class.
|
||||
*
|
||||
* This function is only available in a class using \a QXT_DECLARE_PUBLIC.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \fn const PUB& QxtPrivate::qxt_p() const
|
||||
* \relates <QxtPimpl>
|
||||
* Returns a const reference to the public class.
|
||||
*
|
||||
* This function is only available in a class using \a QXT_DECLARE_PUBLIC.
|
||||
* This overload will be automatically used in const functions.
|
||||
*/
|
@ -1,207 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTGLOBAL_H
|
||||
#define QXTGLOBAL_H
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#define QXT_VERSION 0x000600
|
||||
#define QXT_VERSION_STR "0.6.0"
|
||||
|
||||
//--------------------------global macros------------------------------
|
||||
|
||||
#ifndef QXT_NO_MACROS
|
||||
|
||||
#endif // QXT_NO_MACROS
|
||||
|
||||
//--------------------------export macros------------------------------
|
||||
|
||||
#define QXT_DLLEXPORT DO_NOT_USE_THIS_ANYMORE
|
||||
|
||||
#if !defined(QXT_STATIC)
|
||||
# if defined(BUILD_QXT_CORE)
|
||||
# define QXT_CORE_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QXT_CORE_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QXT_CORE_EXPORT
|
||||
#endif // BUILD_QXT_CORE
|
||||
|
||||
#if !defined(QXT_STATIC)
|
||||
# if defined(BUILD_QXT_GUI)
|
||||
# define QXT_GUI_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QXT_GUI_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QXT_GUI_EXPORT
|
||||
#endif // BUILD_QXT_GUI
|
||||
|
||||
#if !defined(QXT_STATIC)
|
||||
# if defined(BUILD_QXT_NETWORK)
|
||||
# define QXT_NETWORK_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QXT_NETWORK_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QXT_NETWORK_EXPORT
|
||||
#endif // BUILD_QXT_NETWORK
|
||||
|
||||
#if !defined(QXT_STATIC)
|
||||
# if defined(BUILD_QXT_SQL)
|
||||
# define QXT_SQL_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QXT_SQL_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QXT_SQL_EXPORT
|
||||
#endif // BUILD_QXT_SQL
|
||||
|
||||
#if !defined(QXT_STATIC)
|
||||
# if defined(BUILD_QXT_WEB)
|
||||
# define QXT_WEB_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QXT_WEB_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QXT_WEB_EXPORT
|
||||
#endif // BUILD_QXT_WEB
|
||||
|
||||
#if !defined(QXT_STATIC)
|
||||
# if defined(BUILD_QXT_BERKELEY)
|
||||
# define QXT_BERKELEY_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QXT_BERKELEY_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QXT_BERKELEY_EXPORT
|
||||
#endif // BUILD_QXT_BERKELEY
|
||||
|
||||
#if !defined(QXT_STATIC)
|
||||
# if defined(BUILD_QXT_ZEROCONF)
|
||||
# define QXT_ZEROCONF_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QXT_ZEROCONF_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QXT_ZEROCONF_EXPORT
|
||||
#endif // QXT_ZEROCONF_EXPORT
|
||||
|
||||
#if defined BUILD_QXT_CORE || defined BUILD_QXT_GUI || defined BUILD_QXT_SQL || defined BUILD_QXT_NETWORK || defined BUILD_QXT_WEB || defined BUILD_QXT_BERKELEY || defined BUILD_QXT_ZEROCONF
|
||||
# define BUILD_QXT
|
||||
#endif
|
||||
|
||||
QXT_CORE_EXPORT const char* qxtVersion();
|
||||
|
||||
#ifndef QT_BEGIN_NAMESPACE
|
||||
#define QT_BEGIN_NAMESPACE
|
||||
#endif
|
||||
|
||||
#ifndef QT_END_NAMESPACE
|
||||
#define QT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
#ifndef QT_FORWARD_DECLARE_CLASS
|
||||
#define QT_FORWARD_DECLARE_CLASS(Class) class Class;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
** This file is derived from code bearing the following notice:
|
||||
** The sole author of this file, Adam Higerd, has explicitly disclaimed all
|
||||
** copyright interest and protection for the content within. This file has
|
||||
** been placed in the public domain according to United States copyright
|
||||
** statute and case law. In jurisdictions where this public domain dedication
|
||||
** is not legally recognized, anyone who receives a copy of this file is
|
||||
** permitted to use, modify, duplicate, and redistribute this file, in whole
|
||||
** or in part, with no restrictions or conditions. In these jurisdictions,
|
||||
** this file shall be copyright (C) 2006-2008 by Adam Higerd.
|
||||
****************************************************************************/
|
||||
|
||||
#define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface<PUB, PUB##Private> qxt_d;
|
||||
#define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
|
||||
#define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
|
||||
#define QXT_D(PUB) PUB##Private& d = qxt_d()
|
||||
#define QXT_P(PUB) PUB& p = qxt_p()
|
||||
|
||||
template <typename PUB>
|
||||
class QxtPrivate
|
||||
{
|
||||
public:
|
||||
virtual ~QxtPrivate()
|
||||
{}
|
||||
inline void QXT_setPublic(PUB* pub)
|
||||
{
|
||||
qxt_p_ptr = pub;
|
||||
}
|
||||
|
||||
protected:
|
||||
inline PUB& qxt_p()
|
||||
{
|
||||
return *qxt_p_ptr;
|
||||
}
|
||||
inline const PUB& qxt_p() const
|
||||
{
|
||||
return *qxt_p_ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
PUB* qxt_p_ptr;
|
||||
};
|
||||
|
||||
template <typename PUB, typename PVT>
|
||||
class QxtPrivateInterface
|
||||
{
|
||||
friend class QxtPrivate<PUB>;
|
||||
public:
|
||||
QxtPrivateInterface()
|
||||
{
|
||||
pvt = new PVT;
|
||||
}
|
||||
~QxtPrivateInterface()
|
||||
{
|
||||
delete pvt;
|
||||
}
|
||||
|
||||
inline void setPublic(PUB* pub)
|
||||
{
|
||||
pvt->QXT_setPublic(pub);
|
||||
}
|
||||
inline PVT& operator()()
|
||||
{
|
||||
return *static_cast<PVT*>(pvt);
|
||||
}
|
||||
inline const PVT& operator()() const
|
||||
{
|
||||
return *static_cast<PVT*>(pvt);
|
||||
}
|
||||
private:
|
||||
QxtPrivateInterface(const QxtPrivateInterface&) { }
|
||||
QxtPrivateInterface& operator=(const QxtPrivateInterface&) { }
|
||||
QxtPrivate<PUB>* pvt;
|
||||
};
|
||||
|
||||
#endif // QXT_GLOBAL
|
@ -1,211 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxthmac.h"
|
||||
#include <QtGlobal>
|
||||
|
||||
#if QT_VERSION >= 0x040300
|
||||
|
||||
|
||||
/*
|
||||
\class QxtHmac
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtHmac class calculates keyed-Hash Message Authentication Codes
|
||||
|
||||
HMAC is a well-known algorithm for generating a message authentication code (MAC) that can be used to verify the
|
||||
integrity and authenticity of a message.
|
||||
|
||||
This class requires Qt 4.3.0 or greater.
|
||||
|
||||
To verify a message, the sender creates a MAC using a key, which is a secret known only to the sender and recipient,
|
||||
and the content of the message. This MAC is then sent along with the message. The recipient then creates another MAC
|
||||
using the shared key and the content of the message. If the two codes match, the message is verified.
|
||||
|
||||
HMAC has been used as a password encryption scheme. The final output of the HMAC algorithm depends on the shared key
|
||||
and an inner hash. This inner hash is generated from the message content and the key. To use HMAC as a password
|
||||
scheme, the key should be the username; the message should be the user's password. The authenticating party (for
|
||||
instance, a login server) only needs to store this inner hash generated by the innerHash() function. When requesting
|
||||
authentication, the user calculates a HMAC using this key and message and sends his username and this HMAC to the
|
||||
authenticator. The authenticator can then use verify() using the provided HMAC and the stored inner hash. When using
|
||||
this scheme, the password is never stored or transmitted in plain text.
|
||||
*/
|
||||
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
class QxtHmacPrivate : public QxtPrivate<QxtHmac>
|
||||
{
|
||||
public:
|
||||
QXT_DECLARE_PUBLIC(QxtHmac)
|
||||
QxtHmacPrivate() : ohash(0), ihash(0) {}
|
||||
~QxtHmacPrivate()
|
||||
{
|
||||
// deleting NULL is safe, so no tests are needed here
|
||||
delete ohash;
|
||||
delete ihash;
|
||||
}
|
||||
QCryptographicHash* ohash;
|
||||
QCryptographicHash* ihash;
|
||||
QByteArray opad, ipad, result;
|
||||
QCryptographicHash::Algorithm algorithm;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Constructs a QxtHmac object using the specified algorithm.
|
||||
*/
|
||||
QxtHmac::QxtHmac(QCryptographicHash::Algorithm algorithm)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtHmac);
|
||||
qxt_d().ohash = new QCryptographicHash(algorithm);
|
||||
qxt_d().ihash = new QCryptographicHash(algorithm);
|
||||
qxt_d().algorithm = algorithm;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Sets the shared secret key for the message authentication code.
|
||||
*
|
||||
* Any data that had been processed using addData() will be discarded.
|
||||
*/
|
||||
void QxtHmac::setKey(QByteArray key)
|
||||
{
|
||||
// We make the assumption that all hashes use a 512-bit block size; as of Qt 4.4.0 this is true of all supported hash functions
|
||||
QxtHmacPrivate* d = &qxt_d();
|
||||
d->opad = QByteArray(64, 0x5c);
|
||||
d->ipad = QByteArray(64, 0x36);
|
||||
if (key.size() > 64)
|
||||
{
|
||||
key = QCryptographicHash::hash(key, d->algorithm);
|
||||
}
|
||||
for (int i = key.size() - 1; i >= 0; --i)
|
||||
{
|
||||
d->opad[i] = d->opad[i] ^ key[i];
|
||||
d->ipad[i] = d->ipad[i] ^ key[i];
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Resets the object.
|
||||
*
|
||||
* Any data that had been processed using addData() will be discarded.
|
||||
* The key, if set, will be preserved.
|
||||
*/
|
||||
void QxtHmac::reset()
|
||||
{
|
||||
QxtHmacPrivate* d = &qxt_d();
|
||||
d->ihash->reset();
|
||||
d->ihash->addData(d->ipad);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the inner hash of the HMAC function.
|
||||
*
|
||||
* This hash can be stored in lieu of the shared secret on the authenticating side
|
||||
* and used for verifying an HMAC code. When used in this manner, HMAC can be used
|
||||
* to provide a form of secure password authentication. See the documentation above
|
||||
* for details.
|
||||
*/
|
||||
QByteArray QxtHmac::innerHash() const
|
||||
{
|
||||
return qxt_d().ihash->result();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the authentication code for the message.
|
||||
*/
|
||||
QByteArray QxtHmac::result()
|
||||
{
|
||||
QxtHmacPrivate* d = &qxt_d();
|
||||
Q_ASSERT(d->opad.size());
|
||||
if (d->result.size())
|
||||
return d->result;
|
||||
d->ohash->reset();
|
||||
d->ohash->addData(d->opad);
|
||||
d->ohash->addData(innerHash());
|
||||
d->result = d->ohash->result();
|
||||
return d->result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Verifies the authentication code against a known inner hash.
|
||||
*
|
||||
* \sa innerHash()
|
||||
*/
|
||||
bool QxtHmac::verify(const QByteArray& otherInner)
|
||||
{
|
||||
result(); // populates d->result
|
||||
QxtHmacPrivate* d = &qxt_d();
|
||||
d->ohash->reset();
|
||||
d->ohash->addData(d->opad);
|
||||
d->ohash->addData(otherInner);
|
||||
return d->result == d->ohash->result();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Adds the provided data to the message to be authenticated.
|
||||
*/
|
||||
void QxtHmac::addData(const char* data, int length)
|
||||
{
|
||||
Q_ASSERT(qxt_d().opad.size());
|
||||
qxt_d().ihash->addData(data, length);
|
||||
qxt_d().result.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Adds the provided data to the message to be authenticated.
|
||||
*/
|
||||
void QxtHmac::addData(const QByteArray& data)
|
||||
{
|
||||
addData(data.constData(), data.size());
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the HMAC of the provided data using the specified key and hashing algorithm.
|
||||
*/
|
||||
QByteArray QxtHmac::hash(const QByteArray& key, const QByteArray& data, Algorithm algorithm)
|
||||
{
|
||||
QxtHmac hmac(algorithm);
|
||||
hmac.setKey(key);
|
||||
hmac.addData(data);
|
||||
return hmac.result();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Verifies a HMAC against a known key and inner hash using the specified hashing algorithm.
|
||||
*/
|
||||
bool QxtHmac::verify(const QByteArray& key, const QByteArray& hmac, const QByteArray& inner, Algorithm algorithm)
|
||||
{
|
||||
QxtHmac calc(algorithm);
|
||||
calc.setKey(key);
|
||||
|
||||
QxtHmacPrivate* d = &calc.qxt_d();
|
||||
d->ohash->reset();
|
||||
d->ohash->addData(d->opad);
|
||||
d->ohash->addData(inner);
|
||||
return hmac == d->ohash->result();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,64 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTHMAC_H
|
||||
#define QXTHMAC_H
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#if QT_VERSION < 0x040300
|
||||
# warning QxtHmac requires Qt 4.3.0 or greater
|
||||
#else
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include "qxtglobal.h"
|
||||
|
||||
class QxtHmacPrivate;
|
||||
class QXT_CORE_EXPORT QxtHmac
|
||||
{
|
||||
public:
|
||||
typedef QCryptographicHash::Algorithm Algorithm;
|
||||
|
||||
QxtHmac(QCryptographicHash::Algorithm algorithm);
|
||||
|
||||
void setKey(QByteArray key);
|
||||
void reset();
|
||||
|
||||
void addData(const char* data, int length);
|
||||
void addData(const QByteArray& data);
|
||||
|
||||
QByteArray innerHash() const;
|
||||
QByteArray result();
|
||||
bool verify(const QByteArray& otherInner);
|
||||
|
||||
static QByteArray hash(const QByteArray& key, const QByteArray& data, Algorithm algorithm);
|
||||
static bool verify(const QByteArray& key, const QByteArray& hmac, const QByteArray& inner, Algorithm algorithm);
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtHmac)
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -1,133 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
\class QxtJob
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtJob class executes a job on a QThread. Once or multiple times.
|
||||
|
||||
QxtJob allows easily starting jobs on different threads.
|
||||
exec() will ask for the QThread to run the job on.
|
||||
The Qthread needs an event loop. since version 4.4, QThread has
|
||||
a non pure run function with a default event loop, allowing easy deployment of jobs.
|
||||
|
||||
\code
|
||||
QThread thread;
|
||||
thread.start();
|
||||
LockJob().exec(&thread);
|
||||
\endcode
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
\fn void QxtJob::run()
|
||||
This function is called by QxtJob.
|
||||
reimplemented this function to do useful work.
|
||||
Returning from this method will end the execution of the job.
|
||||
*/
|
||||
|
||||
/*
|
||||
\fn void QxtJob::done()
|
||||
This signal is emitted, when the run() function returns.
|
||||
*/
|
||||
|
||||
#include "qxtjob_p.h"
|
||||
#include <cassert>
|
||||
#include <QThread>
|
||||
|
||||
class Thread : public QThread
|
||||
{
|
||||
public:
|
||||
static void usleep(unsigned long usecs)
|
||||
{
|
||||
QThread::usleep(usecs);
|
||||
}
|
||||
};
|
||||
/*!
|
||||
default constructor
|
||||
*/
|
||||
QxtJob::QxtJob()
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtJob);
|
||||
qxt_d().running.set(false);
|
||||
connect(&qxt_d(), SIGNAL(done()), this, SIGNAL(done()));
|
||||
}
|
||||
/*!
|
||||
execute the Job on \a onthread
|
||||
*/
|
||||
void QxtJob::exec(QThread * onthread)
|
||||
{
|
||||
qxt_d().moveToThread(onthread);
|
||||
connect(this, SIGNAL(subseed()), &qxt_d(), SLOT(inwrap_d()), Qt::QueuedConnection);
|
||||
|
||||
qxt_d().running.set(true);
|
||||
emit(subseed());
|
||||
}
|
||||
/*!
|
||||
\warning The destructor joins. Means it blocks until the job is finished
|
||||
*/
|
||||
QxtJob::~QxtJob()
|
||||
{
|
||||
join();
|
||||
}
|
||||
/*!
|
||||
block until the Job finished
|
||||
Note that the current thread will be blocked.
|
||||
If you use this, you better be damn sure you actually want a thread.
|
||||
Maybe you actualy want to use QxtSignalWaiter.
|
||||
*/
|
||||
void QxtJob::join()
|
||||
{
|
||||
while (qxt_d().running.get() == true)
|
||||
{
|
||||
/*!
|
||||
oh yeah that sucks ass,
|
||||
but since any kind of waitcondition will just fail due to undeterminnism,
|
||||
we have no chance then polling.
|
||||
And no, a mutex won't work either.
|
||||
using join for anything else then testcases sounds kindof retarded anyway.
|
||||
*/
|
||||
Thread::usleep(1000);
|
||||
}
|
||||
|
||||
}
|
||||
void QxtJobPrivate::inwrap_d()
|
||||
{
|
||||
synca.wakeAll();
|
||||
qxt_p().run();
|
||||
running.set(false);
|
||||
emit(done());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTJOB_H
|
||||
#define QXTJOB_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QxtJobPrivate;
|
||||
QT_FORWARD_DECLARE_CLASS(QThread)
|
||||
|
||||
class QXT_CORE_EXPORT QxtJob : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtJob();
|
||||
~QxtJob();
|
||||
void exec(QThread * onthread);
|
||||
void join();
|
||||
protected:
|
||||
virtual void run() = 0;
|
||||
Q_SIGNALS:
|
||||
void done();
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtJob)
|
||||
Q_SIGNALS:
|
||||
///\internal
|
||||
void subseed();
|
||||
};
|
||||
|
||||
#endif // QXTJOB_H
|
@ -1,71 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTJOB_P_H
|
||||
#define QXTJOB_P_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <qxtjob.h>
|
||||
#include <QWaitCondition>
|
||||
|
||||
class QxtJobPrivate : public QObject, public QxtPrivate<QxtJob>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
class RunningState
|
||||
{
|
||||
public:
|
||||
void set(bool a)
|
||||
{
|
||||
mutex.lock();
|
||||
r = a;
|
||||
mutex.unlock();
|
||||
}
|
||||
bool get()
|
||||
{
|
||||
mutex.lock();
|
||||
bool a = r;
|
||||
mutex.unlock();
|
||||
return a;
|
||||
}
|
||||
|
||||
QMutex mutex;
|
||||
bool r;
|
||||
|
||||
} running;
|
||||
|
||||
QXT_DECLARE_PUBLIC(QxtJob)
|
||||
QMutex mutexa;
|
||||
QWaitCondition synca;
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void inwrap_d();
|
||||
Q_SIGNALS:
|
||||
void done();
|
||||
|
||||
};
|
||||
|
||||
#endif // QXTJOB_P_H
|
@ -1,306 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtGui module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
\class QxtJSON
|
||||
\inmodule QxtCore
|
||||
\brief The QxtJSON class implements serializing/deserializing from/to JSON
|
||||
|
||||
implements JSON (JavaScript Object Notation) is a lightweight data-interchange format.
|
||||
see http://www.json.org/
|
||||
|
||||
\section2 Type Conversion
|
||||
\table 80%
|
||||
\header \o JSON Type \o Qt Type
|
||||
\row \o object \o QVariantMap/QVariantHash
|
||||
\row \o array \o QVariantList/QStringList
|
||||
\row \o string \o QString
|
||||
\row \o number \o int,double
|
||||
\row \o true \o bool
|
||||
\row \o false \o bool
|
||||
\row \o null \o QVariant()
|
||||
|
||||
\endtable
|
||||
|
||||
*/
|
||||
|
||||
#include "qxtjson.h"
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
#include <QStringList>
|
||||
|
||||
QString QxtJSON::stringify(QVariant v){
|
||||
if (v.isNull()){
|
||||
return "null";
|
||||
}
|
||||
int t = v.type();
|
||||
if (t == QVariant::String){
|
||||
return "\""+v.toString()+"\"";
|
||||
}
|
||||
else if (t == QVariant::Bool){
|
||||
return v.toBool()?"true":"false";
|
||||
}else if (t == QVariant::Int){
|
||||
return QString::number(v.toInt());
|
||||
}else if (t == QVariant::Double){
|
||||
return QString::number(v.toDouble());
|
||||
}else if (t == QVariant::Map){
|
||||
QString r="{";
|
||||
QMap<QString, QVariant> map = v.toMap();
|
||||
QMapIterator<QString, QVariant> i(map);
|
||||
while (i.hasNext()){
|
||||
i.next();
|
||||
r+="\""+i.key()+"\":"+stringify(i.value())+",";
|
||||
}
|
||||
if(r.length()>1)
|
||||
r.chop(1);
|
||||
r+="}";
|
||||
return r;
|
||||
}else if (t == QVariant::Hash){
|
||||
QString r="{";
|
||||
QHash<QString, QVariant> map = v.toHash();
|
||||
QHashIterator<QString, QVariant> i(map);
|
||||
while (i.hasNext()){
|
||||
i.next();
|
||||
r+="\""+i.key()+"\":"+stringify(i.value())+",";
|
||||
}
|
||||
if(r.length()>1)
|
||||
r.chop(1);
|
||||
r+="}";
|
||||
return r;
|
||||
}else if (t == QVariant::StringList){
|
||||
QString r="[";
|
||||
QStringList l = v.toStringList();
|
||||
foreach(QString i, l){
|
||||
r+="\""+i+"\",";
|
||||
}
|
||||
if(r.length()>1)
|
||||
r.chop(1);
|
||||
r+="]";
|
||||
return r;
|
||||
}else if (t == QVariant::List){
|
||||
QString r="[";
|
||||
QVariantList l = v.toList();
|
||||
foreach(QVariant i, l){
|
||||
r+=stringify(i)+",";
|
||||
}
|
||||
if(r.length()>1)
|
||||
r.chop(1);
|
||||
r+="]";
|
||||
return r;
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
static QVariant parseValue(QTextStream &s,bool & error);
|
||||
static QVariantMap parseObject (QTextStream & s,bool & error);
|
||||
static QVariantList parseArray (QTextStream & s,bool & error);
|
||||
static QString parseString (QTextStream & s,bool & error);
|
||||
static QVariant parseLiteral (QTextStream & s,bool & error);
|
||||
|
||||
QVariant QxtJSON::parse(QString string){
|
||||
QTextStream s(&string);
|
||||
bool error=false;
|
||||
QVariant v=parseValue(s,error);
|
||||
if(error)
|
||||
return QVariant();
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static QVariant parseValue(QTextStream &s,bool & error){
|
||||
s.skipWhiteSpace();
|
||||
QChar c;
|
||||
while(!s.atEnd() && !error){
|
||||
s>>c;
|
||||
if (c=='{'){
|
||||
return parseObject(s,error);
|
||||
} else if (c=='"'){
|
||||
return parseString(s,error);
|
||||
} else if (c=='['){
|
||||
return parseArray(s,error);
|
||||
} else {
|
||||
return parseLiteral(s,error);
|
||||
}
|
||||
s.skipWhiteSpace();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
static QVariantMap parseObject (QTextStream & s,bool & error){
|
||||
s.skipWhiteSpace();
|
||||
QVariantMap o;
|
||||
QString key;
|
||||
bool atVal=false;
|
||||
|
||||
QChar c;
|
||||
while(!s.atEnd() && !error){
|
||||
s>>c;
|
||||
if (c=='}'){
|
||||
return o;
|
||||
} else if (c==',' || c==':'){
|
||||
/*
|
||||
They're syntactic sugar, since key:value come in bundles anyway
|
||||
Could check for error handling. too lazy.
|
||||
*/
|
||||
} else if (c=='"'){
|
||||
if(atVal){
|
||||
o[key]=parseString(s,error);
|
||||
atVal=false;
|
||||
}else{
|
||||
key=parseString(s,error);
|
||||
atVal=true;
|
||||
}
|
||||
} else if (c=='['){
|
||||
if(atVal){
|
||||
o[key]=parseArray(s,error);
|
||||
atVal=false;
|
||||
}else{
|
||||
error=true;
|
||||
return QVariantMap();
|
||||
}
|
||||
} else if (c=='{'){
|
||||
if(atVal){
|
||||
o[key]=parseObject(s,error);
|
||||
atVal=false;
|
||||
}else{
|
||||
error=true;
|
||||
return QVariantMap();
|
||||
}
|
||||
} else {
|
||||
if(atVal){
|
||||
o[key]=parseLiteral(s,error);
|
||||
atVal=false;
|
||||
}else{
|
||||
error=true;
|
||||
return QVariantMap();
|
||||
}
|
||||
}
|
||||
s.skipWhiteSpace();
|
||||
}
|
||||
error=true;
|
||||
return QVariantMap();
|
||||
}
|
||||
static QVariantList parseArray (QTextStream & s,bool & error){
|
||||
s.skipWhiteSpace();
|
||||
QVariantList l;
|
||||
QChar c;
|
||||
while(!s.atEnd() && !error){
|
||||
s>>c;
|
||||
if (c==']'){
|
||||
return l;
|
||||
} else if (c==','){
|
||||
} else if (c=='"'){
|
||||
l.append(parseString(s,error));
|
||||
} else if (c=='['){
|
||||
l.append(parseArray(s,error));
|
||||
} else if (c=='{'){
|
||||
l.append(parseObject(s,error));
|
||||
} else {
|
||||
l.append(parseLiteral(s,error));
|
||||
}
|
||||
s.skipWhiteSpace();
|
||||
}
|
||||
error=true;
|
||||
return QVariantList();
|
||||
}
|
||||
static QString parseString (QTextStream & s,bool & error){
|
||||
QString str;
|
||||
QChar c;
|
||||
while(!s.atEnd() && !error){
|
||||
s>>c;
|
||||
if(c=='"'){
|
||||
return str;
|
||||
}else if(c=='\\'){
|
||||
s>>c;
|
||||
if(c=='b'){
|
||||
str.append('\b');
|
||||
}else if(c=='f'){
|
||||
str.append('\f');
|
||||
}else if(c=='n'){
|
||||
str.append('\n');
|
||||
}else if(c=='r'){
|
||||
str.append('\r');
|
||||
}else if(c=='t'){
|
||||
str.append('\t');
|
||||
}else if(c=='f'){
|
||||
str.append('\f');
|
||||
}else if(c=='u'){
|
||||
short u;
|
||||
s>>u;
|
||||
str.append(QChar(u));
|
||||
}else{
|
||||
str.append(c);
|
||||
}
|
||||
}else{
|
||||
str.append(c);
|
||||
}
|
||||
}
|
||||
error=true;
|
||||
return QString();
|
||||
}
|
||||
static QVariant parseLiteral (QTextStream & s,bool & error){
|
||||
s.seek(s.pos()-1);
|
||||
QChar c;
|
||||
while(!s.atEnd() && !error){
|
||||
s>>c;
|
||||
if (c=='t'){
|
||||
s>>c;//r
|
||||
s>>c;//u
|
||||
s>>c;//e
|
||||
return true;
|
||||
} else if (c=='f'){
|
||||
s>>c;//a
|
||||
s>>c;//l
|
||||
s>>c;//s
|
||||
s>>c;//e
|
||||
return false;
|
||||
}else if (c=='n'){
|
||||
s>>c;//u
|
||||
s>>c;//l
|
||||
s>>c;//l
|
||||
return QVariant();
|
||||
}else if (c=='-' || c.isDigit()){
|
||||
QString n;
|
||||
while(( c.isDigit() || (c=='.') || (c=='E') || (c=='e') || (c=='-') || (c=='+') )){
|
||||
n.append(c);
|
||||
if(s.atEnd() || error)
|
||||
break;
|
||||
s>>c;
|
||||
}
|
||||
s.seek(s.pos()-1);
|
||||
if(n.contains('.')){
|
||||
return n.toDouble();
|
||||
}else{
|
||||
return n.toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
error=true;
|
||||
return QVariant();
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtGui module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTJSON_H
|
||||
#define QXTJSON_H
|
||||
|
||||
#include "qxtglobal.h"
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
class QXT_CORE_EXPORT QxtJSON {
|
||||
public:
|
||||
static QVariant parse (QString string);
|
||||
static QString stringify (QVariant v);
|
||||
};
|
||||
#endif
|
@ -1,113 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtlinesocket_p.h"
|
||||
#include <QIODevice>
|
||||
|
||||
/*!
|
||||
\class QxtLineSocket
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtLineSocket class acts on a QIODevice as baseclass for line-based protocols
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLineSocket::newLineReceived(const QByteArray& line)
|
||||
|
||||
This signal is emitted whenever a new \a line is received.
|
||||
*/
|
||||
|
||||
/*!
|
||||
Constructs a new QxtLineSocket with \a parent.
|
||||
*/
|
||||
QxtLineSocket::QxtLineSocket(QObject* parent) : QObject(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtLineSocket);
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a new QxtLineSocket with \a socket and \a parent.
|
||||
*/
|
||||
QxtLineSocket::QxtLineSocket(QIODevice* socket, QObject* parent) : QObject(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtLineSocket);
|
||||
setSocket(socket);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \a socket.
|
||||
*/
|
||||
void QxtLineSocket::setSocket(QIODevice* socket)
|
||||
{
|
||||
if (qxt_d().socket)
|
||||
disconnect(qxt_d().socket, SIGNAL(readyRead()), &qxt_d(), SLOT(readyRead()));
|
||||
qxt_d().socket = socket;
|
||||
if (qxt_d().socket)
|
||||
connect(qxt_d().socket, SIGNAL(readyRead()), &qxt_d(), SLOT(readyRead()));
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the socket.
|
||||
*/
|
||||
QIODevice* QxtLineSocket::socket() const
|
||||
{
|
||||
return qxt_d().socket;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sends a \a line.
|
||||
*/
|
||||
void QxtLineSocket::sendLine(const QByteArray& line)
|
||||
{
|
||||
QByteArray copy(line);
|
||||
copy.replace(QByteArray("\n"), ""); //krazy:exclude=doublequote_chars
|
||||
qxt_d().socket->write(copy + '\n');
|
||||
}
|
||||
|
||||
/*!
|
||||
This virtual function is called by QxtLineSocket whenever a \a line was received.
|
||||
Reimplement this function when creating a subclass of QxtLineSocket.
|
||||
|
||||
\note The default implementation does nothing.
|
||||
*/
|
||||
void QxtLineSocket::newLine(const QByteArray& line)
|
||||
{
|
||||
Q_UNUSED(line);
|
||||
}
|
||||
|
||||
void QxtLineSocketPrivate::readyRead()
|
||||
{
|
||||
buffer += socket->readAll();
|
||||
|
||||
int i = 0;
|
||||
while ((i = buffer.indexOf('\n')) > -1)
|
||||
{
|
||||
QByteArray line = buffer.left(i);
|
||||
emit qxt_p().newLineReceived(line);
|
||||
qxt_p().newLine(line);
|
||||
buffer = buffer.mid(i + 1);
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTLINESOCKET_H
|
||||
#define QXTLINESOCKET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <qxtglobal.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QIODevice)
|
||||
class QxtLineSocketPrivate;
|
||||
|
||||
class QXT_CORE_EXPORT QxtLineSocket : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QxtLineSocket(QObject* parent = 0);
|
||||
explicit QxtLineSocket(QIODevice* socket, QObject* parent = 0);
|
||||
|
||||
void setSocket(QIODevice* socket);
|
||||
QIODevice* socket() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void sendLine(const QByteArray& line);
|
||||
|
||||
Q_SIGNALS:
|
||||
void newLineReceived(const QByteArray& line);
|
||||
|
||||
protected:
|
||||
virtual void newLine(const QByteArray& line);
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtLineSocket)
|
||||
};
|
||||
|
||||
#endif // QXTLINESOCKET_H
|
@ -1,48 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTLINESOCKET_P_H
|
||||
#define QXTLINESOCKET_P_H
|
||||
|
||||
#include "qxtlinesocket.h"
|
||||
|
||||
class QxtLineSocketPrivate : public QObject, public QxtPrivate<QxtLineSocket>
|
||||
{
|
||||
Q_OBJECT
|
||||
QXT_DECLARE_PUBLIC(QxtLineSocket)
|
||||
|
||||
public:
|
||||
QxtLineSocketPrivate() : socket(0)
|
||||
{
|
||||
}
|
||||
|
||||
QIODevice* socket;
|
||||
QByteArray buffer;
|
||||
|
||||
private Q_SLOTS:
|
||||
void readyRead();
|
||||
};
|
||||
|
||||
#endif // QXTLINESOCKET_P_H
|
@ -1,202 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtlinkedtree.h"
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
\class QxtLinkedTree
|
||||
\inmodule QxtCore
|
||||
\brief The QxtLinkedTree class is a fast container for tree structured data
|
||||
|
||||
this template class can be used to store data easily in a tree structure.
|
||||
Internally it uses the doublelinked list scheme, but adds client/parent links.
|
||||
|
||||
There are no random access functions, you have to use QxtLinkedTree::iterator to access the data.
|
||||
This is very fast and efficient.
|
||||
|
||||
|
||||
\code
|
||||
QxtLinkedTree<int> tree(1);
|
||||
|
||||
QxtLinkedTreeIterator<int> it= tree.root();
|
||||
it.append(34);
|
||||
qDebug()<<it<<it.child(); //returns "1 34"
|
||||
|
||||
\endcode
|
||||
|
||||
In order to be able to store an iterator into other data structures (eg. for QAbstractItemModel or QAbstractXmlNodeModel) functions are provided to create and store a linked item from and into a void pointer.
|
||||
|
||||
\code
|
||||
void * root= tree.toVoid(tree.root());
|
||||
QxtLinkedTreeIterator<int> it= tree.fromVoid(root);
|
||||
\endcode
|
||||
|
||||
|
||||
TODO: {implicitshared}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTree::QxtLinkedTree();
|
||||
constructs a QxtLinkedTree with a default constructed root node.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTree::QxtLinkedTree(T t);
|
||||
constructs a QxtLinkedTree.
|
||||
sets the rootnode to \a t
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTree::~QxtLinkedTree()
|
||||
the destructor deletes all items, when they are no longer referenced by any other instance.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtLinkedTree::clear();
|
||||
deletes all nodes recursively. this might take forever depending on the size of your tree.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTree::root();
|
||||
returns an iterator on the root node
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void * QxtLinkedTree::toVoid (QxtLinkedTreeIterator);
|
||||
get an unique void pointer to be able to stuff an iterator into other structures.
|
||||
You must not do anything else but pass this to fromVoid().
|
||||
the pointer is invalid when the actual data has been removed and passing it to fromVoid will crash. You have been warned.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTree::fromVoid (void *);
|
||||
returns an iterator pre positioned on the item specified with toVoid.
|
||||
passing anything that has not being created by toVoid() will crash.
|
||||
also note that passing invalidated nodes will crash too.
|
||||
Be extremly carefull. It is easy to currupt your data with this!
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QxtLinkedTreeIterator
|
||||
\inmodule QxtCore
|
||||
\brief The QxtLinkedTreeIterator class provides fast access to an QxtLinkedTree
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator::child () const;
|
||||
returns an iterator to the first child item of this or an invalid iterator when there are no children
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator::parent () const;
|
||||
returns an iterator to the parent item of this. or an invalid iterator when this is the root node
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator::previous () const;
|
||||
returns an iterator to the previous item of this or an invalid iterator when this is the first one in the next/previous chain
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator::next () const;
|
||||
returns an iterator to the next item of this in the previous/next chain or an invalid iterator when this is the last one
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QxtLinkedTreeIterator::isValid () const;
|
||||
verfies if this iterator points to a valid location inside the tree
|
||||
an invalid node is decoupled from the iteration. it can not be used for anything anymore.
|
||||
\code
|
||||
QxtLinkedTree<int> tree(1);
|
||||
QxtLinkedTreeIterator<int> it= tree.begin();
|
||||
|
||||
it++; //invalid. there are no siblings.
|
||||
it--; //still invalid!
|
||||
\endcode
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn int QxtLinkedTreeIterator::children() const
|
||||
returns the amount of childnodes.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn T & QxtLinkedTreeIterator::operator* () const;
|
||||
Returns a modifiable reference to the current item.
|
||||
You can change the value of an item by using operator*() on the left side of an assignment, for example:
|
||||
\code
|
||||
if (*it == "Hello")
|
||||
*it = "Bonjour";
|
||||
\endcode
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn T QxtLinkedTreeIterator::operator T () const;
|
||||
returns a copy of the current item.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator:: operator + ( int j ) const;
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator & QxtLinkedTreeIterator::operator ++ ();
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator & QxtLinkedTreeIterator::operator ++ (int);
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator & QxtLinkedTreeIterator::operator += ( int j );
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator::operator - ( int j ) const;
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator & QxtLinkedTreeIterator::operator -- ();
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator & QxtLinkedTreeIterator::operator -- (int);
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator & QxtLinkedTreeIterator::operator -= ( int j );
|
||||
*/
|
||||
/*!
|
||||
\fn bool QxtLinkedTreeIterator::operator== ( const iterator & other ) const;
|
||||
compares
|
||||
*/
|
||||
/*!
|
||||
\fn bool QxtLinkedTreeIterator::operator!= ( const iterator & other ) const;
|
||||
compares
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator::erase () const;
|
||||
deletes the current item. returns an iterator to the next sibling. this instance is then invalid.
|
||||
deleting is recursive. all subitems will be deleted too.
|
||||
*/
|
||||
/*!
|
||||
\fn QxtLinkedTreeIterator QxtLinkedTreeIterator::append (const T & value ) const;
|
||||
appens an item to the children of this item. returns an iterator to the new item.
|
||||
*/
|
@ -1,467 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTLINKEDTREE_H
|
||||
#define QXTLINKEDTREE_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
#include <qxtsharedprivate.h>
|
||||
|
||||
template<class T>
|
||||
class QxtLinkedTree;
|
||||
|
||||
template<class T>
|
||||
class QxtLinkedTreeIterator;
|
||||
|
||||
template<class T>
|
||||
class QXT_CORE_EXPORT QxtLinkedTreeItem
|
||||
{
|
||||
public:
|
||||
~QxtLinkedTreeItem()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
private:
|
||||
QxtLinkedTreeItem(T tt)
|
||||
{
|
||||
t = tt;
|
||||
next = 0;
|
||||
previous = 0;
|
||||
parent = 0;
|
||||
child = 0;
|
||||
childcount = 0;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
if (child)
|
||||
{
|
||||
QxtLinkedTreeItem * c = child;
|
||||
while (c)
|
||||
{
|
||||
QxtLinkedTreeItem * e = c;
|
||||
c = c->next;
|
||||
delete e;
|
||||
}
|
||||
child = 0;
|
||||
}
|
||||
}
|
||||
|
||||
friend class QxtLinkedTree<T>;
|
||||
friend class QxtLinkedTreeIterator<T>;
|
||||
QxtLinkedTreeItem * next;
|
||||
QxtLinkedTreeItem * previous;
|
||||
QxtLinkedTreeItem * parent;
|
||||
QxtLinkedTreeItem * child;
|
||||
int childcount;
|
||||
|
||||
T t;
|
||||
///TODO: somehow notify all iterators when one deletes this. so they can be made invalid instead of undefined.
|
||||
};
|
||||
|
||||
///FIXME: nested would be cooler but c++ has no typdefs with templates and doxygen doesn't undertsand nested templates
|
||||
template<class T>
|
||||
class QXT_CORE_EXPORT QxtLinkedTreeIterator
|
||||
{
|
||||
public:
|
||||
QxtLinkedTreeIterator();
|
||||
QxtLinkedTreeIterator(const QxtLinkedTreeIterator<T> & other);
|
||||
QxtLinkedTreeIterator & operator= (const QxtLinkedTreeIterator<T> & other);
|
||||
|
||||
QxtLinkedTreeIterator parent() const;
|
||||
QxtLinkedTreeIterator next() const;
|
||||
QxtLinkedTreeIterator previous() const;
|
||||
QxtLinkedTreeIterator child() const;
|
||||
|
||||
bool isValid() const;
|
||||
int children() const;
|
||||
|
||||
T & operator*() const;
|
||||
T * operator-> () const;
|
||||
operator T() const;
|
||||
|
||||
QxtLinkedTreeIterator operator + (int j) const;
|
||||
QxtLinkedTreeIterator & operator ++ ();
|
||||
QxtLinkedTreeIterator operator ++ (int);
|
||||
QxtLinkedTreeIterator & operator += (int j);
|
||||
|
||||
QxtLinkedTreeIterator operator - (int j) const;
|
||||
QxtLinkedTreeIterator & operator -- ();
|
||||
QxtLinkedTreeIterator operator -- (int);
|
||||
QxtLinkedTreeIterator & operator -= (int j);
|
||||
|
||||
bool operator== (const QxtLinkedTreeIterator<T> & other) const;
|
||||
bool operator!= (const QxtLinkedTreeIterator<T> & other) const;
|
||||
|
||||
QxtLinkedTreeIterator erase() ;
|
||||
QxtLinkedTreeIterator append(const T & value);
|
||||
QxtLinkedTreeIterator insert(int i, const T & value);
|
||||
|
||||
private:
|
||||
friend class QxtLinkedTree<T>;
|
||||
|
||||
QxtLinkedTreeIterator(QxtLinkedTreeItem<T> * t);
|
||||
QxtLinkedTreeItem<T> *item;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class QXT_CORE_EXPORT QxtLinkedTree
|
||||
{
|
||||
public:
|
||||
|
||||
QxtLinkedTree();
|
||||
QxtLinkedTree(T t);
|
||||
~QxtLinkedTree();
|
||||
void clear();
|
||||
QxtLinkedTreeIterator<T> root();
|
||||
static QxtLinkedTreeIterator<T> fromVoid(void *) ;
|
||||
static void * toVoid(QxtLinkedTreeIterator<T>) ;
|
||||
|
||||
#if 0
|
||||
QxtLinkedTreeIterator insert(iterator before, const T & value);
|
||||
#endif
|
||||
|
||||
private:
|
||||
QxtSharedPrivate< QxtLinkedTreeItem<T> > qxt_d;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T>::QxtLinkedTreeIterator()
|
||||
{
|
||||
item = 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T>::QxtLinkedTreeIterator(const QxtLinkedTreeIterator<T> & other)
|
||||
{
|
||||
item = other.item;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> & QxtLinkedTreeIterator<T>::operator= (const QxtLinkedTreeIterator<T> & other)
|
||||
{
|
||||
item = other.item;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::parent() const
|
||||
{
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "iterator out of range");
|
||||
return QxtLinkedTreeIterator<T>(item->parent);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::next() const
|
||||
{
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "iterator out of range");
|
||||
return QxtLinkedTreeIterator<T>(item->next);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::previous() const
|
||||
{
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "iterator out of range");
|
||||
return QxtLinkedTreeIterator<T>(item->previous);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::child() const
|
||||
{
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "iterator out of range");
|
||||
return QxtLinkedTreeIterator<T>(item->child);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool QxtLinkedTreeIterator<T>::isValid() const
|
||||
{
|
||||
return (item != 0);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int QxtLinkedTreeIterator<T>::children() const
|
||||
{
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "iterator out of range");
|
||||
return item->childcount;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T & QxtLinkedTreeIterator<T>::operator*() const
|
||||
{
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "iterator out of range");
|
||||
return item->t;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T * QxtLinkedTreeIterator<T>::operator-> () const
|
||||
{
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "iterator out of range");
|
||||
return &item->t;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T>::operator T() const
|
||||
{
|
||||
Q_ASSERT_X(item,Q_FUNC_INFO, "iterator out of range");
|
||||
return item->t;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T>::QxtLinkedTreeIterator(QxtLinkedTreeItem<T> * t)
|
||||
{
|
||||
item = t;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::operator + (int j) const
|
||||
{
|
||||
QxtLinkedTreeItem<T> * m = item;
|
||||
for (int i = 0;i < j;i++)
|
||||
{
|
||||
m = m->next;
|
||||
if (m == 0)
|
||||
return QxtLinkedTreeIterator<T>();
|
||||
}
|
||||
return QxtLinkedTreeIterator<T>(m);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> & QxtLinkedTreeIterator<T>::operator ++ () /*prefix*/
|
||||
{
|
||||
*this = QxtLinkedTreeIterator<T>(item->next);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::operator ++ (int) /*postfix*/
|
||||
{
|
||||
QxtLinkedTreeIterator<T> d(*this);
|
||||
*this = QxtLinkedTreeIterator<T>(item->next);
|
||||
return d;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> & QxtLinkedTreeIterator<T>::operator += (int j)
|
||||
{
|
||||
*this = *this + j;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::operator - (int j) const
|
||||
{
|
||||
QxtLinkedTreeItem<T> * m = item;
|
||||
for (int i = 0;i < j;i++)
|
||||
{
|
||||
m = m->previous;
|
||||
if (m == 0)
|
||||
return QxtLinkedTreeIterator<T>();
|
||||
}
|
||||
return QxtLinkedTreeIterator<T>(m);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> & QxtLinkedTreeIterator<T>::operator -- () /*prefix*/
|
||||
{
|
||||
*this = QxtLinkedTreeIterator<T>(item->previous);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::operator -- (int) /*postfix*/
|
||||
{
|
||||
QxtLinkedTreeIterator<T> d(*this);
|
||||
*this = QxtLinkedTreeIterator<T>(item->previous);
|
||||
return d;
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> & QxtLinkedTreeIterator<T>::operator -= (int j)
|
||||
{
|
||||
*this = *this - j;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool QxtLinkedTreeIterator<T>::operator== (const QxtLinkedTreeIterator<T> & other) const
|
||||
{
|
||||
return (other.item == item);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool QxtLinkedTreeIterator<T>::operator!= (const QxtLinkedTreeIterator<T> & other) const
|
||||
{
|
||||
return (other.item != item);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::erase()
|
||||
{
|
||||
QxtLinkedTreeItem <T> *node = item;
|
||||
Q_ASSERT_X(item, Q_FUNC_INFO, "can't erase invalid node.");
|
||||
QxtLinkedTreeItem <T> *parent = item->parent;
|
||||
Q_ASSERT_X(parent, Q_FUNC_INFO, "erasing root node not supported.");
|
||||
QxtLinkedTreeItem <T> *next = node->next;
|
||||
|
||||
///delete children
|
||||
QxtLinkedTreeIterator<T> ci = child();
|
||||
while (ci.isValid())
|
||||
{
|
||||
ci = ci.erase();
|
||||
}
|
||||
|
||||
///realign chains
|
||||
if (parent->child == node)
|
||||
{
|
||||
parent->child = node->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
QxtLinkedTreeItem <T> * n = parent->child;
|
||||
while (n->next != node)
|
||||
{
|
||||
Q_ASSERT_X(n->next != 0, Q_FUNC_INFO, "reached end of chain and didn't find the node requested for removal.");
|
||||
n = n->next;
|
||||
}
|
||||
n->next = node->next;
|
||||
}
|
||||
parent->childcount--;
|
||||
delete node;
|
||||
item = 0;
|
||||
return QxtLinkedTreeIterator<T>(next);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::append(const T & value)
|
||||
{
|
||||
QxtLinkedTreeItem <T> * parent = item;
|
||||
Q_ASSERT_X(parent, Q_FUNC_INFO, "invalid iterator");
|
||||
|
||||
QxtLinkedTreeItem<T> *node = new QxtLinkedTreeItem<T>(value);
|
||||
|
||||
if (parent->child == 0)
|
||||
{
|
||||
parent->child = node;
|
||||
node->parent = parent;
|
||||
node->previous = 0;
|
||||
parent->childcount = 1;
|
||||
return QxtLinkedTreeIterator<T>(node);
|
||||
}
|
||||
|
||||
QxtLinkedTreeItem <T> * n = parent->child;
|
||||
while (n->next != 0)
|
||||
n = n->next;
|
||||
n->next = node;
|
||||
node->parent = parent;
|
||||
node->previous = n;
|
||||
parent->childcount++;
|
||||
return QxtLinkedTreeIterator<T>(node);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTreeIterator<T>::insert(int i, const T & value)
|
||||
{
|
||||
QxtLinkedTreeItem <T> * parent = item;
|
||||
Q_ASSERT_X(parent, Q_FUNC_INFO, "invalid iterator");
|
||||
|
||||
|
||||
Q_ASSERT_X(i <= children(), Q_FUNC_INFO, "cannot insert out of range");
|
||||
|
||||
|
||||
if (parent->child == 0 || i == children())
|
||||
{
|
||||
return append(value);
|
||||
}
|
||||
|
||||
QxtLinkedTreeItem<T> *node = new QxtLinkedTreeItem<T>(value);
|
||||
|
||||
QxtLinkedTreeItem <T> * n = parent->child;
|
||||
|
||||
while (i-- > 0)
|
||||
{
|
||||
n = n->next;
|
||||
Q_ASSERT_X(n, Q_FUNC_INFO, "out of range");
|
||||
}
|
||||
if (n->previous)
|
||||
{
|
||||
n->previous->next = node;
|
||||
node->previous = n->previous;
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_ASSERT_X(parent->child == n, Q_FUNC_INFO, "corupted linked tree");
|
||||
parent->child = node;
|
||||
node->previous = 0;
|
||||
}
|
||||
node->next = n;
|
||||
n->previous = node;
|
||||
node->parent = parent;
|
||||
parent->childcount++;
|
||||
return QxtLinkedTreeIterator<T>(node);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTree<T>::QxtLinkedTree(T t)
|
||||
{
|
||||
qxt_d = new QxtLinkedTreeItem<T>(t);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTree<T>::QxtLinkedTree()
|
||||
{
|
||||
qxt_d = new QxtLinkedTreeItem<T>(T());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTree<T>::~QxtLinkedTree()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void QxtLinkedTree<T>::clear()
|
||||
{
|
||||
qxt_d().clear();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTree<T>::fromVoid(void * d)
|
||||
{
|
||||
return QxtLinkedTreeIterator<T>(reinterpret_cast<QxtLinkedTreeItem<T> *>(d));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void * QxtLinkedTree<T>::toVoid(QxtLinkedTreeIterator<T> n)
|
||||
{
|
||||
return reinterpret_cast<void*>(n.item);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QxtLinkedTreeIterator<T> QxtLinkedTree<T>::root()
|
||||
{
|
||||
return QxtLinkedTreeIterator<T>(&qxt_d());
|
||||
}
|
||||
|
||||
#endif // QXTLINKEDTREE_H
|
@ -1,152 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtlocale.h"
|
||||
#include "qxtlocale_data_p.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
/*!
|
||||
\class QxtLocale
|
||||
\inmodule QxtCore
|
||||
\brief The QxtLocale class has some additional data and functionality, missing in QLocale.
|
||||
|
||||
QxtLocale defines currencies and continents. Methods are available to
|
||||
gather various mappings and information.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QxtLocale::Continent
|
||||
|
||||
This enumerated type is used to specify a language.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QxtLocale::Currency
|
||||
|
||||
This enumerated type is used to specify a currency.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QxtLocale::currencyToCode(Currency currency)
|
||||
|
||||
This static method returns the 3-letter code for the given \a currency.
|
||||
*/
|
||||
QString QxtLocale::currencyToCode(Currency currency)
|
||||
{
|
||||
QString code;
|
||||
code.resize(3);
|
||||
const unsigned char *c = currency_code_list + 3 * (uint(currency));
|
||||
code[0] = ushort(c[0]);
|
||||
code[1] = ushort(c[1]);
|
||||
code[2] = ushort(c[2]);
|
||||
return code;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QxtLocale::countryToISO2Letter(QLocale::Country country)
|
||||
|
||||
This static method returns the 2-letter ISO 3166 code for the given \a country.
|
||||
*/
|
||||
QString QxtLocale::countryToISO2Letter(QLocale::Country country)
|
||||
{
|
||||
if (country == QLocale::AnyCountry)
|
||||
return QString();
|
||||
|
||||
QString code;
|
||||
code.resize(2);
|
||||
const unsigned char *c = two_letter_country_code_list + 2 * (uint(country));
|
||||
code[0] = ushort(c[0]);
|
||||
code[1] = ushort(c[1]);
|
||||
return code;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QxtLocale::countryToISO3Letter(QLocale::Country country)
|
||||
|
||||
This static method returns the 3-letter ISO 3166 code for the given \a country.
|
||||
*/
|
||||
QString QxtLocale::countryToISO3Letter(QLocale::Country country)
|
||||
{
|
||||
if (country == QLocale::AnyCountry)
|
||||
return QString();
|
||||
|
||||
QString code;
|
||||
code.resize(3);
|
||||
const unsigned char *c = three_letter_country_code_list + 3 * (uint(country));
|
||||
code[0] = ushort(c[0]);
|
||||
code[1] = ushort(c[1]);
|
||||
code[2] = ushort(c[2]);
|
||||
return code;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QxtLocale::currencyToName(Currency currency)
|
||||
|
||||
This static method returns the translated name for given \a currency.
|
||||
*/
|
||||
QString QxtLocale::currencyToName(Currency currency)
|
||||
{
|
||||
return QCoreApplication::instance()->translate("QxtLocale", currency_names[currency]);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QxtLocale::currencyForCountry(QLocale::Country country)
|
||||
|
||||
This static method returns the currency for the given \a country.
|
||||
*/
|
||||
QxtLocale::Currency QxtLocale::currencyForCountry(QLocale::Country country)
|
||||
{
|
||||
return currency_for_country_list[country];
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QxtLocale::currencyToSymbol(Currency currency)
|
||||
|
||||
This static method returns the symbol for the given \a currency.
|
||||
*/
|
||||
QString QxtLocale::currencyToSymbol(Currency currency)
|
||||
{
|
||||
QChar* data = symbol_for_country_list[currency];
|
||||
int size = data[0].cell();
|
||||
return QString(data + 1, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QxtLocale::continentToName(Continent continent)
|
||||
|
||||
This static method returns the translated name for the given \a continent.
|
||||
*/
|
||||
QString QxtLocale::continentToName(Continent continent)
|
||||
{
|
||||
return QCoreApplication::instance()->translate("QxtLocale", continent_names[continent]);
|
||||
}
|
||||
|
||||
/*!
|
||||
This static method returns the continent for the given \a country.
|
||||
*/
|
||||
QxtLocale::Continent QxtLocale::continentForCountry(QLocale::Country country)
|
||||
{
|
||||
return continent_for_country_list[country];
|
||||
}
|
@ -1,236 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTLOCALE_H
|
||||
#define QXTLOCALE_H
|
||||
#include <QLocale>
|
||||
#include <QObject>
|
||||
#include <qxtglobal.h>
|
||||
|
||||
class QXT_CORE_EXPORT QxtLocale
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(Currency Continent)
|
||||
public:
|
||||
|
||||
enum Currency
|
||||
{
|
||||
NoCurrency = 0,
|
||||
Afghani = 1,
|
||||
AlgerianDinar = 2,
|
||||
ArgentinePeso = 3,
|
||||
ArmenianDram = 4,
|
||||
ArubanGuilder = 5,
|
||||
AustralianDollar = 6,
|
||||
AzerbaijanianManat = 7,
|
||||
BahamianDollar = 8,
|
||||
BahrainiDinar = 9,
|
||||
Baht = 10,
|
||||
Balboa = 11,
|
||||
BarbadosDollar = 12,
|
||||
BelarussianRuble = 13,
|
||||
BelizeDollar = 14,
|
||||
BermudianDollar = 15,
|
||||
BolivarFuerte = 16,
|
||||
Boliviano = 17,
|
||||
BrazilianReal = 18,
|
||||
BruneiDollar = 19,
|
||||
BulgarianLev = 20,
|
||||
BurundiFranc = 21,
|
||||
CFAFrancBCEAO = 22,
|
||||
CFAFrancBEAC = 23,
|
||||
CFPFranc = 24,
|
||||
CanadianDollar = 25,
|
||||
CapeVerdeEscudo = 26,
|
||||
CaymanIslandsDollar = 27,
|
||||
ChileanPeso = 28,
|
||||
ColombianPeso = 29,
|
||||
ComoroFranc = 30,
|
||||
ConvertibleMarks = 31,
|
||||
CordobaOro = 32,
|
||||
CostaRicanColon = 33,
|
||||
CroatianKuna = 34,
|
||||
CubanPeso = 35,
|
||||
CyprusPound = 36,
|
||||
CzechKoruna = 37,
|
||||
Dalasi = 38,
|
||||
DanishKrone = 39,
|
||||
Denar = 40,
|
||||
DjiboutiFranc = 41,
|
||||
Dobra = 42,
|
||||
DominicanPeso = 43,
|
||||
Dong = 44,
|
||||
EastCaribbeanDollar = 45,
|
||||
EgyptianPound = 46,
|
||||
ElSalvadorColon = 47,
|
||||
EthiopianBirr = 48,
|
||||
Euro = 49,
|
||||
FalklandIslandsPound = 50,
|
||||
FijiDollar = 51,
|
||||
Forint = 52,
|
||||
FrancCongolais = 53,
|
||||
GhanaCedi = 54,
|
||||
GibraltarPound = 55,
|
||||
Gourde = 56,
|
||||
Guarani = 57,
|
||||
GuineaBissauPeso = 58,
|
||||
GuineaFranc = 59,
|
||||
GuyanaDollar = 60,
|
||||
HongKongDollar = 61,
|
||||
Hryvnia = 62,
|
||||
IcelandKrona = 63,
|
||||
IndianRupee = 64,
|
||||
IranianRial = 65,
|
||||
IraqiDinar = 66,
|
||||
JamaicanDollar = 67,
|
||||
JordanianDinar = 68,
|
||||
KenyanShilling = 69,
|
||||
Kina = 70,
|
||||
Kip = 71,
|
||||
Kroon = 72,
|
||||
KuwaitiDinar = 73,
|
||||
Kwanza = 74,
|
||||
Kyat = 75,
|
||||
Lari = 76,
|
||||
LatvianLats = 77,
|
||||
LebanesePound = 78,
|
||||
Lek = 79,
|
||||
Lempira = 80,
|
||||
Leone = 81,
|
||||
LiberianDollar = 82,
|
||||
LibyanDinar = 83,
|
||||
Lilangeni = 84,
|
||||
LithuanianLitas = 85,
|
||||
Loti = 86,
|
||||
MalagasyAriary = 87,
|
||||
MalawiKwacha = 88,
|
||||
MalaysianRinggit = 89,
|
||||
MalteseLira = 90,
|
||||
Manat = 91,
|
||||
MauritiusRupee = 92,
|
||||
Metical = 93,
|
||||
MexicanPeso = 94,
|
||||
MexicanUnidadDeInversion = 95,
|
||||
MoldovanLeu = 96,
|
||||
MoroccanDirham = 97,
|
||||
Mvdol = 98,
|
||||
Naira = 99,
|
||||
Nakfa = 100,
|
||||
NamibiaDollar = 101,
|
||||
NepaleseRupee = 102,
|
||||
NetherlandsAntillianGuilder = 103,
|
||||
NewIsraeliSheqel = 104,
|
||||
NewLeu = 105,
|
||||
NewTaiwanDollar = 106,
|
||||
NewTurkishLira = 107,
|
||||
NewZealandDollar = 108,
|
||||
Ngultrum = 109,
|
||||
NorthKoreanWon = 110,
|
||||
NorwegianKrone = 111,
|
||||
NuevoSol = 112,
|
||||
Ouguiya = 113,
|
||||
Paanga = 114,
|
||||
PakistanRupee = 115,
|
||||
Pataca = 116,
|
||||
PesoUruguayo = 117,
|
||||
PhilippinePeso = 118,
|
||||
PoundSterling = 119,
|
||||
Pula = 120,
|
||||
QatariRial = 121,
|
||||
Quetzal = 122,
|
||||
Rand = 123,
|
||||
RialOmani = 124,
|
||||
Riel = 125,
|
||||
Rufiyaa = 126,
|
||||
Rupiah = 127,
|
||||
RussianRuble = 128,
|
||||
RwandaFranc = 129,
|
||||
SaintHelenaPound = 130,
|
||||
SaudiRiyal = 131,
|
||||
SerbianDinar = 132,
|
||||
SeychellesRupee = 133,
|
||||
SingaporeDollar = 134,
|
||||
SlovakKoruna = 135,
|
||||
SolomonIslandsDollar = 136,
|
||||
Som = 137,
|
||||
SomaliShilling = 138,
|
||||
Somoni = 139,
|
||||
SriLankaRupee = 140,
|
||||
SudanesePound = 141,
|
||||
SurinamDollar = 142,
|
||||
SwedishKrona = 143,
|
||||
SwissFranc = 144,
|
||||
SyrianPound = 145,
|
||||
Taka = 146,
|
||||
Tala = 147,
|
||||
TanzanianShilling = 148,
|
||||
Tenge = 149,
|
||||
TrinidadAndTobagoDollar = 150,
|
||||
Tugrik = 151,
|
||||
TunisianDinar = 152,
|
||||
UAEDirham = 153,
|
||||
USDollar = 154,
|
||||
UgandaShilling = 155,
|
||||
UnidadDeValorReal = 156,
|
||||
UnidadesDeFomento = 157,
|
||||
UruguayPesoEnUnidadesIndexadas = 158,
|
||||
UzbekistanSum = 159,
|
||||
Vatu = 160,
|
||||
Won = 161,
|
||||
YemeniRial = 162,
|
||||
Yen = 163,
|
||||
YuanRenminbi = 164,
|
||||
ZambiaKwacha = 165,
|
||||
ZimbabweDollar = 166,
|
||||
Zloty = 167,
|
||||
LastCurrency = Zloty
|
||||
};
|
||||
|
||||
enum Continent
|
||||
{
|
||||
None = 0,
|
||||
NorthAmerica = 1,
|
||||
SouthAmerica = 2,
|
||||
Europe = 3,
|
||||
Africa = 4,
|
||||
Asia = 5,
|
||||
Australia = 6,
|
||||
Antarctica = 7,
|
||||
LastContinent = Antarctica
|
||||
};
|
||||
|
||||
static QString countryToISO2Letter(QLocale::Country country);
|
||||
static QString countryToISO3Letter(QLocale::Country country);
|
||||
|
||||
static Currency currencyForCountry(QLocale::Country country);
|
||||
static QString currencyToCode(Currency currency);
|
||||
static QString currencyToName(Currency currency);
|
||||
static QString currencyToSymbol(Currency currency);
|
||||
|
||||
static QString continentToName(Continent continent);
|
||||
static Continent continentForCountry(QLocale::Country country);
|
||||
};
|
||||
|
||||
#endif // QXTLOCALE_H
|
@ -1,1532 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
//
|
||||
// Generated on Fri Aug 14 00:10:57 2009
|
||||
// for Qt 4.5.2
|
||||
//
|
||||
|
||||
#ifndef QXTLOCALE_DATA_P_H
|
||||
#define QXTLOCALE_DATA_P_H
|
||||
#include <QObject>
|
||||
#include <QChar>
|
||||
static const unsigned char two_letter_country_code_list[] =
|
||||
" " // Default
|
||||
"AF" // Afghanistan
|
||||
"AL" // Albania
|
||||
"DZ" // Algeria
|
||||
"AS" // AmericanSamoa
|
||||
"AD" // Andorra
|
||||
"AO" // Angola
|
||||
"AI" // Anguilla
|
||||
"AQ" // Antarctica
|
||||
"AG" // AntiguaAndBarbuda
|
||||
"AR" // Argentina
|
||||
"AM" // Armenia
|
||||
"AW" // Aruba
|
||||
"AU" // Australia
|
||||
"AT" // Austria
|
||||
"AZ" // Azerbaijan
|
||||
"BS" // Bahamas
|
||||
"BH" // Bahrain
|
||||
"BD" // Bangladesh
|
||||
"BB" // Barbados
|
||||
"BY" // Belarus
|
||||
"BE" // Belgium
|
||||
"BZ" // Belize
|
||||
"BJ" // Benin
|
||||
"BM" // Bermuda
|
||||
"BT" // Bhutan
|
||||
"BO" // Bolivia
|
||||
"BA" // BosniaAndHerzegowina
|
||||
"BW" // Botswana
|
||||
"BV" // BouvetIsland
|
||||
"BR" // Brazil
|
||||
"IO" // BritishIndianOceanTerritory
|
||||
"BN" // BruneiDarussalam
|
||||
"BG" // Bulgaria
|
||||
"BF" // BurkinaFaso
|
||||
"BI" // Burundi
|
||||
"KH" // Cambodia
|
||||
"CM" // Cameroon
|
||||
"CA" // Canada
|
||||
"CV" // CapeVerde
|
||||
"KY" // CaymanIslands
|
||||
"CF" // CentralAfricanRepublic
|
||||
"TD" // Chad
|
||||
"CL" // Chile
|
||||
"CN" // China
|
||||
"CX" // ChristmasIsland
|
||||
"CC" // CocosIslands
|
||||
"CO" // Colombia
|
||||
"KM" // Comoros
|
||||
"CD" // DemocraticRepublicOfCongo
|
||||
"CG" // PeoplesRepublicOfCongo
|
||||
"CK" // CookIslands
|
||||
"CR" // CostaRica
|
||||
"CI" // IvoryCoast
|
||||
"HR" // Croatia
|
||||
"CU" // Cuba
|
||||
"CY" // Cyprus
|
||||
"CZ" // CzechRepublic
|
||||
"DK" // Denmark
|
||||
"DJ" // Djibouti
|
||||
"DM" // Dominica
|
||||
"DO" // DominicanRepublic
|
||||
"TL" // EastTimor
|
||||
"EC" // Ecuador
|
||||
"EG" // Egypt
|
||||
"SV" // ElSalvador
|
||||
"GQ" // EquatorialGuinea
|
||||
"ER" // Eritrea
|
||||
"EE" // Estonia
|
||||
"ET" // Ethiopia
|
||||
"FK" // FalklandIslands
|
||||
"FO" // FaroeIslands
|
||||
"FJ" // Fiji
|
||||
"FI" // Finland
|
||||
"FR" // France
|
||||
"FX" // MetropolitanFrance
|
||||
"GF" // FrenchGuiana
|
||||
"PF" // FrenchPolynesia
|
||||
"TF" // FrenchSouthernTerritories
|
||||
"GA" // Gabon
|
||||
"GM" // Gambia
|
||||
"GE" // Georgia
|
||||
"DE" // Germany
|
||||
"GH" // Ghana
|
||||
"GI" // Gibraltar
|
||||
"GR" // Greece
|
||||
"GL" // Greenland
|
||||
"GD" // Grenada
|
||||
"GP" // Guadeloupe
|
||||
"GU" // Guam
|
||||
"GT" // Guatemala
|
||||
"GN" // Guinea
|
||||
"GW" // GuineaBissau
|
||||
"GY" // Guyana
|
||||
"HT" // Haiti
|
||||
"HM" // HeardAndMcDonaldIslands
|
||||
"HN" // Honduras
|
||||
"HK" // HongKong
|
||||
"HU" // Hungary
|
||||
"IS" // Iceland
|
||||
"IN" // India
|
||||
"ID" // Indonesia
|
||||
"IR" // Iran
|
||||
"IQ" // Iraq
|
||||
"IE" // Ireland
|
||||
"IL" // Israel
|
||||
"IT" // Italy
|
||||
"JM" // Jamaica
|
||||
"JP" // Japan
|
||||
"JO" // Jordan
|
||||
"KZ" // Kazakhstan
|
||||
"KE" // Kenya
|
||||
"KI" // Kiribati
|
||||
"KP" // DemocraticRepublicOfKorea
|
||||
"KR" // RepublicOfKorea
|
||||
"KW" // Kuwait
|
||||
"KG" // Kyrgyzstan
|
||||
"LA" // Lao
|
||||
"LV" // Latvia
|
||||
"LB" // Lebanon
|
||||
"LS" // Lesotho
|
||||
"LR" // Liberia
|
||||
"LY" // LibyanArabJamahiriya
|
||||
"LI" // Liechtenstein
|
||||
"LT" // Lithuania
|
||||
"LU" // Luxembourg
|
||||
"MO" // Macau
|
||||
"MK" // Macedonia
|
||||
"MG" // Madagascar
|
||||
"MW" // Malawi
|
||||
"MY" // Malaysia
|
||||
"MV" // Maldives
|
||||
"ML" // Mali
|
||||
"MT" // Malta
|
||||
"MH" // MarshallIslands
|
||||
"MQ" // Martinique
|
||||
"MR" // Mauritania
|
||||
"MU" // Mauritius
|
||||
"YT" // Mayotte
|
||||
"MX" // Mexico
|
||||
"FM" // Micronesia
|
||||
"MD" // Moldova
|
||||
"MC" // Monaco
|
||||
"MN" // Mongolia
|
||||
"MS" // Montserrat
|
||||
"MA" // Morocco
|
||||
"MZ" // Mozambique
|
||||
"MM" // Myanmar
|
||||
"NA" // Namibia
|
||||
"NR" // Nauru
|
||||
"NP" // Nepal
|
||||
"NL" // Netherlands
|
||||
"AN" // NetherlandsAntilles
|
||||
"NC" // NewCaledonia
|
||||
"NZ" // NewZealand
|
||||
"NI" // Nicaragua
|
||||
"NE" // Niger
|
||||
"NG" // Nigeria
|
||||
"NU" // Niue
|
||||
"NF" // NorfolkIsland
|
||||
"MP" // NorthernMarianaIslands
|
||||
"NO" // Norway
|
||||
"OM" // Oman
|
||||
"PK" // Pakistan
|
||||
"PW" // Palau
|
||||
"PS" // PalestinianTerritory
|
||||
"PA" // Panama
|
||||
"PG" // PapuaNewGuinea
|
||||
"PY" // Paraguay
|
||||
"PE" // Peru
|
||||
"PH" // Philippines
|
||||
"PN" // Pitcairn
|
||||
"PL" // Poland
|
||||
"PT" // Portugal
|
||||
"PR" // PuertoRico
|
||||
"QA" // Qatar
|
||||
"RE" // Reunion
|
||||
"RO" // Romania
|
||||
"RU" // RussianFederation
|
||||
"RW" // Rwanda
|
||||
"KN" // SaintKittsAndNevis
|
||||
"LC" // StLucia
|
||||
"VC" // StVincentAndTheGrenadines
|
||||
"WS" // Samoa
|
||||
"SM" // SanMarino
|
||||
"ST" // SaoTomeAndPrincipe
|
||||
"SA" // SaudiArabia
|
||||
"SN" // Senegal
|
||||
"SC" // Seychelles
|
||||
"SL" // SierraLeone
|
||||
"SG" // Singapore
|
||||
"SK" // Slovakia
|
||||
"SI" // Slovenia
|
||||
"SB" // SolomonIslands
|
||||
"SO" // Somalia
|
||||
"ZA" // SouthAfrica
|
||||
"GS" // SouthGeorgiaAndTheSouthSandwichIslands
|
||||
"ES" // Spain
|
||||
"LK" // SriLanka
|
||||
"SH" // StHelena
|
||||
"PM" // StPierreAndMiquelon
|
||||
"SD" // Sudan
|
||||
"SR" // Suriname
|
||||
"SJ" // SvalbardAndJanMayenIslands
|
||||
"SZ" // Swaziland
|
||||
"SE" // Sweden
|
||||
"CH" // Switzerland
|
||||
"SY" // SyrianArabRepublic
|
||||
"TW" // Taiwan
|
||||
"TJ" // Tajikistan
|
||||
"TZ" // Tanzania
|
||||
"TH" // Thailand
|
||||
"TG" // Togo
|
||||
"TK" // Tokelau
|
||||
"TO" // Tonga
|
||||
"TT" // TrinidadAndTobago
|
||||
"TN" // Tunisia
|
||||
"TR" // Turkey
|
||||
"TM" // Turkmenistan
|
||||
"TC" // TurksAndCaicosIslands
|
||||
"TV" // Tuvalu
|
||||
"UG" // Uganda
|
||||
"UA" // Ukraine
|
||||
"AE" // UnitedArabEmirates
|
||||
"GB" // UnitedKingdom
|
||||
"US" // UnitedStates
|
||||
"UM" // UnitedStatesMinorOutlyingIslands
|
||||
"UY" // Uruguay
|
||||
"UZ" // Uzbekistan
|
||||
"VU" // Vanuatu
|
||||
"VA" // VaticanCityState
|
||||
"VE" // Venezuela
|
||||
"VN" // VietNam
|
||||
"VG" // BritishVirginIslands
|
||||
"VI" // USVirginIslands
|
||||
"WF" // WallisAndFutunaIslands
|
||||
"EH" // WesternSahara
|
||||
"YE" // Yemen
|
||||
"YU" // Yugoslavia
|
||||
"ZM" // Zambia
|
||||
"ZW" // Zimbabwe
|
||||
"CS" // SerbiaAndMontenegro
|
||||
;
|
||||
static const unsigned char three_letter_country_code_list[] =
|
||||
" " // Default
|
||||
"AFG" // Afghanistan
|
||||
"ALB" // Albania
|
||||
"DZA" // Algeria
|
||||
"ASM" // AmericanSamoa
|
||||
"AND" // Andorra
|
||||
"AGO" // Angola
|
||||
"AIA" // Anguilla
|
||||
"ATA" // Antarctica
|
||||
"ATG" // AntiguaAndBarbuda
|
||||
"ARG" // Argentina
|
||||
"ARM" // Armenia
|
||||
"ABW" // Aruba
|
||||
"AUS" // Australia
|
||||
"AUT" // Austria
|
||||
"AZE" // Azerbaijan
|
||||
"BHS" // Bahamas
|
||||
"BHR" // Bahrain
|
||||
"BGD" // Bangladesh
|
||||
"BRB" // Barbados
|
||||
"BLR" // Belarus
|
||||
"BEL" // Belgium
|
||||
"BLZ" // Belize
|
||||
"BEN" // Benin
|
||||
"BMU" // Bermuda
|
||||
"BTN" // Bhutan
|
||||
"BOL" // Bolivia
|
||||
"BIH" // BosniaAndHerzegowina
|
||||
"BWA" // Botswana
|
||||
"BVT" // BouvetIsland
|
||||
"BRA" // Brazil
|
||||
"IOT" // BritishIndianOceanTerritory
|
||||
"BRN" // BruneiDarussalam
|
||||
"BGR" // Bulgaria
|
||||
"BFA" // BurkinaFaso
|
||||
"BDI" // Burundi
|
||||
"KHM" // Cambodia
|
||||
"CMR" // Cameroon
|
||||
"CAN" // Canada
|
||||
"CPV" // CapeVerde
|
||||
"CYM" // CaymanIslands
|
||||
"CAF" // CentralAfricanRepublic
|
||||
"TCD" // Chad
|
||||
"CHL" // Chile
|
||||
"CHN" // China
|
||||
"CXR" // ChristmasIsland
|
||||
"CCK" // CocosIslands
|
||||
"COL" // Colombia
|
||||
"COM" // Comoros
|
||||
"COD" // DemocraticRepublicOfCongo
|
||||
"COG" // PeoplesRepublicOfCongo
|
||||
"COK" // CookIslands
|
||||
"CRI" // CostaRica
|
||||
"CIV" // IvoryCoast
|
||||
"HRV" // Croatia
|
||||
"CUB" // Cuba
|
||||
"CYP" // Cyprus
|
||||
"CZE" // CzechRepublic
|
||||
"DNK" // Denmark
|
||||
"DJI" // Djibouti
|
||||
"DMA" // Dominica
|
||||
"DOM" // DominicanRepublic
|
||||
"TLS" // EastTimor
|
||||
"ECU" // Ecuador
|
||||
"EGY" // Egypt
|
||||
"SLV" // ElSalvador
|
||||
"GNQ" // EquatorialGuinea
|
||||
"ERI" // Eritrea
|
||||
"EST" // Estonia
|
||||
"ETH" // Ethiopia
|
||||
"FLK" // FalklandIslands
|
||||
"FRO" // FaroeIslands
|
||||
"FJI" // Fiji
|
||||
"FIN" // Finland
|
||||
"FRA" // France
|
||||
"FX." // MetropolitanFrance
|
||||
"GUF" // FrenchGuiana
|
||||
"PYF" // FrenchPolynesia
|
||||
"ATF" // FrenchSouthernTerritories
|
||||
"GAB" // Gabon
|
||||
"GMB" // Gambia
|
||||
"GEO" // Georgia
|
||||
"DEU" // Germany
|
||||
"GHA" // Ghana
|
||||
"GIB" // Gibraltar
|
||||
"GRC" // Greece
|
||||
"GRL" // Greenland
|
||||
"GRD" // Grenada
|
||||
"GLP" // Guadeloupe
|
||||
"GUM" // Guam
|
||||
"GTM" // Guatemala
|
||||
"GIN" // Guinea
|
||||
"GNB" // GuineaBissau
|
||||
"GUY" // Guyana
|
||||
"HTI" // Haiti
|
||||
"HMD" // HeardAndMcDonaldIslands
|
||||
"HND" // Honduras
|
||||
"HKG" // HongKong
|
||||
"HUN" // Hungary
|
||||
"ISL" // Iceland
|
||||
"IND" // India
|
||||
"IDN" // Indonesia
|
||||
"IRN" // Iran
|
||||
"IRQ" // Iraq
|
||||
"IRL" // Ireland
|
||||
"ISR" // Israel
|
||||
"ITA" // Italy
|
||||
"JAM" // Jamaica
|
||||
"JPN" // Japan
|
||||
"JOR" // Jordan
|
||||
"KAZ" // Kazakhstan
|
||||
"KEN" // Kenya
|
||||
"KIR" // Kiribati
|
||||
"PRK" // DemocraticRepublicOfKorea
|
||||
"KOR" // RepublicOfKorea
|
||||
"KWT" // Kuwait
|
||||
"KGZ" // Kyrgyzstan
|
||||
"LAO" // Lao
|
||||
"LVA" // Latvia
|
||||
"LBN" // Lebanon
|
||||
"LSO" // Lesotho
|
||||
"LBR" // Liberia
|
||||
"LBY" // LibyanArabJamahiriya
|
||||
"LIE" // Liechtenstein
|
||||
"LTU" // Lithuania
|
||||
"LUX" // Luxembourg
|
||||
"MAC" // Macau
|
||||
"MKD" // Macedonia
|
||||
"MDG" // Madagascar
|
||||
"MWI" // Malawi
|
||||
"MYS" // Malaysia
|
||||
"MDV" // Maldives
|
||||
"MLI" // Mali
|
||||
"MLT" // Malta
|
||||
"MHL" // MarshallIslands
|
||||
"MTQ" // Martinique
|
||||
"MRT" // Mauritania
|
||||
"MUS" // Mauritius
|
||||
"MYT" // Mayotte
|
||||
"MEX" // Mexico
|
||||
"FSM" // Micronesia
|
||||
"MDA" // Moldova
|
||||
"MCO" // Monaco
|
||||
"MNG" // Mongolia
|
||||
"MSR" // Montserrat
|
||||
"MAR" // Morocco
|
||||
"MOZ" // Mozambique
|
||||
"MMR" // Myanmar
|
||||
"NAM" // Namibia
|
||||
"NRU" // Nauru
|
||||
"NPL" // Nepal
|
||||
"NLD" // Netherlands
|
||||
"ANT" // NetherlandsAntilles
|
||||
"NCL" // NewCaledonia
|
||||
"NZL" // NewZealand
|
||||
"NIC" // Nicaragua
|
||||
"NER" // Niger
|
||||
"NGA" // Nigeria
|
||||
"NIU" // Niue
|
||||
"NFK" // NorfolkIsland
|
||||
"MNP" // NorthernMarianaIslands
|
||||
"NOR" // Norway
|
||||
"OMN" // Oman
|
||||
"PAK" // Pakistan
|
||||
"PLW" // Palau
|
||||
"PSE" // PalestinianTerritory
|
||||
"PAN" // Panama
|
||||
"PNG" // PapuaNewGuinea
|
||||
"PRY" // Paraguay
|
||||
"PER" // Peru
|
||||
"PHL" // Philippines
|
||||
"PCN" // Pitcairn
|
||||
"POL" // Poland
|
||||
"PRT" // Portugal
|
||||
"PRI" // PuertoRico
|
||||
"QAT" // Qatar
|
||||
"REU" // Reunion
|
||||
"ROU" // Romania
|
||||
"RUS" // RussianFederation
|
||||
"RWA" // Rwanda
|
||||
"KNA" // SaintKittsAndNevis
|
||||
"LCA" // StLucia
|
||||
"VCT" // StVincentAndTheGrenadines
|
||||
"WSM" // Samoa
|
||||
"SMR" // SanMarino
|
||||
"STP" // SaoTomeAndPrincipe
|
||||
"SAU" // SaudiArabia
|
||||
"SEN" // Senegal
|
||||
"SYC" // Seychelles
|
||||
"SLE" // SierraLeone
|
||||
"SGP" // Singapore
|
||||
"SVK" // Slovakia
|
||||
"SVN" // Slovenia
|
||||
"SLB" // SolomonIslands
|
||||
"SOM" // Somalia
|
||||
"ZAF" // SouthAfrica
|
||||
"SGS" // SouthGeorgiaAndTheSouthSandwichIslands
|
||||
"ESP" // Spain
|
||||
"LKA" // SriLanka
|
||||
"SHN" // StHelena
|
||||
"SPM" // StPierreAndMiquelon
|
||||
"SDN" // Sudan
|
||||
"SUR" // Suriname
|
||||
"SJM" // SvalbardAndJanMayenIslands
|
||||
"SWZ" // Swaziland
|
||||
"SWE" // Sweden
|
||||
"CHE" // Switzerland
|
||||
"SYR" // SyrianArabRepublic
|
||||
"TWN" // Taiwan
|
||||
"TJK" // Tajikistan
|
||||
"TZA" // Tanzania
|
||||
"THA" // Thailand
|
||||
"TGO" // Togo
|
||||
"TKL" // Tokelau
|
||||
"TON" // Tonga
|
||||
"TTO" // TrinidadAndTobago
|
||||
"TUN" // Tunisia
|
||||
"TUR" // Turkey
|
||||
"TKM" // Turkmenistan
|
||||
"TCA" // TurksAndCaicosIslands
|
||||
"TUV" // Tuvalu
|
||||
"UGA" // Uganda
|
||||
"UKR" // Ukraine
|
||||
"ARE" // UnitedArabEmirates
|
||||
"GBR" // UnitedKingdom
|
||||
"USA" // UnitedStates
|
||||
"UMI" // UnitedStatesMinorOutlyingIslands
|
||||
"URY" // Uruguay
|
||||
"UZB" // Uzbekistan
|
||||
"VUT" // Vanuatu
|
||||
"VAT" // VaticanCityState
|
||||
"VEN" // Venezuela
|
||||
"VNM" // VietNam
|
||||
"VGB" // BritishVirginIslands
|
||||
"VIR" // USVirginIslands
|
||||
"WLF" // WallisAndFutunaIslands
|
||||
"ESH" // WesternSahara
|
||||
"YEM" // Yemen
|
||||
"YUG" // Yugoslavia
|
||||
"ZMB" // Zambia
|
||||
"ZWE" // Zimbabwe
|
||||
"SRB" // SerbiaAndMontenegro
|
||||
;
|
||||
static QxtLocale::Currency currency_for_country_list[] = {
|
||||
QxtLocale::NoCurrency, // Default
|
||||
QxtLocale::Afghani, // Afghanistan
|
||||
QxtLocale::Lek, // Albania
|
||||
QxtLocale::AlgerianDinar, // Algeria
|
||||
QxtLocale::USDollar, // AmericanSamoa
|
||||
QxtLocale::Euro, // Andorra
|
||||
QxtLocale::Kwanza, // Angola
|
||||
QxtLocale::EastCaribbeanDollar, // Anguilla
|
||||
QxtLocale::NoCurrency, // Antarctica
|
||||
QxtLocale::EastCaribbeanDollar, // AntiguaAndBarbuda
|
||||
QxtLocale::ArgentinePeso, // Argentina
|
||||
QxtLocale::ArmenianDram, // Armenia
|
||||
QxtLocale::ArubanGuilder, // Aruba
|
||||
QxtLocale::AustralianDollar, // Australia
|
||||
QxtLocale::Euro, // Austria
|
||||
QxtLocale::AzerbaijanianManat, // Azerbaijan
|
||||
QxtLocale::BahamianDollar, // Bahamas
|
||||
QxtLocale::BahrainiDinar, // Bahrain
|
||||
QxtLocale::Taka, // Bangladesh
|
||||
QxtLocale::BarbadosDollar, // Barbados
|
||||
QxtLocale::BelarussianRuble, // Belarus
|
||||
QxtLocale::Euro, // Belgium
|
||||
QxtLocale::BelizeDollar, // Belize
|
||||
QxtLocale::CFAFrancBCEAO, // Benin
|
||||
QxtLocale::BermudianDollar, // Bermuda
|
||||
QxtLocale::IndianRupee, // Bhutan
|
||||
QxtLocale::Boliviano, // Bolivia
|
||||
QxtLocale::ConvertibleMarks, // BosniaAndHerzegowina
|
||||
QxtLocale::Pula, // Botswana
|
||||
QxtLocale::NorwegianKrone, // BouvetIsland
|
||||
QxtLocale::BrazilianReal, // Brazil
|
||||
QxtLocale::USDollar, // BritishIndianOceanTerritory
|
||||
QxtLocale::BruneiDollar, // BruneiDarussalam
|
||||
QxtLocale::BulgarianLev, // Bulgaria
|
||||
QxtLocale::CFAFrancBCEAO, // BurkinaFaso
|
||||
QxtLocale::BurundiFranc, // Burundi
|
||||
QxtLocale::Riel, // Cambodia
|
||||
QxtLocale::CFAFrancBEAC, // Cameroon
|
||||
QxtLocale::CanadianDollar, // Canada
|
||||
QxtLocale::CapeVerdeEscudo, // CapeVerde
|
||||
QxtLocale::CaymanIslandsDollar, // CaymanIslands
|
||||
QxtLocale::CFAFrancBEAC, // CentralAfricanRepublic
|
||||
QxtLocale::CFAFrancBEAC, // Chad
|
||||
QxtLocale::ChileanPeso, // Chile
|
||||
QxtLocale::YuanRenminbi, // China
|
||||
QxtLocale::AustralianDollar, // ChristmasIsland
|
||||
QxtLocale::AustralianDollar, // CocosIslands
|
||||
QxtLocale::ColombianPeso, // Colombia
|
||||
QxtLocale::ComoroFranc, // Comoros
|
||||
QxtLocale::CFAFrancBEAC, // DemocraticRepublicOfCongo
|
||||
QxtLocale::CFAFrancBEAC, // PeoplesRepublicOfCongo
|
||||
QxtLocale::NewZealandDollar, // CookIslands
|
||||
QxtLocale::CostaRicanColon, // CostaRica
|
||||
QxtLocale::CFAFrancBCEAO, // IvoryCoast
|
||||
QxtLocale::CroatianKuna, // Croatia
|
||||
QxtLocale::CubanPeso, // Cuba
|
||||
QxtLocale::CyprusPound, // Cyprus
|
||||
QxtLocale::CzechKoruna, // CzechRepublic
|
||||
QxtLocale::DanishKrone, // Denmark
|
||||
QxtLocale::DjiboutiFranc, // Djibouti
|
||||
QxtLocale::EastCaribbeanDollar, // Dominica
|
||||
QxtLocale::EastCaribbeanDollar, // DominicanRepublic
|
||||
QxtLocale::USDollar, // EastTimor
|
||||
QxtLocale::USDollar, // Ecuador
|
||||
QxtLocale::EgyptianPound, // Egypt
|
||||
QxtLocale::ElSalvadorColon, // ElSalvador
|
||||
QxtLocale::CFAFrancBEAC, // EquatorialGuinea
|
||||
QxtLocale::Nakfa, // Eritrea
|
||||
QxtLocale::Kroon, // Estonia
|
||||
QxtLocale::EthiopianBirr, // Ethiopia
|
||||
QxtLocale::FalklandIslandsPound, // FalklandIslands
|
||||
QxtLocale::DanishKrone, // FaroeIslands
|
||||
QxtLocale::FijiDollar, // Fiji
|
||||
QxtLocale::Euro, // Finland
|
||||
QxtLocale::Euro, // France
|
||||
QxtLocale::Euro, // MetropolitanFrance
|
||||
QxtLocale::Euro, // FrenchGuiana
|
||||
QxtLocale::CFPFranc, // FrenchPolynesia
|
||||
QxtLocale::Euro, // FrenchSouthernTerritories
|
||||
QxtLocale::CFAFrancBEAC, // Gabon
|
||||
QxtLocale::Dalasi, // Gambia
|
||||
QxtLocale::Lari, // Georgia
|
||||
QxtLocale::Euro, // Germany
|
||||
QxtLocale::GhanaCedi, // Ghana
|
||||
QxtLocale::GibraltarPound, // Gibraltar
|
||||
QxtLocale::Euro, // Greece
|
||||
QxtLocale::DanishKrone, // Greenland
|
||||
QxtLocale::EastCaribbeanDollar, // Grenada
|
||||
QxtLocale::Euro, // Guadeloupe
|
||||
QxtLocale::USDollar, // Guam
|
||||
QxtLocale::Quetzal, // Guatemala
|
||||
QxtLocale::CFAFrancBEAC, // Guinea
|
||||
QxtLocale::GuineaFranc, // GuineaBissau
|
||||
QxtLocale::GuyanaDollar, // Guyana
|
||||
QxtLocale::Gourde, // Haiti
|
||||
QxtLocale::AustralianDollar, // HeardAndMcDonaldIslands
|
||||
QxtLocale::Lempira, // Honduras
|
||||
QxtLocale::HongKongDollar, // HongKong
|
||||
QxtLocale::Forint, // Hungary
|
||||
QxtLocale::IcelandKrona, // Iceland
|
||||
QxtLocale::IndianRupee, // India
|
||||
QxtLocale::Rupiah, // Indonesia
|
||||
QxtLocale::IranianRial, // Iran
|
||||
QxtLocale::IraqiDinar, // Iraq
|
||||
QxtLocale::Euro, // Ireland
|
||||
QxtLocale::NewIsraeliSheqel, // Israel
|
||||
QxtLocale::Euro, // Italy
|
||||
QxtLocale::JamaicanDollar, // Jamaica
|
||||
QxtLocale::Yen, // Japan
|
||||
QxtLocale::JordanianDinar, // Jordan
|
||||
QxtLocale::Tenge, // Kazakhstan
|
||||
QxtLocale::KenyanShilling, // Kenya
|
||||
QxtLocale::AustralianDollar, // Kiribati
|
||||
QxtLocale::Won, // DemocraticRepublicOfKorea
|
||||
QxtLocale::NorthKoreanWon, // RepublicOfKorea
|
||||
QxtLocale::KuwaitiDinar, // Kuwait
|
||||
QxtLocale::Som, // Kyrgyzstan
|
||||
QxtLocale::Kip, // Lao
|
||||
QxtLocale::LatvianLats, // Latvia
|
||||
QxtLocale::LebanesePound, // Lebanon
|
||||
QxtLocale::Rand, // Lesotho
|
||||
QxtLocale::LiberianDollar, // Liberia
|
||||
QxtLocale::LibyanDinar, // LibyanArabJamahiriya
|
||||
QxtLocale::SwissFranc, // Liechtenstein
|
||||
QxtLocale::LithuanianLitas, // Lithuania
|
||||
QxtLocale::Euro, // Luxembourg
|
||||
QxtLocale::Pataca, // Macau
|
||||
QxtLocale::Denar, // Macedonia
|
||||
QxtLocale::MalagasyAriary, // Madagascar
|
||||
QxtLocale::MalawiKwacha, // Malawi
|
||||
QxtLocale::MalaysianRinggit, // Malaysia
|
||||
QxtLocale::Rufiyaa, // Maldives
|
||||
QxtLocale::CFAFrancBCEAO, // Mali
|
||||
QxtLocale::MalteseLira, // Malta
|
||||
QxtLocale::USDollar, // MarshallIslands
|
||||
QxtLocale::Euro, // Martinique
|
||||
QxtLocale::Ouguiya, // Mauritania
|
||||
QxtLocale::MauritiusRupee, // Mauritius
|
||||
QxtLocale::Euro, // Mayotte
|
||||
QxtLocale::MexicanPeso, // Mexico
|
||||
QxtLocale::USDollar, // Micronesia
|
||||
QxtLocale::MoldovanLeu, // Moldova
|
||||
QxtLocale::Euro, // Monaco
|
||||
QxtLocale::Tugrik, // Mongolia
|
||||
QxtLocale::EastCaribbeanDollar, // Montserrat
|
||||
QxtLocale::MoroccanDirham, // Morocco
|
||||
QxtLocale::Metical, // Mozambique
|
||||
QxtLocale::Kyat, // Myanmar
|
||||
QxtLocale::Rand, // Namibia
|
||||
QxtLocale::AustralianDollar, // Nauru
|
||||
QxtLocale::NepaleseRupee, // Nepal
|
||||
QxtLocale::Euro, // Netherlands
|
||||
QxtLocale::Euro, // NetherlandsAntilles
|
||||
QxtLocale::CFPFranc, // NewCaledonia
|
||||
QxtLocale::NewZealandDollar, // NewZealand
|
||||
QxtLocale::CordobaOro, // Nicaragua
|
||||
QxtLocale::CFAFrancBCEAO, // Niger
|
||||
QxtLocale::CFAFrancBCEAO, // Nigeria
|
||||
QxtLocale::NewZealandDollar, // Niue
|
||||
QxtLocale::AustralianDollar, // NorfolkIsland
|
||||
QxtLocale::USDollar, // NorthernMarianaIslands
|
||||
QxtLocale::NorwegianKrone, // Norway
|
||||
QxtLocale::RialOmani, // Oman
|
||||
QxtLocale::PakistanRupee, // Pakistan
|
||||
QxtLocale::USDollar, // Palau
|
||||
QxtLocale::NewIsraeliSheqel, // PalestinianTerritory
|
||||
QxtLocale::Balboa, // Panama
|
||||
QxtLocale::GuineaFranc, // PapuaNewGuinea
|
||||
QxtLocale::Guarani, // Paraguay
|
||||
QxtLocale::NuevoSol, // Peru
|
||||
QxtLocale::PhilippinePeso, // Philippines
|
||||
QxtLocale::NewZealandDollar, // Pitcairn
|
||||
QxtLocale::Zloty, // Poland
|
||||
QxtLocale::Euro, // Portugal
|
||||
QxtLocale::USDollar, // PuertoRico
|
||||
QxtLocale::QatariRial, // Qatar
|
||||
QxtLocale::Euro, // Reunion
|
||||
QxtLocale::NewLeu, // Romania
|
||||
QxtLocale::RussianRuble, // RussianFederation
|
||||
QxtLocale::RwandaFranc, // Rwanda
|
||||
QxtLocale::EastCaribbeanDollar, // SaintKittsAndNevis
|
||||
QxtLocale::EastCaribbeanDollar, // StLucia
|
||||
QxtLocale::EastCaribbeanDollar, // StVincentAndTheGrenadines
|
||||
QxtLocale::USDollar, // Samoa
|
||||
QxtLocale::Euro, // SanMarino
|
||||
QxtLocale::Dobra, // SaoTomeAndPrincipe
|
||||
QxtLocale::SaudiRiyal, // SaudiArabia
|
||||
QxtLocale::CFAFrancBCEAO, // Senegal
|
||||
QxtLocale::SeychellesRupee, // Seychelles
|
||||
QxtLocale::Leone, // SierraLeone
|
||||
QxtLocale::SingaporeDollar, // Singapore
|
||||
QxtLocale::SlovakKoruna, // Slovakia
|
||||
QxtLocale::Euro, // Slovenia
|
||||
QxtLocale::SolomonIslandsDollar, // SolomonIslands
|
||||
QxtLocale::SomaliShilling, // Somalia
|
||||
QxtLocale::Rand, // SouthAfrica
|
||||
QxtLocale::PoundSterling, // SouthGeorgiaAndTheSouthSandwichIslands
|
||||
QxtLocale::Euro, // Spain
|
||||
QxtLocale::SriLankaRupee, // SriLanka
|
||||
QxtLocale::SaintHelenaPound, // StHelena
|
||||
QxtLocale::Euro, // StPierreAndMiquelon
|
||||
QxtLocale::SudanesePound, // Sudan
|
||||
QxtLocale::SurinamDollar, // Suriname
|
||||
QxtLocale::NorwegianKrone, // SvalbardAndJanMayenIslands
|
||||
QxtLocale::Lilangeni, // Swaziland
|
||||
QxtLocale::SwedishKrona, // Sweden
|
||||
QxtLocale::SwissFranc, // Switzerland
|
||||
QxtLocale::SyrianPound, // SyrianArabRepublic
|
||||
QxtLocale::NewTaiwanDollar, // Taiwan
|
||||
QxtLocale::Somoni, // Tajikistan
|
||||
QxtLocale::TanzanianShilling, // Tanzania
|
||||
QxtLocale::Baht, // Thailand
|
||||
QxtLocale::CFAFrancBCEAO, // Togo
|
||||
QxtLocale::NewZealandDollar, // Tokelau
|
||||
QxtLocale::Paanga, // Tonga
|
||||
QxtLocale::TrinidadAndTobagoDollar, // TrinidadAndTobago
|
||||
QxtLocale::TunisianDinar, // Tunisia
|
||||
QxtLocale::NewTurkishLira, // Turkey
|
||||
QxtLocale::Manat, // Turkmenistan
|
||||
QxtLocale::USDollar, // TurksAndCaicosIslands
|
||||
QxtLocale::AustralianDollar, // Tuvalu
|
||||
QxtLocale::UgandaShilling, // Uganda
|
||||
QxtLocale::Hryvnia, // Ukraine
|
||||
QxtLocale::UAEDirham, // UnitedArabEmirates
|
||||
QxtLocale::PoundSterling, // UnitedKingdom
|
||||
QxtLocale::USDollar, // UnitedStates
|
||||
QxtLocale::USDollar, // UnitedStatesMinorOutlyingIslands
|
||||
QxtLocale::PesoUruguayo, // Uruguay
|
||||
QxtLocale::UzbekistanSum, // Uzbekistan
|
||||
QxtLocale::Vatu, // Vanuatu
|
||||
QxtLocale::Euro, // VaticanCityState
|
||||
QxtLocale::BolivarFuerte, // Venezuela
|
||||
QxtLocale::Dong, // VietNam
|
||||
QxtLocale::USDollar, // BritishVirginIslands
|
||||
QxtLocale::USDollar, // USVirginIslands
|
||||
QxtLocale::CFPFranc, // WallisAndFutunaIslands
|
||||
QxtLocale::MoroccanDirham, // WesternSahara
|
||||
QxtLocale::YemeniRial, // Yemen
|
||||
QxtLocale::NoCurrency, // Yugoslavia
|
||||
QxtLocale::ZambiaKwacha, // Zambia
|
||||
QxtLocale::ZimbabweDollar, // Zimbabwe
|
||||
};
|
||||
static const char* currency_names[] = {
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "*No Currency*"), // NoCurrency
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Afghani"), // Afghani
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Algerian Dinar"), // AlgerianDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Argentine Peso"), // ArgentinePeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Armenian Dram"), // ArmenianDram
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Aruban Guilder"), // ArubanGuilder
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Australian Dollar"), // AustralianDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Azerbaijanian Manat"), // AzerbaijanianManat
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Bahamian Dollar"), // BahamianDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Bahraini Dinar"), // BahrainiDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Baht"), // Baht
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Balboa"), // Balboa
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Barbados Dollar"), // BarbadosDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Belarussian Ruble"), // BelarussianRuble
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Belize Dollar"), // BelizeDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Bermudian Dollar"), // BermudianDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Bolivar Fuerte"), // BolivarFuerte
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Boliviano"), // Boliviano
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Brazilian Real"), // BrazilianReal
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Brunei Dollar"), // BruneiDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Bulgarian Lev"), // BulgarianLev
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Burundi Franc"), // BurundiFranc
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "CFA Franc BCEAO"), // CFAFrancBCEAO
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "CFA Franc BEAC"), // CFAFrancBEAC
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "CFP Franc"), // CFPFranc
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Canadian Dollar"), // CanadianDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Cape Verde Escudo"), // CapeVerdeEscudo
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Cayman Islands Dollar"), // CaymanIslandsDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Chilean Peso"), // ChileanPeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Colombian Peso"), // ColombianPeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Comoro Franc"), // ComoroFranc
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Convertible Marks"), // ConvertibleMarks
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Cordoba Oro"), // CordobaOro
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Costa Rican Colon"), // CostaRicanColon
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Croatian Kuna"), // CroatianKuna
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Cuban Peso"), // CubanPeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Cyprus Pound"), // CyprusPound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Czech Koruna"), // CzechKoruna
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Dalasi"), // Dalasi
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Danish Krone"), // DanishKrone
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Denar"), // Denar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Djibouti Franc"), // DjiboutiFranc
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Dobra"), // Dobra
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Dominican Peso"), // DominicanPeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Dong"), // Dong
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "East Caribbean Dollar"), // EastCaribbeanDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Egyptian Pound"), // EgyptianPound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "El Salvador Colon"), // ElSalvadorColon
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Ethiopian Birr"), // EthiopianBirr
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Euro"), // Euro
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Falkland Islands Pound"), // FalklandIslandsPound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Fiji Dollar"), // FijiDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Forint"), // Forint
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Franc Congolais"), // FrancCongolais
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Ghana Cedi"), // GhanaCedi
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Gibraltar Pound"), // GibraltarPound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Gourde"), // Gourde
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Guarani"), // Guarani
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Guinea-Bissau Peso"), // GuineaBissauPeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Guinea Franc"), // GuineaFranc
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Guyana Dollar"), // GuyanaDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Hong Kong Dollar"), // HongKongDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Hryvnia"), // Hryvnia
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Iceland Krona"), // IcelandKrona
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Indian Rupee"), // IndianRupee
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Iranian Rial"), // IranianRial
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Iraqi Dinar"), // IraqiDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Jamaican Dollar"), // JamaicanDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Jordanian Dinar"), // JordanianDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Kenyan Shilling"), // KenyanShilling
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Kina"), // Kina
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Kip"), // Kip
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Kroon"), // Kroon
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Kuwaiti Dinar"), // KuwaitiDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Kwanza"), // Kwanza
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Kyat"), // Kyat
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Lari"), // Lari
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Latvian Lats"), // LatvianLats
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Lebanese Pound"), // LebanesePound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Lek"), // Lek
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Lempira"), // Lempira
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Leone"), // Leone
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Liberian Dollar"), // LiberianDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Libyan Dinar"), // LibyanDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Lilangeni"), // Lilangeni
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Lithuanian Litas"), // LithuanianLitas
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Loti"), // Loti
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Malagasy Ariary"), // MalagasyAriary
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "MalawiKwacha"), // MalawiKwacha
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Malaysian Ringgit"), // MalaysianRinggit
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Maltese Lira"), // MalteseLira
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Manat"), // Manat
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Mauritius Rupee"), // MauritiusRupee
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Metical"), // Metical
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Mexican Peso"), // MexicanPeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Mexican Unidad de Inversion"), // MexicanUnidadDeInversion
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Moldovan Leu"), // MoldovanLeu
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Moroccan Dirham"), // MoroccanDirham
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Mvdol"), // Mvdol
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Naira"), // Naira
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Nakfa"), // Nakfa
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Namibia Dollar"), // NamibiaDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Nepalese Rupee"), // NepaleseRupee
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Netherlands Antillian Guilder"), // NetherlandsAntillianGuilder
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "New Israeli Sheqel"), // NewIsraeliSheqel
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "New Leu"), // NewLeu
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "New Taiwan Dollar"), // NewTaiwanDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "New Turkish Lira"), // NewTurkishLira
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "New Zealand Dollar"), // NewZealandDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Ngultrum"), // Ngultrum
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "North Korean Won"), // NorthKoreanWon
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Norwegian Krone"), // NorwegianKrone
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Nuevo Sol"), // NuevoSol
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Ouguiya"), // Ouguiya
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Pa'anga"), // Paanga
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Pakistan Rupee"), // PakistanRupee
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Pataca"), // Pataca
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Peso Uruguayo"), // PesoUruguayo
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Philippine Peso"), // PhilippinePeso
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Pound Sterling"), // PoundSterling
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Pula"), // Pula
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Qatari Rial"), // QatariRial
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Quetzal"), // Quetzal
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Rand"), // Rand
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Rial Omani"), // RialOmani
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Riel"), // Riel
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Rufiyaa"), // Rufiyaa
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Rupiah"), // Rupiah
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Russian Ruble"), // RussianRuble
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Rwanda Franc"), // RwandaFranc
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Saint Helena Pound"), // SaintHelenaPound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Saudi Riyal"), // SaudiRiyal
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Serbian Dinar"), // SerbianDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Seychelles Rupee"), // SeychellesRupee
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Singapore Dollar"), // SingaporeDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Slovak Koruna"), // SlovakKoruna
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Solomon Islands Dollar"), // SolomonIslandsDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Som"), // Som
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Somali Shilling"), // SomaliShilling
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Somoni"), // Somoni
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Sri Lanka Rupee"), // SriLankaRupee
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Sudanese Pound"), // SudanesePound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Surinam Dollar"), // SurinamDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Swedish Krona"), // SwedishKrona
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Swiss Franc"), // SwissFranc
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Syrian Pound"), // SyrianPound
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Taka"), // Taka
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Tala"), // Tala
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Tanzanian Shilling"), // TanzanianShilling
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Tenge"), // Tenge
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Trinidad and Tobago Dollar"), // TrinidadAndTobagoDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Tugrik"), // Tugrik
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Tunisian Dinar"), // TunisianDinar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "UAE Dirham"), // UAEDirham
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "US Dollar"), // USDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Uganda Shilling"), // UgandaShilling
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Unidad de Valor Real"), // UnidadDeValorReal
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Unidades de fomento"), // UnidadesDeFomento
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Uruguay Peso en Unidades Indexadas"), // UruguayPesoEnUnidadesIndexadas
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Uzbekistan Sum"), // UzbekistanSum
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Vatu"), // Vatu
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Won"), // Won
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Yemeni Rial"), // YemeniRial
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Yen"), // Yen
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Yuan Renminbi"), // YuanRenminbi
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "ZambiaKwacha"), // ZambiaKwacha
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Zimbabwe Dollar"), // ZimbabweDollar
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Zloty"), // Zloty
|
||||
};
|
||||
static QChar symbol_for_country_list[][5] =
|
||||
{
|
||||
{ }, // NoCurrency
|
||||
{ 1,0x60b }, // Afghani
|
||||
{ }, // AlgerianDinar
|
||||
{ 1,0x24 }, // ArgentinePeso
|
||||
{ }, // ArmenianDram
|
||||
{ 1,0x192 }, // ArubanGuilder
|
||||
{ 1,0x24 }, // AustralianDollar
|
||||
{ 3,0x43c,0x430,0x43d }, // AzerbaijanianManat
|
||||
{ 1,0x24 }, // BahamianDollar
|
||||
{ }, // BahrainiDinar
|
||||
{ 1,0xe3f }, // Baht
|
||||
{ 3,0x42,0x2f,0x2e }, // Balboa
|
||||
{ 1,0x24 }, // BarbadosDollar
|
||||
{ 2,0x70,0x2e }, // BelarussianRuble
|
||||
{ 3,0x42,0x5a,0x24 }, // BelizeDollar
|
||||
{ 1,0x24 }, // BermudianDollar
|
||||
{ 2,0x42,0x73 }, // BolivarFuerte
|
||||
{ 2,0x24,0x62 }, // Boliviano
|
||||
{ 2,0x52,0x24 }, // BrazilianReal
|
||||
{ 1,0x24 }, // BruneiDollar
|
||||
{ 2,0x43b,0x432 }, // BulgarianLev
|
||||
{ }, // BurundiFranc
|
||||
{ }, // CFAFrancBCEAO
|
||||
{ }, // CFAFrancBEAC
|
||||
{ }, // CFPFranc
|
||||
{ 1,0x24 }, // CanadianDollar
|
||||
{ }, // CapeVerdeEscudo
|
||||
{ 1,0x24 }, // CaymanIslandsDollar
|
||||
{ 1,0x24 }, // ChileanPeso
|
||||
{ 1,0x24 }, // ColombianPeso
|
||||
{ }, // ComoroFranc
|
||||
{ 2,0x4b,0x4d }, // ConvertibleMarks
|
||||
{ 2,0x43,0x24 }, // CordobaOro
|
||||
{ 1,0x20a1 }, // CostaRicanColon
|
||||
{ 2,0x6b,0x6e }, // CroatianKuna
|
||||
{ 1,0x20b1 }, // CubanPeso
|
||||
{ }, // CyprusPound
|
||||
{ 2,0x4b,0x10d }, // CzechKoruna
|
||||
{ }, // Dalasi
|
||||
{ 2,0x6b,0x72 }, // DanishKrone
|
||||
{ 3,0x434,0x435,0x43d }, // Denar
|
||||
{ }, // DjiboutiFranc
|
||||
{ }, // Dobra
|
||||
{ 3,0x52,0x44,0x24 }, // DominicanPeso
|
||||
{ 1,0x20ab }, // Dong
|
||||
{ 1,0x24 }, // EastCaribbeanDollar
|
||||
{ 1,0xa3 }, // EgyptianPound
|
||||
{ 1,0x24 }, // ElSalvadorColon
|
||||
{ }, // EthiopianBirr
|
||||
{ 1,0x20ac }, // Euro
|
||||
{ 1,0xa3 }, // FalklandIslandsPound
|
||||
{ 1,0x24 }, // FijiDollar
|
||||
{ 2,0x46,0x74 }, // Forint
|
||||
{ }, // FrancCongolais
|
||||
{ }, // GhanaCedi
|
||||
{ 1,0xa3 }, // GibraltarPound
|
||||
{ }, // Gourde
|
||||
{ 2,0x47,0x73 }, // Guarani
|
||||
{ }, // GuineaBissauPeso
|
||||
{ }, // GuineaFranc
|
||||
{ 1,0x24 }, // GuyanaDollar
|
||||
{ 1,0x5143 }, // HongKongDollar
|
||||
{ 1,0x20b4 }, // Hryvnia
|
||||
{ 2,0x6b,0x72 }, // IcelandKrona
|
||||
{ 1,0x20a8 }, // IndianRupee
|
||||
{ 1,0xfdfc }, // IranianRial
|
||||
{ }, // IraqiDinar
|
||||
{ 2,0x4a,0x24 }, // JamaicanDollar
|
||||
{ }, // JordanianDinar
|
||||
{ }, // KenyanShilling
|
||||
{ }, // Kina
|
||||
{ 1,0x20ad }, // Kip
|
||||
{ 2,0x6b,0x72 }, // Kroon
|
||||
{ }, // KuwaitiDinar
|
||||
{ }, // Kwanza
|
||||
{ }, // Kyat
|
||||
{ }, // Lari
|
||||
{ 2,0x4c,0x73 }, // LatvianLats
|
||||
{ 1,0xa3 }, // LebanesePound
|
||||
{ 3,0x4c,0x65,0x6b }, // Lek
|
||||
{ 1,0x4c }, // Lempira
|
||||
{ }, // Leone
|
||||
{ 1,0x24 }, // LiberianDollar
|
||||
{ }, // LibyanDinar
|
||||
{ }, // Lilangeni
|
||||
{ 2,0x4c,0x74 }, // LithuanianLitas
|
||||
{ }, // Loti
|
||||
{ }, // MalagasyAriary
|
||||
{ }, // MalawiKwacha
|
||||
{ 2,0x52,0x4d }, // MalaysianRinggit
|
||||
{ }, // MalteseLira
|
||||
{ }, // Manat
|
||||
{ 1,0x20a8 }, // MauritiusRupee
|
||||
{ 2,0x4d,0x54 }, // Metical
|
||||
{ 1,0x24 }, // MexicanPeso
|
||||
{ }, // MexicanUnidadDeInversion
|
||||
{ }, // MoldovanLeu
|
||||
{ }, // MoroccanDirham
|
||||
{ }, // Mvdol
|
||||
{ 1,0x20a6 }, // Naira
|
||||
{ }, // Nakfa
|
||||
{ 1,0x24 }, // NamibiaDollar
|
||||
{ 1,0x20a8 }, // NepaleseRupee
|
||||
{ 1,0x192 }, // NetherlandsAntillianGuilder
|
||||
{ 1,0x20aa }, // NewIsraeliSheqel
|
||||
{ 3,0x6c,0x65,0x69 }, // NewLeu
|
||||
{ 3,0x4e,0x54,0x24 }, // NewTaiwanDollar
|
||||
{ 3,0x59,0x54,0x4c }, // NewTurkishLira
|
||||
{ 1,0x24 }, // NewZealandDollar
|
||||
{ }, // Ngultrum
|
||||
{ 1,0x20a9 }, // NorthKoreanWon
|
||||
{ 2,0x6b,0x72 }, // NorwegianKrone
|
||||
{ 3,0x53,0x2f,0x2e }, // NuevoSol
|
||||
{ }, // Ouguiya
|
||||
{ }, // Paanga
|
||||
{ 1,0x20a8 }, // PakistanRupee
|
||||
{ }, // Pataca
|
||||
{ 2,0x24,0x55 }, // PesoUruguayo
|
||||
{ 3,0x50,0x68,0x70 }, // PhilippinePeso
|
||||
{ 1,0xa3 }, // PoundSterling
|
||||
{ 1,0x50 }, // Pula
|
||||
{ 1,0xfdfc }, // QatariRial
|
||||
{ 1,0x51 }, // Quetzal
|
||||
{ 1,0x52 }, // Rand
|
||||
{ 1,0xfdfc }, // RialOmani
|
||||
{ 1,0x17db }, // Riel
|
||||
{ }, // Rufiyaa
|
||||
{ 2,0x52,0x7 }, // Rupiah
|
||||
{ 3,0x440,0x443,0x431 }, // RussianRuble
|
||||
{ }, // RwandaFranc
|
||||
{ 1,0xa3 }, // SaintHelenaPound
|
||||
{ 1,0xfdfc }, // SaudiRiyal
|
||||
{ 4,0x414,0x438,0x43d,0x2e }, // SerbianDinar
|
||||
{ 1,0x20a8 }, // SeychellesRupee
|
||||
{ 1,0x24 }, // SingaporeDollar
|
||||
{ }, // SlovakKoruna
|
||||
{ 1,0x24 }, // SolomonIslandsDollar
|
||||
{ 2,0x43b,0x432 }, // Som
|
||||
{ 1,0x53 }, // SomaliShilling
|
||||
{ }, // Somoni
|
||||
{ 1,0x20a8 }, // SriLankaRupee
|
||||
{ }, // SudanesePound
|
||||
{ 1,0x24 }, // SurinamDollar
|
||||
{ 2,0x6b,0x72 }, // SwedishKrona
|
||||
{ 3,0x43,0x48,0x46 }, // SwissFranc
|
||||
{ 1,0xa3 }, // SyrianPound
|
||||
{ }, // Taka
|
||||
{ }, // Tala
|
||||
{ }, // TanzanianShilling
|
||||
{ 2,0x43b,0x432 }, // Tenge
|
||||
{ 3,0x54,0x54,0x24 }, // TrinidadAndTobagoDollar
|
||||
{ 1,0x20ae }, // Tugrik
|
||||
{ }, // TunisianDinar
|
||||
{ 1,0x62c }, // UAEDirham
|
||||
{ 1,0x24 }, // USDollar
|
||||
{ }, // UgandaShilling
|
||||
{ }, // UnidadDeValorReal
|
||||
{ }, // UnidadesDeFomento
|
||||
{ }, // UruguayPesoEnUnidadesIndexadas
|
||||
{ 2,0x43b,0x432 }, // UzbekistanSum
|
||||
{ }, // Vatu
|
||||
{ 1,0x20a9 }, // Won
|
||||
{ 1,0xfdfc }, // YemeniRial
|
||||
{ 1,0xa5 }, // Yen
|
||||
{ 1,0x5143 }, // YuanRenminbi
|
||||
{ }, // ZambiaKwacha
|
||||
{ 2,0x5a,0x24 }, // ZimbabweDollar
|
||||
{ 2,0x7a,0x142 }, // Zloty
|
||||
}
|
||||
;
|
||||
static const unsigned char currency_code_list[] =
|
||||
" " // NoCurrency
|
||||
"AFN" // Afghani
|
||||
"DZD" // AlgerianDinar
|
||||
"ARS" // ArgentinePeso
|
||||
"AMD" // ArmenianDram
|
||||
"AWG" // ArubanGuilder
|
||||
"AUD" // AustralianDollar
|
||||
"AZN" // AzerbaijanianManat
|
||||
"BSD" // BahamianDollar
|
||||
"BHD" // BahrainiDinar
|
||||
"THB" // Baht
|
||||
"PAB" // Balboa
|
||||
"BBD" // BarbadosDollar
|
||||
"BYR" // BelarussianRuble
|
||||
"BZD" // BelizeDollar
|
||||
"BMD" // BermudianDollar
|
||||
"VEF" // BolivarFuerte
|
||||
"BOB" // Boliviano
|
||||
"BRL" // BrazilianReal
|
||||
"BND" // BruneiDollar
|
||||
"BGN" // BulgarianLev
|
||||
"BIF" // BurundiFranc
|
||||
"XOF" // CFAFrancBCEAO
|
||||
"XAF" // CFAFrancBEAC
|
||||
"XPF" // CFPFranc
|
||||
"CAD" // CanadianDollar
|
||||
"CVE" // CapeVerdeEscudo
|
||||
"KYD" // CaymanIslandsDollar
|
||||
"CLP" // ChileanPeso
|
||||
"COP" // ColombianPeso
|
||||
"KMF" // ComoroFranc
|
||||
"BAM" // ConvertibleMarks
|
||||
"NIO" // CordobaOro
|
||||
"CRC" // CostaRicanColon
|
||||
"HRK" // CroatianKuna
|
||||
"CUP" // CubanPeso
|
||||
"CYP" // CyprusPound
|
||||
"CZK" // CzechKoruna
|
||||
"GMD" // Dalasi
|
||||
"DKK" // DanishKrone
|
||||
"MKD" // Denar
|
||||
"DJF" // DjiboutiFranc
|
||||
"STD" // Dobra
|
||||
"DOP" // DominicanPeso
|
||||
"VND" // Dong
|
||||
"XCD" // EastCaribbeanDollar
|
||||
"EGP" // EgyptianPound
|
||||
"SVC" // ElSalvadorColon
|
||||
"ETB" // EthiopianBirr
|
||||
"EUR" // Euro
|
||||
"FKP" // FalklandIslandsPound
|
||||
"FJD" // FijiDollar
|
||||
"HUF" // Forint
|
||||
"CDF" // FrancCongolais
|
||||
"GHS" // GhanaCedi
|
||||
"GIP" // GibraltarPound
|
||||
"HTG" // Gourde
|
||||
"PYG" // Guarani
|
||||
"GWP" // GuineaBissauPeso
|
||||
"GNF" // GuineaFranc
|
||||
"GYD" // GuyanaDollar
|
||||
"HKD" // HongKongDollar
|
||||
"UAH" // Hryvnia
|
||||
"ISK" // IcelandKrona
|
||||
"INR" // IndianRupee
|
||||
"IRR" // IranianRial
|
||||
"IQD" // IraqiDinar
|
||||
"JMD" // JamaicanDollar
|
||||
"JOD" // JordanianDinar
|
||||
"KES" // KenyanShilling
|
||||
"PGK" // Kina
|
||||
"LAK" // Kip
|
||||
"EEK" // Kroon
|
||||
"KWD" // KuwaitiDinar
|
||||
"AOA" // Kwanza
|
||||
"MMK" // Kyat
|
||||
"GEL" // Lari
|
||||
"LVL" // LatvianLats
|
||||
"LBP" // LebanesePound
|
||||
"ALL" // Lek
|
||||
"HNL" // Lempira
|
||||
"SLL" // Leone
|
||||
"LRD" // LiberianDollar
|
||||
"LYD" // LibyanDinar
|
||||
"SZL" // Lilangeni
|
||||
"LTL" // LithuanianLitas
|
||||
"LSL" // Loti
|
||||
"MGA" // MalagasyAriary
|
||||
"MWK" // MalawiKwacha
|
||||
"MYR" // MalaysianRinggit
|
||||
"MTL" // MalteseLira
|
||||
"TMM" // Manat
|
||||
"MUR" // MauritiusRupee
|
||||
"MZN" // Metical
|
||||
"MXN" // MexicanPeso
|
||||
"MXV" // MexicanUnidadDeInversion
|
||||
"MDL" // MoldovanLeu
|
||||
"MAD" // MoroccanDirham
|
||||
"BOV" // Mvdol
|
||||
"NGN" // Naira
|
||||
"ERN" // Nakfa
|
||||
"NAD" // NamibiaDollar
|
||||
"NPR" // NepaleseRupee
|
||||
"ANG" // NetherlandsAntillianGuilder
|
||||
"ILS" // NewIsraeliSheqel
|
||||
"RON" // NewLeu
|
||||
"TWD" // NewTaiwanDollar
|
||||
"TRY" // NewTurkishLira
|
||||
"NZD" // NewZealandDollar
|
||||
"BTN" // Ngultrum
|
||||
"KPW" // NorthKoreanWon
|
||||
"NOK" // NorwegianKrone
|
||||
"PEN" // NuevoSol
|
||||
"MRO" // Ouguiya
|
||||
"TOP" // Paanga
|
||||
"PKR" // PakistanRupee
|
||||
"MOP" // Pataca
|
||||
"UYU" // PesoUruguayo
|
||||
"PHP" // PhilippinePeso
|
||||
"GBP" // PoundSterling
|
||||
"BWP" // Pula
|
||||
"QAR" // QatariRial
|
||||
"GTQ" // Quetzal
|
||||
"ZAR" // Rand
|
||||
"OMR" // RialOmani
|
||||
"KHR" // Riel
|
||||
"MVR" // Rufiyaa
|
||||
"IDR" // Rupiah
|
||||
"RUB" // RussianRuble
|
||||
"RWF" // RwandaFranc
|
||||
"SHP" // SaintHelenaPound
|
||||
"SAR" // SaudiRiyal
|
||||
"RSD" // SerbianDinar
|
||||
"SCR" // SeychellesRupee
|
||||
"SGD" // SingaporeDollar
|
||||
"SKK" // SlovakKoruna
|
||||
"SBD" // SolomonIslandsDollar
|
||||
"KGS" // Som
|
||||
"SOS" // SomaliShilling
|
||||
"TJS" // Somoni
|
||||
"LKR" // SriLankaRupee
|
||||
"SDG" // SudanesePound
|
||||
"SRD" // SurinamDollar
|
||||
"SEK" // SwedishKrona
|
||||
"CHF" // SwissFranc
|
||||
"SYP" // SyrianPound
|
||||
"BDT" // Taka
|
||||
"WST" // Tala
|
||||
"TZS" // TanzanianShilling
|
||||
"KZT" // Tenge
|
||||
"TTD" // TrinidadAndTobagoDollar
|
||||
"MNT" // Tugrik
|
||||
"TND" // TunisianDinar
|
||||
"AED" // UAEDirham
|
||||
"USD" // USDollar
|
||||
"UGX" // UgandaShilling
|
||||
"COU" // UnidadDeValorReal
|
||||
"CLF" // UnidadesDeFomento
|
||||
"UYI" // UruguayPesoEnUnidadesIndexadas
|
||||
"UZS" // UzbekistanSum
|
||||
"VUV" // Vatu
|
||||
"KRW" // Won
|
||||
"YER" // YemeniRial
|
||||
"JPY" // Yen
|
||||
"CNY" // YuanRenminbi
|
||||
"ZMK" // ZambiaKwacha
|
||||
"ZWD" // ZimbabweDollar
|
||||
"PLN" // Zloty
|
||||
;
|
||||
static const char* continent_names[] = {
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "None"), // None
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "NorthAmerica"), // NorthAmerica
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "SouthAmerica"), // SouthAmerica
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Europe"), // Europe
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Africa"), // Africa
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Asia"), // Asia
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Australia"), // Australia
|
||||
QT_TRANSLATE_NOOP("QxtLocale", "Antarctica"), // Antarctica
|
||||
};
|
||||
static const QxtLocale::Continent continent_for_country_list[] = {
|
||||
QxtLocale::None, // Default
|
||||
QxtLocale::Asia, // Afghanistan
|
||||
QxtLocale::Europe, // Albania
|
||||
QxtLocale::Africa, // Algeria
|
||||
QxtLocale::Australia, // AmericanSamoa
|
||||
QxtLocale::Europe, // Andorra
|
||||
QxtLocale::Africa, // Angola
|
||||
QxtLocale::NorthAmerica, // Anguilla
|
||||
QxtLocale::Antarctica, // Antarctica
|
||||
QxtLocale::NorthAmerica, // AntiguaAndBarbuda
|
||||
QxtLocale::SouthAmerica, // Argentina
|
||||
QxtLocale::Europe, // Armenia
|
||||
QxtLocale::NorthAmerica, // Aruba
|
||||
QxtLocale::Australia, // Australia
|
||||
QxtLocale::Europe, // Austria
|
||||
QxtLocale::Europe, // Azerbaijan
|
||||
QxtLocale::NorthAmerica, // Bahamas
|
||||
QxtLocale::Asia, // Bahrain
|
||||
QxtLocale::Asia, // Bangladesh
|
||||
QxtLocale::NorthAmerica, // Barbados
|
||||
QxtLocale::Europe, // Belarus
|
||||
QxtLocale::Europe, // Belgium
|
||||
QxtLocale::SouthAmerica, // Belize
|
||||
QxtLocale::Africa, // Benin
|
||||
QxtLocale::NorthAmerica, // Bermuda
|
||||
QxtLocale::Asia, // Bhutan
|
||||
QxtLocale::SouthAmerica, // Bolivia
|
||||
QxtLocale::Europe, // BosniaAndHerzegowina
|
||||
QxtLocale::Africa, // Botswana
|
||||
QxtLocale::None, // BouvetIsland
|
||||
QxtLocale::SouthAmerica, // Brazil
|
||||
QxtLocale::Asia, // BritishIndianOceanTerritory
|
||||
QxtLocale::Asia, // BruneiDarussalam
|
||||
QxtLocale::Europe, // Bulgaria
|
||||
QxtLocale::Africa, // BurkinaFaso
|
||||
QxtLocale::Africa, // Burundi
|
||||
QxtLocale::Asia, // Cambodia
|
||||
QxtLocale::Africa, // Cameroon
|
||||
QxtLocale::NorthAmerica, // Canada
|
||||
QxtLocale::Africa, // CapeVerde
|
||||
QxtLocale::NorthAmerica, // CaymanIslands
|
||||
QxtLocale::Africa, // CentralAfricanRepublic
|
||||
QxtLocale::Africa, // Chad
|
||||
QxtLocale::SouthAmerica, // Chile
|
||||
QxtLocale::Asia, // China
|
||||
QxtLocale::Australia, // ChristmasIsland
|
||||
QxtLocale::Australia, // CocosIslands
|
||||
QxtLocale::SouthAmerica, // Colombia
|
||||
QxtLocale::Africa, // Comoros
|
||||
QxtLocale::Africa, // DemocraticRepublicOfCongo
|
||||
QxtLocale::Africa, // PeoplesRepublicOfCongo
|
||||
QxtLocale::Australia, // CookIslands
|
||||
QxtLocale::NorthAmerica, // CostaRica
|
||||
QxtLocale::Africa, // IvoryCoast
|
||||
QxtLocale::Europe, // Croatia
|
||||
QxtLocale::NorthAmerica, // Cuba
|
||||
QxtLocale::Europe, // Cyprus
|
||||
QxtLocale::Europe, // CzechRepublic
|
||||
QxtLocale::Europe, // Denmark
|
||||
QxtLocale::Africa, // Djibouti
|
||||
QxtLocale::NorthAmerica, // Dominica
|
||||
QxtLocale::NorthAmerica, // DominicanRepublic
|
||||
QxtLocale::Asia, // EastTimor
|
||||
QxtLocale::SouthAmerica, // Ecuador
|
||||
QxtLocale::Africa, // Egypt
|
||||
QxtLocale::NorthAmerica, // ElSalvador
|
||||
QxtLocale::Africa, // EquatorialGuinea
|
||||
QxtLocale::Africa, // Eritrea
|
||||
QxtLocale::Europe, // Estonia
|
||||
QxtLocale::Africa, // Ethiopia
|
||||
QxtLocale::SouthAmerica, // FalklandIslands
|
||||
QxtLocale::Europe, // FaroeIslands
|
||||
QxtLocale::Australia, // Fiji
|
||||
QxtLocale::Europe, // Finland
|
||||
QxtLocale::Europe, // France
|
||||
QxtLocale::Europe, // MetropolitanFrance
|
||||
QxtLocale::SouthAmerica, // FrenchGuiana
|
||||
QxtLocale::Australia, // FrenchPolynesia
|
||||
QxtLocale::None, // FrenchSouthernTerritories
|
||||
QxtLocale::Africa, // Gabon
|
||||
QxtLocale::Africa, // Gambia
|
||||
QxtLocale::Europe, // Georgia
|
||||
QxtLocale::Europe, // Germany
|
||||
QxtLocale::Africa, // Ghana
|
||||
QxtLocale::Europe, // Gibraltar
|
||||
QxtLocale::Europe, // Greece
|
||||
QxtLocale::NorthAmerica, // Greenland
|
||||
QxtLocale::NorthAmerica, // Grenada
|
||||
QxtLocale::NorthAmerica, // Guadeloupe
|
||||
QxtLocale::Australia, // Guam
|
||||
QxtLocale::NorthAmerica, // Guatemala
|
||||
QxtLocale::Africa, // Guinea
|
||||
QxtLocale::Africa, // GuineaBissau
|
||||
QxtLocale::SouthAmerica, // Guyana
|
||||
QxtLocale::NorthAmerica, // Haiti
|
||||
QxtLocale::None, // HeardAndMcDonaldIslands
|
||||
QxtLocale::SouthAmerica, // Honduras
|
||||
QxtLocale::Asia, // HongKong
|
||||
QxtLocale::Europe, // Hungary
|
||||
QxtLocale::Europe, // Iceland
|
||||
QxtLocale::Asia, // India
|
||||
QxtLocale::Australia, // Indonesia
|
||||
QxtLocale::Asia, // Iran
|
||||
QxtLocale::Asia, // Iraq
|
||||
QxtLocale::Europe, // Ireland
|
||||
QxtLocale::Asia, // Israel
|
||||
QxtLocale::Europe, // Italy
|
||||
QxtLocale::NorthAmerica, // Jamaica
|
||||
QxtLocale::Asia, // Japan
|
||||
QxtLocale::Asia, // Jordan
|
||||
QxtLocale::Europe, // Kazakhstan
|
||||
QxtLocale::Africa, // Kenya
|
||||
QxtLocale::Australia, // Kiribati
|
||||
QxtLocale::Asia, // DemocraticRepublicOfKorea
|
||||
QxtLocale::Asia, // RepublicOfKorea
|
||||
QxtLocale::Asia, // Kuwait
|
||||
QxtLocale::Asia, // Kyrgyzstan
|
||||
QxtLocale::Asia, // Lao
|
||||
QxtLocale::Europe, // Latvia
|
||||
QxtLocale::Asia, // Lebanon
|
||||
QxtLocale::Africa, // Lesotho
|
||||
QxtLocale::Africa, // Liberia
|
||||
QxtLocale::Africa, // LibyanArabJamahiriya
|
||||
QxtLocale::Europe, // Liechtenstein
|
||||
QxtLocale::Europe, // Lithuania
|
||||
QxtLocale::Europe, // Luxembourg
|
||||
QxtLocale::Asia, // Macau
|
||||
QxtLocale::Europe, // Macedonia
|
||||
QxtLocale::Africa, // Madagascar
|
||||
QxtLocale::Africa, // Malawi
|
||||
QxtLocale::Asia, // Malaysia
|
||||
QxtLocale::Asia, // Maldives
|
||||
QxtLocale::Africa, // Mali
|
||||
QxtLocale::Europe, // Malta
|
||||
QxtLocale::Australia, // MarshallIslands
|
||||
QxtLocale::NorthAmerica, // Martinique
|
||||
QxtLocale::Africa, // Mauritania
|
||||
QxtLocale::Africa, // Mauritius
|
||||
QxtLocale::Africa, // Mayotte
|
||||
QxtLocale::NorthAmerica, // Mexico
|
||||
QxtLocale::Australia, // Micronesia
|
||||
QxtLocale::Asia, // Moldova
|
||||
QxtLocale::Europe, // Monaco
|
||||
QxtLocale::Asia, // Mongolia
|
||||
QxtLocale::NorthAmerica, // Montserrat
|
||||
QxtLocale::Africa, // Morocco
|
||||
QxtLocale::Africa, // Mozambique
|
||||
QxtLocale::Asia, // Myanmar
|
||||
QxtLocale::Africa, // Namibia
|
||||
QxtLocale::Australia, // Nauru
|
||||
QxtLocale::Asia, // Nepal
|
||||
QxtLocale::Europe, // Netherlands
|
||||
QxtLocale::NorthAmerica, // NetherlandsAntilles
|
||||
QxtLocale::Australia, // NewCaledonia
|
||||
QxtLocale::Australia, // NewZealand
|
||||
QxtLocale::NorthAmerica, // Nicaragua
|
||||
QxtLocale::Africa, // Niger
|
||||
QxtLocale::Africa, // Nigeria
|
||||
QxtLocale::Australia, // Niue
|
||||
QxtLocale::Australia, // NorfolkIsland
|
||||
QxtLocale::Australia, // NorthernMarianaIslands
|
||||
QxtLocale::Europe, // Norway
|
||||
QxtLocale::Asia, // Oman
|
||||
QxtLocale::Asia, // Pakistan
|
||||
QxtLocale::Australia, // Palau
|
||||
QxtLocale::Asia, // PalestinianTerritory
|
||||
QxtLocale::NorthAmerica, // Panama
|
||||
QxtLocale::Australia, // PapuaNewGuinea
|
||||
QxtLocale::SouthAmerica, // Paraguay
|
||||
QxtLocale::SouthAmerica, // Peru
|
||||
QxtLocale::Asia, // Philippines
|
||||
QxtLocale::Australia, // Pitcairn
|
||||
QxtLocale::Europe, // Poland
|
||||
QxtLocale::Europe, // Portugal
|
||||
QxtLocale::NorthAmerica, // PuertoRico
|
||||
QxtLocale::Asia, // Qatar
|
||||
QxtLocale::Africa, // Reunion
|
||||
QxtLocale::Europe, // Romania
|
||||
QxtLocale::Europe, // RussianFederation
|
||||
QxtLocale::Africa, // Rwanda
|
||||
QxtLocale::NorthAmerica, // SaintKittsAndNevis
|
||||
QxtLocale::NorthAmerica, // StLucia
|
||||
QxtLocale::NorthAmerica, // StVincentAndTheGrenadines
|
||||
QxtLocale::Australia, // Samoa
|
||||
QxtLocale::Europe, // SanMarino
|
||||
QxtLocale::Africa, // SaoTomeAndPrincipe
|
||||
QxtLocale::Asia, // SaudiArabia
|
||||
QxtLocale::Africa, // Senegal
|
||||
QxtLocale::Africa, // Seychelles
|
||||
QxtLocale::Africa, // SierraLeone
|
||||
QxtLocale::Asia, // Singapore
|
||||
QxtLocale::Europe, // Slovakia
|
||||
QxtLocale::Europe, // Slovenia
|
||||
QxtLocale::Australia, // SolomonIslands
|
||||
QxtLocale::Africa, // Somalia
|
||||
QxtLocale::Africa, // SouthAfrica
|
||||
QxtLocale::SouthAmerica, // SouthGeorgiaAndTheSouthSandwichIslands
|
||||
QxtLocale::Europe, // Spain
|
||||
QxtLocale::Asia, // SriLanka
|
||||
QxtLocale::Africa, // StHelena
|
||||
QxtLocale::NorthAmerica, // StPierreAndMiquelon
|
||||
QxtLocale::Africa, // Sudan
|
||||
QxtLocale::SouthAmerica, // Suriname
|
||||
QxtLocale::Europe, // SvalbardAndJanMayenIslands
|
||||
QxtLocale::Africa, // Swaziland
|
||||
QxtLocale::Europe, // Sweden
|
||||
QxtLocale::Europe, // Switzerland
|
||||
QxtLocale::Asia, // SyrianArabRepublic
|
||||
QxtLocale::Asia, // Taiwan
|
||||
QxtLocale::Asia, // Tajikistan
|
||||
QxtLocale::Africa, // Tanzania
|
||||
QxtLocale::Asia, // Thailand
|
||||
QxtLocale::Africa, // Togo
|
||||
QxtLocale::Australia, // Tokelau
|
||||
QxtLocale::Australia, // Tonga
|
||||
QxtLocale::NorthAmerica, // TrinidadAndTobago
|
||||
QxtLocale::Africa, // Tunisia
|
||||
QxtLocale::Europe, // Turkey
|
||||
QxtLocale::Asia, // Turkmenistan
|
||||
QxtLocale::NorthAmerica, // TurksAndCaicosIslands
|
||||
QxtLocale::Australia, // Tuvalu
|
||||
QxtLocale::Africa, // Uganda
|
||||
QxtLocale::Europe, // Ukraine
|
||||
QxtLocale::Asia, // UnitedArabEmirates
|
||||
QxtLocale::Europe, // UnitedKingdom
|
||||
QxtLocale::NorthAmerica, // UnitedStates
|
||||
QxtLocale::Australia, // UnitedStatesMinorOutlyingIslands
|
||||
QxtLocale::SouthAmerica, // Uruguay
|
||||
QxtLocale::Asia, // Uzbekistan
|
||||
QxtLocale::Australia, // Vanuatu
|
||||
QxtLocale::Europe, // VaticanCityState
|
||||
QxtLocale::SouthAmerica, // Venezuela
|
||||
QxtLocale::Asia, // VietNam
|
||||
QxtLocale::NorthAmerica, // BritishVirginIslands
|
||||
QxtLocale::NorthAmerica, // USVirginIslands
|
||||
QxtLocale::Australia, // WallisAndFutunaIslands
|
||||
QxtLocale::Africa, // WesternSahara
|
||||
QxtLocale::Asia, // Yemen
|
||||
QxtLocale::Europe, // Yugoslavia
|
||||
QxtLocale::Africa, // Zambia
|
||||
QxtLocale::Africa, // Zimbabwe
|
||||
QxtLocale::Europe, // SerbiaAndMontenegro
|
||||
};
|
||||
#endif
|
@ -1,1109 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\class QxtLogger
|
||||
\brief The QxtLogger class is an easy to use, easy to extend logging tool.
|
||||
\inmodule QxtCore
|
||||
|
||||
\section1 Overview
|
||||
QxtLogger is an easy to use, easy to extend, thread-safe logging tool. It was designed to be used "out of the box".
|
||||
\code
|
||||
#include <QxtLogger>
|
||||
...
|
||||
QxtLogger::getInstance()->debug("Hi!"); // without using the macro
|
||||
qxtLog->debug("Hi!"); // using the macro
|
||||
\endcode
|
||||
\sa getInstance()
|
||||
|
||||
\section1 Usage
|
||||
QxtLogger is designed to work "out of the box". The Logger itself is a singleton object that manages all of the logging
|
||||
that is requested. It provides 8 methods to actually log content; they are listed from the most logically verbose to the
|
||||
most logically important:
|
||||
\list
|
||||
\o trace()
|
||||
\o debug()
|
||||
\o info()
|
||||
\o warning()
|
||||
\o error()
|
||||
\o critical()
|
||||
\o fatal()
|
||||
\o write()
|
||||
\endlist
|
||||
|
||||
These named members only have meaning to the person who uses them. For example, you could call qxtLog->trace() from
|
||||
many parts of a complicated, massively recursive function to trace it's output; use qxtLog->info() to log that
|
||||
an event such as "Logging has started" has happened; use qxtLog->fatal() when an unhandled exception is thrown. Or,
|
||||
you could use qxtLog->write() for everything.
|
||||
|
||||
Each of these members comes in two forms: the first takes up to ten QVariants (for moc compatibility), the second
|
||||
form takes a QList<QVariant>. Thus, you can invoke the info() member in the following ways:
|
||||
|
||||
\code
|
||||
// Using the 10-param members.
|
||||
qxtLog->info(15);
|
||||
qxtLog->info("I am a test");
|
||||
qxtLog->info(QTime::currentTime(), "something happened", 3.14);
|
||||
|
||||
// Now with QList<QVariant>
|
||||
qxtLog->info(QList<QVariant>() << "test" << 15 << QTime::currentTime());
|
||||
\endcode
|
||||
|
||||
The real power behind QxtLogger comes from telling it which log levels you actually want to see. Calling qxtLog->enableAllLogLevels()
|
||||
can give you a lot of data if you need it. But if you only want to see warnings and errors, qxtLog->setMinimumLogLevel(WarningLevel) might
|
||||
be more useful.
|
||||
|
||||
\section1 Extending
|
||||
The functionality of QxtLogger can be extended by creating plugins derived from QxtLoggerEngine. Logger Engines
|
||||
are the little workers that actually take the raw data, format it, and spit it out into meaningful forms.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\macro qxtLog
|
||||
\relates QxtLogger
|
||||
|
||||
A global pointer referring to the unique logger object. It is
|
||||
equivalent to the pointer returned by the QxtLogger::instance() function.
|
||||
|
||||
\sa QxtLogger::getInstance()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtLogger::loggerEngineAdded(const QString& engineName)
|
||||
|
||||
This signal is emitted when an engine with \a engineName has been added.
|
||||
|
||||
\sa loggerEngineRemoved()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtLogger::loggerEngineRemoved(const QString& engineName)
|
||||
|
||||
This signal is emitted when an engine with \a engineName has been removed.
|
||||
|
||||
\sa loggerEngineAdded()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtLogger::loggerEngineEnabled(const QString& engineName)
|
||||
|
||||
This signal is emitted when an engine with \a engineName has been enabled.
|
||||
|
||||
\sa loggerEngineDisabled()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QxtLogger::loggerEngineDisabled(const QString& engineName)
|
||||
|
||||
This signal is emitted when an engine with \a engineName has been disabled.
|
||||
|
||||
\sa loggerEngineEnabled()
|
||||
*/
|
||||
|
||||
#include "qxtlogger.h"
|
||||
#include "qxtlogger_p.h"
|
||||
#include "qxtlogstream.h"
|
||||
#include "logengines/qxtbasicstdloggerengine.h"
|
||||
#include <QtDebug>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
|
||||
/*******************************************************************************
|
||||
Constructor for QxtLogger's private data
|
||||
*******************************************************************************/
|
||||
QxtLoggerPrivate::QxtLoggerPrivate()
|
||||
{
|
||||
mut_lock = new QMutex(QMutex::Recursive);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
Destructor for QxtLogger's private data
|
||||
*******************************************************************************/
|
||||
QxtLoggerPrivate::~QxtLoggerPrivate()
|
||||
{
|
||||
Q_FOREACH(QxtLoggerEngine *eng, map_logEngineMap)
|
||||
{
|
||||
if (eng)
|
||||
{
|
||||
eng->killLoggerEngine();
|
||||
delete eng;
|
||||
}
|
||||
}
|
||||
delete mut_lock;
|
||||
mut_lock = NULL;
|
||||
}
|
||||
|
||||
void QxtLoggerPrivate::log(QxtLogger::LogLevel level, const QList<QVariant>& msgList)
|
||||
{
|
||||
Q_FOREACH(QxtLoggerEngine *eng, map_logEngineMap)
|
||||
{
|
||||
if (eng && eng->isInitialized() && eng->isLoggingEnabled() && eng->isLogLevelEnabled(level))
|
||||
{
|
||||
eng->writeFormatted(level, msgList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QxtLoggerPrivate::setQxtLoggerEngineMinimumLevel(QxtLoggerEngine *eng, QxtLogger::LogLevel level)
|
||||
{
|
||||
QMutexLocker lock(mut_lock);
|
||||
if (!eng) return;
|
||||
(QxtLogger::TraceLevel < level) ? eng->disableLogLevels(QxtLogger::TraceLevel) : eng->enableLogLevels(QxtLogger::TraceLevel);
|
||||
(QxtLogger::DebugLevel < level) ? eng->disableLogLevels(QxtLogger::DebugLevel) : eng->enableLogLevels(QxtLogger::DebugLevel);
|
||||
(QxtLogger::InfoLevel < level) ? eng->disableLogLevels(QxtLogger::InfoLevel) : eng->enableLogLevels(QxtLogger::InfoLevel);
|
||||
(QxtLogger::WarningLevel < level) ? eng->disableLogLevels(QxtLogger::WarningLevel) : eng->enableLogLevels(QxtLogger::WarningLevel);
|
||||
(QxtLogger::ErrorLevel < level) ? eng->disableLogLevels(QxtLogger::ErrorLevel) : eng->enableLogLevels(QxtLogger::ErrorLevel);
|
||||
(QxtLogger::CriticalLevel < level) ? eng->disableLogLevels(QxtLogger::CriticalLevel) : eng->enableLogLevels(QxtLogger::CriticalLevel);
|
||||
(QxtLogger::FatalLevel < level) ? eng->disableLogLevels(QxtLogger::FatalLevel) : eng->enableLogLevels(QxtLogger::FatalLevel);
|
||||
(QxtLogger::WriteLevel < level) ? eng->disableLogLevels(QxtLogger::WriteLevel) : eng->enableLogLevels(QxtLogger::WriteLevel);
|
||||
}
|
||||
|
||||
/*! \brief Returns the named Engine.
|
||||
*/
|
||||
QxtLoggerEngine *QxtLogger::engine(const QString &engineName)
|
||||
{
|
||||
if (! isLoggerEngine(engineName)) return 0;
|
||||
else return qxt_d().map_logEngineMap.value(engineName);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the InfoLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->info() << "informational message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::info()
|
||||
{
|
||||
return stream(QxtLogger::InfoLevel);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the TraceLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->trace() << "detailed trace message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::trace()
|
||||
{
|
||||
return stream(QxtLogger::TraceLevel);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the ErrorLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->error() << "error message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::error()
|
||||
{
|
||||
return stream(QxtLogger::ErrorLevel);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the WarningLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->warning() << "warning message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::warning()
|
||||
{
|
||||
return stream(QxtLogger::WarningLevel);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the DebugLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->debug() << "debugging log message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::debug()
|
||||
{
|
||||
return stream(QxtLogger::DebugLevel);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the CriticalLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->critical() << "critical error message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::critical()
|
||||
{
|
||||
return stream(QxtLogger::CriticalLevel);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the FatalLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->fatal() << "fatal error message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::fatal()
|
||||
{
|
||||
return stream(QxtLogger::FatalLevel);
|
||||
}
|
||||
|
||||
/*! \brief Opens a stream to write a message to all Engines with the WriteLevel set.
|
||||
The parameterless logging functions return a QxtLogStream for use similar to qDebug().
|
||||
\code
|
||||
qxtLog->write() << "log message";
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::write()
|
||||
{
|
||||
return stream(QxtLogger::WriteLevel);
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Writes a message to all Engines with the InfoLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::info(const QVariant &message, const QVariant &msg1, const QVariant &msg2, const QVariant &msg3, const QVariant &msg4, const QVariant &msg5, const QVariant &msg6, const QVariant &msg7, const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
info(args);
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Writes a message to all Engines with the TraceLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::trace(const QVariant &message, const QVariant &msg1 , const QVariant &msg2 , const QVariant &msg3 , const QVariant &msg4 , const QVariant &msg5 , const QVariant &msg6 , const QVariant &msg7 , const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
trace(args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the WarningLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::warning(const QVariant &message, const QVariant &msg1 , const QVariant &msg2 , const QVariant &msg3 , const QVariant &msg4 , const QVariant &msg5 , const QVariant &msg6 , const QVariant &msg7 , const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
warning(args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the ErrorLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::error(const QVariant &message, const QVariant &msg1 , const QVariant &msg2 , const QVariant &msg3 , const QVariant &msg4 , const QVariant &msg5 , const QVariant &msg6 , const QVariant &msg7 , const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
error(args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the DebugLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::debug(const QVariant &message, const QVariant &msg1 , const QVariant &msg2 , const QVariant &msg3 , const QVariant &msg4 , const QVariant &msg5 , const QVariant &msg6 , const QVariant &msg7 , const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
debug(args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the WriteLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::write(const QVariant &message, const QVariant &msg1 , const QVariant &msg2, const QVariant &msg3 , const QVariant &msg4 , const QVariant &msg5 , const QVariant &msg6 , const QVariant &msg7 , const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
write(args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the CriticalLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::critical(const QVariant &message, const QVariant &msg1 , const QVariant &msg2 , const QVariant &msg3 , const QVariant &msg4 , const QVariant &msg5 , const QVariant &msg6 , const QVariant &msg7 , const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
critical(args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the FatalLevel set.
|
||||
The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc
|
||||
currently only accepts functions with up to 10 parameters. They can take any value that
|
||||
QVariant can take as an argument.
|
||||
*/
|
||||
void QxtLogger::fatal(const QVariant &message, const QVariant &msg1 , const QVariant &msg2 , const QVariant &msg3 , const QVariant &msg4 , const QVariant &msg5 , const QVariant &msg6 , const QVariant &msg7 , const QVariant &msg8 , const QVariant &msg9)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QList<QVariant> args;
|
||||
args.push_back(message);
|
||||
if (!msg1.isNull()) args.push_back(msg1);
|
||||
if (!msg2.isNull()) args.push_back(msg2);
|
||||
if (!msg3.isNull()) args.push_back(msg3);
|
||||
if (!msg4.isNull()) args.push_back(msg4);
|
||||
if (!msg5.isNull()) args.push_back(msg5);
|
||||
if (!msg6.isNull()) args.push_back(msg6);
|
||||
if (!msg7.isNull()) args.push_back(msg7);
|
||||
if (!msg8.isNull()) args.push_back(msg8);
|
||||
if (!msg9.isNull()) args.push_back(msg9);
|
||||
|
||||
fatal(args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the InfoLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::info(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::InfoLevel, args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the TraceLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::trace(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::TraceLevel, args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the WarningLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::warning(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::WarningLevel, args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the ErrorLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::error(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::ErrorLevel, args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the DebugLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::debug(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::DebugLevel, args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the CriticalLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::critical(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::CriticalLevel, args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the FatalLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::fatal(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::FatalLevel, args);
|
||||
}
|
||||
|
||||
/*! \brief Writes a message to all Engines with the WriteLevel set.
|
||||
The 1-parameter logging messages can take any number of arguments in the
|
||||
form of a QList<QVariant>, or QList<QVariant>.
|
||||
*/
|
||||
void QxtLogger::write(const QList<QVariant> &args)
|
||||
{
|
||||
log(QxtLogger::WriteLevel, args);
|
||||
}
|
||||
|
||||
/*! A Generic Logging Function that takes a LogLevel and a QList<QVariant> of messages
|
||||
|
||||
This function is provided for convenience.
|
||||
*/
|
||||
void QxtLogger::log(LogLevel level, const QList<QVariant>& args)
|
||||
{
|
||||
/*
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
qxt_d().log(level, msgList);
|
||||
*/
|
||||
QMetaObject::invokeMethod(&qxt_d(), "log", Qt::AutoConnection, Q_ARG(QxtLogger::LogLevel, level), Q_ARG(QList<QVariant>, args));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
Message Handler for qdebug, qerror, qwarning, etc...
|
||||
When QxtLogger is enabled as a message handler for Qt, this function
|
||||
redirects message calls like qdebug, qwarning, qfatal.
|
||||
\sa QxtLogger::installAsMessageHandler
|
||||
\sa QxtLogger::removeAsMessageHandler
|
||||
*******************************************************************************/
|
||||
void QxtLoggerMessageHandler(QtMsgType type, const char *msg)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
QxtLogger::getInstance()->debug(msg, "qdebug");
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
QxtLogger::getInstance()->warning(msg, "qwarning");
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
QxtLogger::getInstance()->critical(msg, "qcritical");
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
QxtLogger::getInstance()->fatal(msg, "qfatal");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Installs QxtLogger as Qt's message handler.
|
||||
This will make Qt macros use QxtLogger instead of the default
|
||||
mechanism:
|
||||
\list
|
||||
\o qDebug()
|
||||
\o qWarning()
|
||||
\o qCritical()
|
||||
\o qFatal() will call abort() and terminate your application.
|
||||
\endlist
|
||||
*/
|
||||
void QxtLogger::installAsMessageHandler()
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
qInstallMsgHandler(QxtLoggerMessageHandler);
|
||||
}
|
||||
|
||||
/*! \brief Tells Qt to use it's own message handling again.
|
||||
*/
|
||||
void QxtLogger::removeAsMessageHandler()
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
qInstallMsgHandler(0);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Constructor
|
||||
Private, since QxtLogger is a singleton.
|
||||
*****************************************************************************/
|
||||
QxtLogger::QxtLogger()
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtLogger);
|
||||
qRegisterMetaType<QxtLogger::LogLevel>();
|
||||
qRegisterMetaType<QxtLogger::LogLevels>();
|
||||
addLoggerEngine("DEFAULT", new QxtBasicSTDLoggerEngine);
|
||||
setMinimumLevel("DEFAULT", QxtLogger::InfoLevel);
|
||||
}
|
||||
|
||||
/***************************************************************************//*!
|
||||
Destructor.
|
||||
The Destructor for QxtLogger iterates through all the currently installed
|
||||
QxtLoggerEngines, calls their killLoggerEngine functions through QxtLoggerEngine::killLoggerEngine(),
|
||||
and then deletes them from the map.
|
||||
*******************************************************************************/
|
||||
QxtLogger::~QxtLogger()
|
||||
{
|
||||
// implicit destruction only
|
||||
}
|
||||
|
||||
/*! \brief Returns a pointer to the instance of the Logger.
|
||||
QxtLogger is implemented as a singleton, a single object, that
|
||||
manages all of the logging done in an application. The easiest way
|
||||
to use it is by calling the qxtLog macro:
|
||||
|
||||
\code
|
||||
#include <QxtLogger>
|
||||
...
|
||||
qxtLog->info("I can log things!");
|
||||
\endcode
|
||||
|
||||
qxtLog expands to QxtLogger::getInstance, which returns a pointer to the logger.
|
||||
|
||||
QxtLogger manages it's own memory, so please remember the second rule of pointers:
|
||||
don't delete it unless you instantiated it yourself.
|
||||
\code
|
||||
delete qxtLog; // Will horribly crash your app, and possibly your system
|
||||
\endcode
|
||||
|
||||
*/
|
||||
QxtLogger *QxtLogger::getInstance()
|
||||
{
|
||||
static QxtLogger objectInstance;
|
||||
return &objectInstance;
|
||||
}
|
||||
|
||||
/*! \brief Returns a QString of the given LogLevel.
|
||||
This function is provided for convenience.
|
||||
*/
|
||||
QString QxtLogger::logLevelToString(LogLevel level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case TraceLevel:
|
||||
return "TraceLevel";
|
||||
case DebugLevel:
|
||||
return "DebugLevel";
|
||||
case InfoLevel:
|
||||
return "InfoLevel";
|
||||
case WarningLevel:
|
||||
return "WarningLevel";
|
||||
case ErrorLevel:
|
||||
return "ErrorLevel";
|
||||
case CriticalLevel:
|
||||
return "CriticalLevel";
|
||||
case FatalLevel:
|
||||
return "FatalLevel";
|
||||
case WriteLevel:
|
||||
return "WriteLevel";
|
||||
case AllLevels:
|
||||
return "AllLevels";
|
||||
default:
|
||||
return "NoLevels";
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Returns a LogLevel for the given string, or QxtLogger::NoLevels if invalid.
|
||||
This function is provided for convenience.
|
||||
*/
|
||||
QxtLogger::LogLevel QxtLogger::stringToLogLevel(const QString& level)
|
||||
{
|
||||
if (level.toLower() == "alllevels") return QxtLogger::AllLevels;
|
||||
else if (level.toLower() == "writelevel") return QxtLogger::TraceLevel;
|
||||
else if (level.toLower() == "fatallevel") return QxtLogger::DebugLevel;
|
||||
else if (level.toLower() == "criticallevel") return QxtLogger::InfoLevel;
|
||||
else if (level.toLower() == "errorlevel") return QxtLogger::WarningLevel;
|
||||
else if (level.toLower() == "warnlevel") return QxtLogger::ErrorLevel;
|
||||
else if (level.toLower() == "infolevel") return QxtLogger::CriticalLevel;
|
||||
else if (level.toLower() == "debuglevel") return QxtLogger::FatalLevel;
|
||||
else if (level.toLower() == "tracelevel") return QxtLogger::WriteLevel;
|
||||
else return QxtLogger::NoLevels;
|
||||
}
|
||||
|
||||
/*! \brief Enables the given LogLevels across all Engines.
|
||||
\code
|
||||
qxtLog->enableLogLevels(QxtLogger::NoLevels);
|
||||
qxtLog->write("I don't do anything!");
|
||||
qxtLog->enableLogLevels(QxtLogger::AllLevels);
|
||||
qxtLog->write("Hi there!");
|
||||
\endcode
|
||||
\a levels A bitmask of LogLevels
|
||||
*/
|
||||
void QxtLogger::enableLogLevels(LogLevels levels)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.empty()) return;
|
||||
|
||||
Q_FOREACH(QxtLoggerEngine *eng, qxt_d().map_logEngineMap)
|
||||
{
|
||||
if (eng)
|
||||
{
|
||||
eng->enableLogLevels(levels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Returns a reference to a refcounted stream.
|
||||
This is still in its early phases and is in dire need of testing and debugging.
|
||||
\code
|
||||
QxtLogger::stream(QxtLogger::WriteLevel) << "This should write stuff" << 1.5 << QString();
|
||||
\endcode
|
||||
*/
|
||||
QxtLogStream QxtLogger::stream(LogLevel level)
|
||||
{
|
||||
return QxtLogStream(this, level, QList<QVariant>());
|
||||
}
|
||||
|
||||
/*! \brief Enables the given LogLevels on a named Engine.
|
||||
This will use the given engine name to tell a loaded QxtLoggerEngine
|
||||
what LogLevels it should enable.
|
||||
\code
|
||||
qxtLog->addLoggerEngine("test", "libTestLogger");
|
||||
qxtLog->enableLogLevels("test", QxtLoger::AllLevels);
|
||||
qxtLog->write("You can see me through your 'test' logger now!");
|
||||
\endcode
|
||||
|
||||
\a engineName The name of a QxtLoggerEngine.
|
||||
\a levels A LogLevel or LogLevels to enable.
|
||||
\sa addLoggerEngine()
|
||||
*******************************************************************************/
|
||||
void QxtLogger::enableLogLevels(const QString &engineName, LogLevels levels)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(engineName))
|
||||
{
|
||||
qxt_d().map_logEngineMap.value(engineName)->enableLogLevels(levels);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*! \brief Turns on all log levels for a named engine.
|
||||
This is a function provided for convenience, and is equivalent to
|
||||
calling:
|
||||
\code
|
||||
qxtLog->enableLogLevels("test", QxtLogger::AllLevels);
|
||||
\endcode
|
||||
*/
|
||||
void QxtLogger::enableAllLogLevels(const QString &engineName)
|
||||
{
|
||||
enableLogLevels(engineName, QxtLogger::AllLevels);
|
||||
}
|
||||
|
||||
/*! \brief Turns on all log levels for all engines.
|
||||
This is a function provided for convenience, and is equivalent to
|
||||
calling:
|
||||
\code
|
||||
qxtLog->enableLogLevels(QxtLogger::AllLevels);
|
||||
\endcode
|
||||
*/
|
||||
void QxtLogger::enableAllLogLevels()
|
||||
{
|
||||
enableLogLevels(QxtLogger::AllLevels);
|
||||
}
|
||||
|
||||
/*! \brief Enables a named engine if it is currently disabled.
|
||||
\a engineName the name of a QxtLoggerEngine.
|
||||
*/
|
||||
void QxtLogger::enableLoggerEngine(const QString &engineName)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(engineName))
|
||||
{
|
||||
qxt_d().map_logEngineMap.value(engineName)->enableLogging();
|
||||
emit loggerEngineEnabled(engineName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Unflags the given LogLevels across all Engines.
|
||||
Disables the given LogLevel across all QxtLoggersEngines. Note that some
|
||||
|
||||
\a levels A LogLevel or LogLevels to disable.
|
||||
*/
|
||||
void QxtLogger::disableLogLevels(LogLevels levels)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.empty()) return;
|
||||
Q_FOREACH(QxtLoggerEngine *eng, qxt_d().map_logEngineMap)
|
||||
{
|
||||
if (eng)
|
||||
{
|
||||
eng->disableLogLevels(levels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Disables the named Engine.
|
||||
Disables the the named QxtLoggerEngine if it exists.
|
||||
|
||||
\a engineName The name of a log Engine to disable.
|
||||
*/
|
||||
void QxtLogger::disableLoggerEngine(const QString &engineName)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(engineName))
|
||||
{
|
||||
qxt_d().map_logEngineMap.value(engineName)->disableLogging();
|
||||
emit loggerEngineDisabled(engineName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Sets the minimumlog level for all Engines, as well as the levels above it.
|
||||
\a level The single LogLevel to set as minimum.
|
||||
*/
|
||||
void QxtLogger::setMinimumLevel(LogLevel level)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
Q_FOREACH(QxtLoggerEngine *eng, qxt_d().map_logEngineMap)
|
||||
{
|
||||
if (eng)
|
||||
{
|
||||
qxt_d().setQxtLoggerEngineMinimumLevel(eng, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Sets the minimumlog level for the named Engine, as well as the levels above it.
|
||||
\a engineName The name of a QxtLoggerEngine.
|
||||
\a level The single LogLevel to set as minimum.
|
||||
*/
|
||||
void QxtLogger::setMinimumLevel(const QString &engineName, LogLevel level)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(engineName))
|
||||
{
|
||||
qxt_d().setQxtLoggerEngineMinimumLevel(qxt_d().map_logEngineMap.value(engineName), level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Calls QxtLoggerEngine::initLoggerEngine() for the named Engine.
|
||||
Some QxtLoggerEngine plugins might require additional initialization. Check the documentation
|
||||
for your plugin. Most basic plugins will not require special tasks.
|
||||
\a engineName The name of a QxtLoggerEngine.
|
||||
*/
|
||||
void QxtLogger::initLoggerEngine(const QString &engineName)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(engineName))
|
||||
{
|
||||
qxt_d().map_logEngineMap.value(engineName)->initLoggerEngine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Calls QxtLoggerEngine::killLoggerEngine() for the named Engine.
|
||||
Some QxtLoggerEngine plugins might require special cleanup before destruction.
|
||||
Check the documentation for your plugin. Most basic plugins will not require this.
|
||||
\a engineName The name of a QxtLoggerEngine.
|
||||
*/
|
||||
void QxtLogger::killLoggerEngine(const QString &engineName)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(engineName))
|
||||
{
|
||||
qxt_d().map_logEngineMap.value(engineName)->killLoggerEngine();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*! \brief Checks if the named Engine has the given LogLevel enabled.
|
||||
\a engineName The name of a QxtLoggerEngine to query
|
||||
\a level A LogLevel or LogLevels to disable.
|
||||
Returns true or false.
|
||||
*/
|
||||
bool QxtLogger::isLogLevelEnabled(const QString &engineName, LogLevel level) const
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
return qxt_d().map_logEngineMap.value(engineName)->isLogLevelEnabled(level);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
/*! \brief Disables the given LogLevel across the named QxtLoggersEngines.
|
||||
\a engineName The name of a QxtLoggerEngine.
|
||||
\a level A LogLevel or LogLevels to disable.
|
||||
*/
|
||||
void QxtLogger::disableLogLevels(const QString &engineName, LogLevels levels)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (qxt_d().map_logEngineMap.contains(engineName))
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(engineName))
|
||||
{
|
||||
qxt_d().map_logEngineMap.value(engineName)->disableLogLevels(levels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Disables all log levels for the named Engine.
|
||||
\a engineName The name of an Engine.
|
||||
*/
|
||||
void QxtLogger::disableAllLogLevels(const QString &engineName)
|
||||
{
|
||||
disableLogLevels(engineName, QxtLogger::AllLevels);
|
||||
}
|
||||
|
||||
/*! \brief Disables all log levels for all named Engines.
|
||||
*/
|
||||
void QxtLogger::disableAllLogLevels()
|
||||
{
|
||||
disableLogLevels(QxtLogger::AllLevels);
|
||||
}
|
||||
|
||||
/*! \brief Gives QxtLogger an already-instantiated QxtLoggerEngine to use.
|
||||
addLoggerEngine inserts a subclass of QxtLoggerEngine for QxtLogger
|
||||
to manage. QxtLogger takes ownership of the engine and will
|
||||
manage memory on its own.
|
||||
\code
|
||||
#include <QxtLogger>
|
||||
...
|
||||
class MyLoggerEngine : public QxtLoggerEngine;
|
||||
...
|
||||
qxtLog->addLoggerEngine("my engine", new MyLoggerEngine);
|
||||
\endcode
|
||||
\sa QxtLoggerEngine
|
||||
*/
|
||||
void QxtLogger::addLoggerEngine(const QString &engineName, QxtLoggerEngine *engine)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
if (!qxt_d().map_logEngineMap.contains(engineName) && engine)
|
||||
{
|
||||
qxt_d().map_logEngineMap.insert(engineName, engine);
|
||||
emit loggerEngineAdded(engineName);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
\brief Gives QxtLogger an already-instantiated QLibrary.
|
||||
This is an overloaded functionand not the preferred method of adding Engines.
|
||||
It is useful to load plugins that are not in the applications Path.
|
||||
\code
|
||||
QLibrary *lib = new QLibrary("/path/to/plugin");
|
||||
qxtLog->addLogger("my engine", lib);
|
||||
\endcode
|
||||
|
||||
void QxtLogger::addLoggerEngine(const QString &engineName, QLibrary *engineLib)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
typedef QxtLoggerEngine* (*LibInstance)();
|
||||
LibInstance instance = (LibInstance)engineLib->resolve("getInstance");
|
||||
qWarning() << engineLib->errorString();
|
||||
|
||||
if (!instance) return;
|
||||
else if (!qxt_d().map_logEngineMap.contains(engineName) && engineLib)
|
||||
{
|
||||
qxt_d().map_logEngineMap.insert(engineName, instance());
|
||||
emit loggerEngineAdded(engineName);
|
||||
}
|
||||
}
|
||||
|
||||
\brief Loads an Engine from a plugin in the current path.
|
||||
\code
|
||||
qxtLog->addLogger("my lib", "libQxtSomeKindOfLoggerEngine");
|
||||
\endcode
|
||||
\a engineName The name to give this QxtLoggerEngine.
|
||||
\a libName The name of the library to load.
|
||||
|
||||
void QxtLogger::addLoggerEngine(const QString &engineName, const QString &libName)
|
||||
{
|
||||
QLibrary engineLib(libName);
|
||||
|
||||
addLoggerEngine(engineName, &engineLib);
|
||||
}
|
||||
*/
|
||||
/*! \brief Remove the named Engine from use.
|
||||
*/
|
||||
void QxtLogger::removeLoggerEngine(const QString &engineName)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QxtLoggerEngine* eng = takeLoggerEngine(engineName);
|
||||
if (!eng) return;
|
||||
eng->killLoggerEngine();
|
||||
delete eng;
|
||||
}
|
||||
|
||||
/*! \brief Remove the Engine from use.
|
||||
*/
|
||||
void QxtLogger::removeLoggerEngine(QxtLoggerEngine *engine)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
Q_FOREACH(const QString& i, this->qxt_d().map_logEngineMap.keys(engine))
|
||||
{
|
||||
takeLoggerEngine(i); // return value ignored
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Take the named Engine.
|
||||
*/
|
||||
QxtLoggerEngine *QxtLogger::takeLoggerEngine(const QString &engineName)
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QxtLoggerEngine *eng = qxt_d().map_logEngineMap.take(engineName);
|
||||
if (!eng) return NULL;
|
||||
emit loggerEngineRemoved(engineName);
|
||||
return eng;
|
||||
}
|
||||
|
||||
/*! \brief Retuns a QStringList containing the names of all loaded Engines being managed by QxtLogger.
|
||||
Returns QStringList engine names.
|
||||
*/
|
||||
QStringList QxtLogger::allLoggerEngines() const
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
return qxt_d().map_logEngineMap.keys();
|
||||
}
|
||||
|
||||
/*! \brief Retuns a QStringList containing the names of all loaded Engines that are currently enabled.
|
||||
Returns QStringList engine names.
|
||||
*/
|
||||
QStringList QxtLogger::allEnabledLoggerEngines() const
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QStringList engineNames = qxt_d().map_logEngineMap.keys();
|
||||
QStringList result;
|
||||
Q_FOREACH(const QString& name, engineNames)
|
||||
{
|
||||
if (qxt_d().map_logEngineMap.value(name)->isLoggingEnabled()) result.append(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*! \brief Retuns a QStringList containing the names of all loaded Engines that have currently certain log level enabled.
|
||||
Returns QStringList engine names.
|
||||
*/
|
||||
QStringList QxtLogger::allEnabledLoggerEngines(LogLevel level) const
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QStringList engineNames = qxt_d().map_logEngineMap.keys();
|
||||
QStringList result;
|
||||
Q_FOREACH(const QString& name, engineNames)
|
||||
{
|
||||
QxtLoggerEngine* engine = qxt_d().map_logEngineMap.value(name);
|
||||
if (engine->isLoggingEnabled() && engine->isLogLevelEnabled(level))
|
||||
{
|
||||
result.append(name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*! \brief Retuns a QStringList containing the names of all loaded Engines that are currently disabled.
|
||||
Returns QStringList engine names.
|
||||
*/
|
||||
QStringList QxtLogger::allDisabledLoggerEngines() const
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
QStringList sl_engineNames = qxt_d().map_logEngineMap.keys();
|
||||
QStringList result;
|
||||
Q_FOREACH(const QString& name, sl_engineNames)
|
||||
{
|
||||
if (!qxt_d().map_logEngineMap.value(name)->isLoggingEnabled()) result.append(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*! \brief Checks if the given string names a currently loaded Engine.
|
||||
Returns True or false.
|
||||
*/
|
||||
bool QxtLogger::isLoggerEngine(const QString &engineName) const
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
return qxt_d().map_logEngineMap.contains(engineName);
|
||||
}
|
||||
|
||||
/*! \brief Checks if the named engine is currently enabled.
|
||||
Returns True or false
|
||||
*/
|
||||
bool QxtLogger::isLoggerEngineEnabled(const QString &engineName) const
|
||||
{
|
||||
QMutexLocker lock(qxt_d().mut_lock);
|
||||
return (qxt_d().map_logEngineMap.contains(engineName) && qxt_d().map_logEngineMap.value(engineName)->isLoggingEnabled());
|
||||
}
|
@ -1,208 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTLOGGER_H
|
||||
#define QXTLOGGER_H
|
||||
|
||||
#include "qxtglobal.h"
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QFlags>
|
||||
|
||||
class QxtLoggerPrivate;
|
||||
class QxtLogStream;
|
||||
class QxtLoggerEngine;
|
||||
|
||||
void QxtLoggerMessageHandler(QtMsgType type, const char *msg);
|
||||
|
||||
class QXT_CORE_EXPORT QxtLogger : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QXT_DECLARE_PRIVATE(QxtLogger)
|
||||
|
||||
// Constructor & Destructor. Made private as QxtLogger is implemented as a singleton.
|
||||
QxtLogger();
|
||||
~QxtLogger();
|
||||
|
||||
public:
|
||||
/*******************************************************************************
|
||||
Defines for a bitmask to enable/disable logging levels.
|
||||
Arranged in levels from (assumed) most verbose to most important.
|
||||
*******************************************************************************/
|
||||
enum LogLevel
|
||||
{
|
||||
NoLevels = 0, /**< No Levels enabled */
|
||||
TraceLevel = 1 << 0, /**< The most verbose, flags trace() messages to be logged */
|
||||
DebugLevel = 1 << 1, /**< Flags debug() messages to be logged */
|
||||
InfoLevel = 1 << 2, /**< Flags info() messages to be logged */
|
||||
WarningLevel = 1 << 3, /**< Flags warning() messages to be logged */
|
||||
ErrorLevel = 1 << 4, /**< Flags error() messages to be logged */
|
||||
CriticalLevel = 1 << 5, /**< Flags critical() messages to be logged */
|
||||
FatalLevel = 1 << 6, /**< Flags fatal() messages to be logged */
|
||||
WriteLevel = 1 << 7, /**< The most important, flags write() messages to be logged */
|
||||
AllLevels = TraceLevel | DebugLevel | InfoLevel | WarningLevel | ErrorLevel | CriticalLevel | FatalLevel | WriteLevel /**< Enables all log levels */
|
||||
};
|
||||
Q_DECLARE_FLAGS(LogLevels, LogLevel)
|
||||
|
||||
/* Sone useful things */
|
||||
static QString logLevelToString(LogLevel level);
|
||||
static QxtLogger::LogLevel stringToLogLevel(const QString& level);
|
||||
static QxtLogger* getInstance();
|
||||
|
||||
void initLoggerEngine(const QString& engineName);
|
||||
void killLoggerEngine(const QString& engineName);
|
||||
|
||||
// Functions to install or remove QxtLogger as a handler for qDebug, qFatal, etc...
|
||||
void installAsMessageHandler();
|
||||
void removeAsMessageHandler();
|
||||
|
||||
//Functions for adding and removing loggers.
|
||||
void addLoggerEngine(const QString& engineName, QxtLoggerEngine *engine);
|
||||
void removeLoggerEngine(const QString& engineName);
|
||||
void removeLoggerEngine(QxtLoggerEngine *engine);
|
||||
QxtLoggerEngine* takeLoggerEngine(const QString& engineName);
|
||||
QxtLoggerEngine* engine(const QString& engineName);
|
||||
|
||||
// Functions for checking loggers.
|
||||
QStringList allLoggerEngines() const;
|
||||
QStringList allEnabledLoggerEngines() const;
|
||||
QStringList allEnabledLoggerEngines(LogLevel level) const;
|
||||
QStringList allDisabledLoggerEngines() const;
|
||||
|
||||
bool isLogLevelEnabled(const QString& engineName, LogLevel level) const;
|
||||
bool isLoggerEngine(const QString& engineName) const;
|
||||
bool isLoggerEngineEnabled(const QString& engineName) const;
|
||||
|
||||
/*******************************************************************************
|
||||
Streaming!
|
||||
*******************************************************************************/
|
||||
QxtLogStream stream(LogLevel level);
|
||||
QxtLogStream trace();
|
||||
QxtLogStream debug();
|
||||
QxtLogStream info();
|
||||
QxtLogStream warning();
|
||||
QxtLogStream error();
|
||||
QxtLogStream critical();
|
||||
QxtLogStream fatal();
|
||||
QxtLogStream write();
|
||||
|
||||
/*******************************************************************************
|
||||
Log Level enable and disable: The 1-param functions enable/disable that level on
|
||||
ALL log engines. The 2-param functions enable/disable that on a named logger.
|
||||
*******************************************************************************/
|
||||
void enableLogLevels(LogLevels levels);
|
||||
void enableLogLevels(const QString& engineName, LogLevels levels);
|
||||
void enableAllLogLevels();
|
||||
void enableAllLogLevels(const QString& engineName);
|
||||
void enableLoggerEngine(const QString& engineName);
|
||||
|
||||
void disableLogLevels(LogLevels levels);
|
||||
void disableLogLevels(const QString& engineName, LogLevels levels);
|
||||
void disableAllLogLevels();
|
||||
void disableAllLogLevels(const QString& engineName);
|
||||
void disableLoggerEngine(const QString& engineName);
|
||||
|
||||
void setMinimumLevel(LogLevel level);
|
||||
void setMinimumLevel(const QString& engineName, LogLevel level);
|
||||
|
||||
public Q_SLOTS:
|
||||
/*******************************************************************************
|
||||
Logging Functions: what the QxtLogger is all about.
|
||||
*******************************************************************************/
|
||||
void info(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
void trace(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
void warning(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
void error(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
void debug(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
void critical(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
void fatal(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
void write(const QVariant& message, const QVariant& msg1 = QVariant(),
|
||||
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
|
||||
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
|
||||
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
|
||||
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
|
||||
|
||||
/*******************************************************************************
|
||||
Logging Functions in QList<QVariant> form.
|
||||
*******************************************************************************/
|
||||
void info(const QList<QVariant>& args);
|
||||
void trace(const QList<QVariant>& args);
|
||||
void warning(const QList<QVariant>& args);
|
||||
void error(const QList<QVariant>& args);
|
||||
void debug(const QList<QVariant>& args);
|
||||
void critical(const QList<QVariant>& args);
|
||||
void fatal(const QList<QVariant>& args);
|
||||
void write(const QList<QVariant>& args);
|
||||
|
||||
/*******************************************************************************
|
||||
And now a generic Logging function
|
||||
*******************************************************************************/
|
||||
void log(LogLevel level, const QList<QVariant>& args);
|
||||
|
||||
Q_SIGNALS:
|
||||
void loggerEngineAdded(const QString& engineName);
|
||||
void loggerEngineRemoved(const QString& engineName);
|
||||
void loggerEngineEnabled(const QString& engineName);
|
||||
void loggerEngineDisabled(const QString& engineName);
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QxtLogger::LogLevels)
|
||||
Q_DECLARE_METATYPE(QxtLogger::LogLevel)
|
||||
Q_DECLARE_METATYPE(QxtLogger::LogLevels)
|
||||
|
||||
#define qxtLog QxtLogger::getInstance()
|
||||
|
||||
#include "qxtlogstream.h"
|
||||
|
||||
#endif // QXTLOGGER_H
|
@ -1,53 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTLOGGERPRIVATE_H
|
||||
#define QXTLOGGERPRIVATE_H
|
||||
|
||||
#include "qxtlogger.h"
|
||||
#include <QHash>
|
||||
|
||||
/*******************************************************************************
|
||||
QxtLoggerPrivate
|
||||
This is the d_ptr private class containing the actual data this library
|
||||
works with.
|
||||
*******************************************************************************/
|
||||
QT_FORWARD_DECLARE_CLASS(QMutex)
|
||||
class QxtLoggerPrivate : public QObject, public QxtPrivate<QxtLogger>
|
||||
{
|
||||
Q_OBJECT
|
||||
QXT_DECLARE_PUBLIC(QxtLogger)
|
||||
public:
|
||||
QxtLoggerPrivate();
|
||||
~QxtLoggerPrivate();
|
||||
void setQxtLoggerEngineMinimumLevel(QxtLoggerEngine *engine, QxtLogger::LogLevel level);
|
||||
QHash<QString, QxtLoggerEngine*> map_logEngineMap;
|
||||
QMutex* mut_lock;
|
||||
|
||||
public Q_SLOTS:
|
||||
void log(QxtLogger::LogLevel, const QList<QVariant>&);
|
||||
};
|
||||
|
||||
#endif // QXTLOGGERPRIVATE_H
|
@ -1,171 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtloggerengine.h"
|
||||
|
||||
/*! \class QxtLoggerEngine
|
||||
\brief The QxtLoggerEngine class is the parent class of all extended Engine Plugins.
|
||||
\inmodule QxtCore
|
||||
|
||||
\section1 Overview
|
||||
QxtLoggerEngine is what gives the QxtLogger it's power. While the Logger itself
|
||||
manages memory, logic, and log levels, it is the various Engine Plugins that
|
||||
do the actual work of logging the data.
|
||||
*/
|
||||
|
||||
class QxtLoggerEnginePrivate : public QxtPrivate<QxtLoggerEngine>
|
||||
{
|
||||
QXT_DECLARE_PUBLIC(QxtLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtLoggerEnginePrivate();
|
||||
|
||||
QxtLogger::LogLevels bm_logLevel;
|
||||
bool b_isLogging;
|
||||
};
|
||||
|
||||
QxtLoggerEnginePrivate::QxtLoggerEnginePrivate()
|
||||
: bm_logLevel(QxtLogger::AllLevels), b_isLogging(true)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructor
|
||||
*/
|
||||
QxtLoggerEngine::QxtLoggerEngine()
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtLoggerEngine);
|
||||
}
|
||||
|
||||
/*!
|
||||
Destructor
|
||||
*/
|
||||
QxtLoggerEngine::~QxtLoggerEngine()
|
||||
{
|
||||
QxtLogger::getInstance()->removeLoggerEngine(this);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn virtual void QxtLoggerEngine::initLoggerEngine() = 0
|
||||
|
||||
Initializes the logger engine.
|
||||
|
||||
This function is called by QxtLogger. Reimplement this function when creating a subclass of QxtLoggerEngine.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual void QxtLoggerEngine::killLoggerEngine() = 0
|
||||
|
||||
Kills the logger engine.
|
||||
|
||||
This function is called by QxtLogger. Reimplement this function when creating a subclass of QxtLoggerEngine.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual bool QxtLoggerEngine::isInitialized() const = 0
|
||||
|
||||
Returns \c true if the logger engine is initialized.
|
||||
|
||||
This function is called by QxtLogger. Reimplement this function when creating a subclass of QxtLoggerEngine.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual void QxtLoggerEngine::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant>& messages) = 0
|
||||
|
||||
Writes formatted \a messages with given \a level.
|
||||
|
||||
This function is called by QxtLogger. Reimplement this function when creating a subclass of QxtLoggerEngine.
|
||||
*/
|
||||
|
||||
/*!
|
||||
Returns \c true if logging is enabled and \c false otherwise.
|
||||
*/
|
||||
bool QxtLoggerEngine::isLoggingEnabled() const
|
||||
{
|
||||
return qxt_d().b_isLogging;
|
||||
}
|
||||
|
||||
/*!
|
||||
Enables logging.
|
||||
*/
|
||||
void QxtLoggerEngine::enableLogging()
|
||||
{
|
||||
setLoggingEnabled();
|
||||
}
|
||||
|
||||
/*!
|
||||
Disables logging.
|
||||
*/
|
||||
void QxtLoggerEngine::disableLogging()
|
||||
{
|
||||
setLoggingEnabled(false);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets logging enabled if \a enable is \c true, or disabled otherwise.
|
||||
*/
|
||||
void QxtLoggerEngine::setLoggingEnabled(bool enable)
|
||||
{
|
||||
qxt_d().b_isLogging = enable;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets log \a levels enabled if \a enable is \c true, or disabled otherwise.
|
||||
*/
|
||||
void QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::LogLevels levels, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
qxt_d().bm_logLevel |= levels;
|
||||
}
|
||||
else
|
||||
{
|
||||
qxt_d().bm_logLevel &= ~levels;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Enables log \a levels.
|
||||
*/
|
||||
void QxtLoggerEngine::enableLogLevels(QxtLogger::LogLevels levels)
|
||||
{
|
||||
setLogLevelsEnabled(levels, true);
|
||||
}
|
||||
|
||||
/*!
|
||||
Disables log \a levels.
|
||||
*/
|
||||
void QxtLoggerEngine::disableLogLevels(QxtLogger::LogLevels levels)
|
||||
{
|
||||
setLogLevelsEnabled(levels, false);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns \c true if log \a level is enabled and \c false otherwise.
|
||||
*/
|
||||
bool QxtLoggerEngine::isLogLevelEnabled(QxtLogger::LogLevel level) const
|
||||
{
|
||||
return (qxt_d().bm_logLevel & level);
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTLOGGERENGINE_H
|
||||
#define QXTLOGGERENGINE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QIODevice>
|
||||
#include <QFile>
|
||||
#include "qxtlogger.h"
|
||||
|
||||
class QxtLoggerEnginePrivate;
|
||||
|
||||
class QXT_CORE_EXPORT QxtLoggerEngine
|
||||
{
|
||||
QXT_DECLARE_PRIVATE(QxtLoggerEngine)
|
||||
|
||||
public:
|
||||
QxtLoggerEngine();
|
||||
virtual ~QxtLoggerEngine();
|
||||
|
||||
virtual void initLoggerEngine() = 0;
|
||||
virtual void killLoggerEngine() = 0;
|
||||
virtual bool isInitialized() const = 0;
|
||||
|
||||
virtual void writeFormatted(QxtLogger::LogLevel level, const QList<QVariant>& messages) = 0;
|
||||
|
||||
virtual void setLoggingEnabled(bool enable = true);
|
||||
bool isLoggingEnabled() const;
|
||||
void enableLogging();
|
||||
void disableLogging();
|
||||
|
||||
virtual void setLogLevelsEnabled(QxtLogger::LogLevels levels, bool enable = true);
|
||||
bool isLogLevelEnabled(QxtLogger::LogLevel level) const;
|
||||
void enableLogLevels(QxtLogger::LogLevels levels);
|
||||
void disableLogLevels(QxtLogger::LogLevels levels);
|
||||
};
|
||||
|
||||
#endif // QXTLOGGERENGINE_H
|
@ -1,81 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtlogstream.h"
|
||||
#include "qxtlogstream_p.h"
|
||||
#include "qxtlogger.h"
|
||||
|
||||
/*!
|
||||
\class QxtLogStream
|
||||
\brief The QxtLogStream class provides a logging stream.
|
||||
\inmodule QxtCore
|
||||
|
||||
\sa QxtLogger
|
||||
*/
|
||||
|
||||
QxtLogStreamPrivate::QxtLogStreamPrivate(QxtLogger *owner, QxtLogger::LogLevel level, const QList<QVariant> &data) : owner(owner), level(level), refcount(1), data(data)
|
||||
{
|
||||
// Nothing to see here.
|
||||
}
|
||||
|
||||
QxtLogStreamPrivate::~QxtLogStreamPrivate()
|
||||
{
|
||||
owner->log(level, data);
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a new QxtLogStream with log \a level and \a data, owned by \a owner.
|
||||
*/
|
||||
QxtLogStream::QxtLogStream(QxtLogger *owner, QxtLogger::LogLevel level, const QList<QVariant> &data) : d(new QxtLogStreamPrivate(owner, level, data))
|
||||
{
|
||||
// Nothing here either.
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a copy of \a other.
|
||||
*/
|
||||
QxtLogStream::QxtLogStream(const QxtLogStream &other)
|
||||
{
|
||||
d = other.d;
|
||||
d->refcount++;
|
||||
}
|
||||
|
||||
/*!
|
||||
Destructor.
|
||||
*/
|
||||
QxtLogStream::~QxtLogStream()
|
||||
{
|
||||
d->refcount--;
|
||||
if (d->refcount == 0) delete d;
|
||||
}
|
||||
|
||||
/*!
|
||||
Appends \a value.
|
||||
*/
|
||||
QxtLogStream& QxtLogStream::operator<< (const QVariant &value)
|
||||
{
|
||||
d->data.append(value);
|
||||
return *this;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTLOGSTREAM_H
|
||||
#define QXTLOGSTREAM_H
|
||||
|
||||
#include <QVariant>
|
||||
#include <QList>
|
||||
#include "qxtlogger.h"
|
||||
|
||||
class QxtLogger;
|
||||
class QxtLogStreamPrivate;
|
||||
|
||||
class QXT_CORE_EXPORT QxtLogStream
|
||||
{
|
||||
friend class QxtLogger;
|
||||
|
||||
public:
|
||||
QxtLogStream(const QxtLogStream &other);
|
||||
~QxtLogStream();
|
||||
QxtLogStream& operator<< (const QVariant &value);
|
||||
|
||||
private:
|
||||
QxtLogStream(QxtLogger *owner, QxtLogger::LogLevel level, const QList<QVariant> &data);
|
||||
QxtLogStreamPrivate *d;
|
||||
};
|
||||
|
||||
#endif // QXTLOGSTREAM_H
|
@ -1,46 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTLOGSTREAM_P_H
|
||||
#define QXTLOGSTREAM_P_H
|
||||
|
||||
#include "qxtlogger.h"
|
||||
|
||||
class QxtLogStream;
|
||||
|
||||
class QxtLogStreamPrivate
|
||||
{
|
||||
friend class QxtLogStream;
|
||||
public:
|
||||
QxtLogStreamPrivate(QxtLogger* owner, QxtLogger::LogLevel level, const QList<QVariant>& data);
|
||||
~QxtLogStreamPrivate();
|
||||
|
||||
QxtLogger *owner;
|
||||
QxtLogger::LogLevel level;
|
||||
int refcount; // Unfortunately, QExplicitlySharedDataPointer was introduced in Qt 4.4, and we have to work with Qt 4.2 ;_;
|
||||
QList<QVariant> data;
|
||||
};
|
||||
|
||||
#endif // QXTLOGSTREAM_P_H
|
@ -1,371 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\namespace QxtMetaObject
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtMetaObject namespace provides extensions to QMetaObject
|
||||
|
||||
including QxtMetaObject::bind
|
||||
|
||||
*/
|
||||
|
||||
#include "qxtmetaobject.h"
|
||||
#include "qxtboundfunction.h"
|
||||
#include "qxtboundcfunction.h"
|
||||
#include "qxtmetatype.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QMetaObject>
|
||||
#include <QMetaMethod>
|
||||
#include <QtDebug>
|
||||
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
class QxtBoundArgument
|
||||
{
|
||||
// This class intentionally left blank
|
||||
};
|
||||
Q_DECLARE_METATYPE(QxtBoundArgument)
|
||||
|
||||
class QxtBoundFunctionBase;
|
||||
|
||||
QxtBoundFunction::QxtBoundFunction(QObject* parent) : QObject(parent)
|
||||
{
|
||||
// initializer only
|
||||
}
|
||||
#endif
|
||||
|
||||
bool QxtBoundFunction::invoke(Qt::ConnectionType type, QXT_IMPL_10ARGS(QVariant))
|
||||
{
|
||||
return invoke(type, QXT_VAR_ARG(1), QXT_VAR_ARG(2), QXT_VAR_ARG(3), QXT_VAR_ARG(4), QXT_VAR_ARG(5), QXT_VAR_ARG(6), QXT_VAR_ARG(7), QXT_VAR_ARG(8), QXT_VAR_ARG(9), QXT_VAR_ARG(10));
|
||||
}
|
||||
|
||||
bool QxtBoundFunction::invoke(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QVariant))
|
||||
{
|
||||
return invoke(type, returnValue, QXT_VAR_ARG(1), QXT_VAR_ARG(2), QXT_VAR_ARG(3), QXT_VAR_ARG(4), QXT_VAR_ARG(5), QXT_VAR_ARG(6), QXT_VAR_ARG(7), QXT_VAR_ARG(8), QXT_VAR_ARG(9), QXT_VAR_ARG(10));
|
||||
}
|
||||
|
||||
QxtBoundFunctionBase::QxtBoundFunctionBase(QObject* parent, QGenericArgument* params[10], QByteArray types[10]) : QxtBoundFunction(parent)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (!params[i]) break;
|
||||
if (QByteArray(params[i]->name()) == "QxtBoundArgument")
|
||||
{
|
||||
arg[i] = QGenericArgument("QxtBoundArgument", params[i]->data());
|
||||
}
|
||||
else
|
||||
{
|
||||
data[i] = qxtConstructFromGenericArgument(*params[i]);
|
||||
arg[i] = p[i] = QGenericArgument(params[i]->name(), data[i]);
|
||||
}
|
||||
bindTypes[i] = types[i];
|
||||
}
|
||||
}
|
||||
|
||||
QxtBoundFunctionBase::~QxtBoundFunctionBase()
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (arg[i].name() == 0) return;
|
||||
if (QByteArray(arg[i].name()) != "QxtBoundArgument") qxtDestroyFromGenericArgument(arg[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int QxtBoundFunctionBase::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = QObject::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
if (_c == QMetaObject::InvokeMetaMethod)
|
||||
{
|
||||
if (_id == 0)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (QByteArray(arg[i].name()) == "QxtBoundArgument")
|
||||
{
|
||||
p[i] = QGenericArgument(bindTypes[i].constData(), _a[(quintptr)(arg[i].data())]);
|
||||
}
|
||||
}
|
||||
invokeImpl(Qt::DirectConnection, QGenericReturnArgument(), p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9]);
|
||||
}
|
||||
_id = -1;
|
||||
}
|
||||
return _id;
|
||||
}
|
||||
|
||||
bool QxtBoundFunctionBase::invokeBase(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument))
|
||||
{
|
||||
QGenericArgument* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (QByteArray(arg[i].name()) == "QxtBoundArgument")
|
||||
{
|
||||
p[i] = *args[(quintptr)(arg[i].data()) - 1];
|
||||
}
|
||||
}
|
||||
return invokeImpl(type, returnValue, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9]);
|
||||
}
|
||||
|
||||
bool QxtBoundFunction::invoke(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument))
|
||||
{
|
||||
return reinterpret_cast<QxtBoundFunctionBase*>(this)->invokeBase(type, returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
|
||||
#ifndef QXT_DOXYGEN_RUN
|
||||
class QxtBoundSlot : public QxtBoundFunctionBase
|
||||
{
|
||||
public:
|
||||
QByteArray sig;
|
||||
|
||||
QxtBoundSlot(QObject* receiver, const char* invokable, QGenericArgument* params[10], QByteArray types[10]) : QxtBoundFunctionBase(receiver, params, types), sig(invokable)
|
||||
{
|
||||
// initializers only
|
||||
}
|
||||
|
||||
virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument))
|
||||
{
|
||||
if (!QMetaObject::invokeMethod(parent(), QxtMetaObject::methodName(sig.constData()), type, returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10))
|
||||
{
|
||||
qWarning() << "QxtBoundFunction: call to" << sig << "failed";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace QxtMetaObject
|
||||
{
|
||||
|
||||
/*!
|
||||
Returns the name of the given method.
|
||||
|
||||
Example usage:
|
||||
\code
|
||||
QByteArray method = QxtMetaObject::methodName(" int foo ( int bar, double baz )");
|
||||
// method is now "foo"
|
||||
\endcode
|
||||
*/
|
||||
QByteArray methodName(const char* method)
|
||||
{
|
||||
QByteArray name = methodSignature(method);
|
||||
const int idx = name.indexOf("(");
|
||||
if (idx != -1)
|
||||
name.truncate(idx);
|
||||
return name;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the signature of the given method.
|
||||
*/
|
||||
QByteArray methodSignature(const char* method)
|
||||
{
|
||||
QByteArray name = QMetaObject::normalizedSignature(method);
|
||||
if(name[0] >= '0' && name[0] <= '9')
|
||||
return name.mid(1);
|
||||
return name;
|
||||
}
|
||||
|
||||
/*!
|
||||
Checks if \a method contains parentheses and begins with 1 or 2.
|
||||
*/
|
||||
bool isSignalOrSlot(const char* method)
|
||||
{
|
||||
QByteArray m(method);
|
||||
return (m.count() && (m[0] >= '0' && m[0] <= '9') && m.contains('(') && m.contains(')'));
|
||||
}
|
||||
|
||||
/*!
|
||||
* Creates a binding to the provided signal, slot, or Q_INVOKABLE method using the
|
||||
* provided parameter list. The type of each argument is deduced from the type of
|
||||
* the QVariant. This function cannot bind positional arguments; see the
|
||||
* overload using QGenericArgument.
|
||||
*
|
||||
* If the provided QObject does not implement the requested method, or if the
|
||||
* argument list is incompatible with the method's function signature, this
|
||||
* function returns NULL.
|
||||
*
|
||||
* The returned QxtBoundFunction is created as a child of the receiver.
|
||||
* Changing the parent will result in undefined behavior.
|
||||
*
|
||||
* \sa QxtMetaObject::connect, QxtBoundFunction
|
||||
*/
|
||||
QxtBoundFunction* bind(QObject* recv, const char* invokable, QXT_IMPL_10ARGS(QVariant))
|
||||
{
|
||||
if (!recv)
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: cannot connect to null QObject";
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
|
||||
QByteArray connSlot("2"), recvSlot(QMetaObject::normalizedSignature(invokable));
|
||||
const QMetaObject* meta = recv->metaObject();
|
||||
int methodID = meta->indexOfMethod(QxtMetaObject::methodSignature(recvSlot.constData()));
|
||||
if (methodID == -1)
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: no such method " << recvSlot;
|
||||
return 0;
|
||||
}
|
||||
QMetaMethod method = meta->method(methodID);
|
||||
int argCount = method.parameterTypes().count();
|
||||
const QList<QByteArray> paramTypes = method.parameterTypes();
|
||||
|
||||
for (int i = 0; i < argCount; i++)
|
||||
{
|
||||
if (paramTypes[i] == "QxtBoundArgument") continue;
|
||||
int type = QMetaType::type(paramTypes[i].constData());
|
||||
if (!args[i]->canConvert((QVariant::Type)type))
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: incompatible parameter list for " << recvSlot;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return QxtMetaObject::bind(recv, invokable, QXT_ARG(1), QXT_ARG(2), QXT_ARG(3), QXT_ARG(4), QXT_ARG(5), QXT_ARG(6), QXT_ARG(7), QXT_ARG(8), QXT_ARG(9), QXT_ARG(10));
|
||||
}
|
||||
|
||||
/*!
|
||||
* Creates a binding to the provided signal, slot, or Q_INVOKABLE method using the
|
||||
* provided parameter list. Use the Q_ARG macro to specify constant parameters, or
|
||||
* use the QXT_BIND macro to relay a parameter from a connected signal or passed
|
||||
* via the QxtBoundFunction::invoke() method.
|
||||
*
|
||||
* If the provided QObject does not implement the requested method, or if the
|
||||
* argument list is incompatible with the method's function signature, this
|
||||
* function returns NULL.
|
||||
*
|
||||
* The returned QxtBoundFunction is created as a child of the receiver.
|
||||
* Changing the parent will result in undefined behavior.
|
||||
*
|
||||
* \sa QxtMetaObject::connect, QxtBoundFunction, QXT_BIND
|
||||
*/
|
||||
QxtBoundFunction* bind(QObject* recv, const char* invokable, QXT_IMPL_10ARGS(QGenericArgument))
|
||||
{
|
||||
if (!recv)
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: cannot connect to null QObject";
|
||||
return 0;
|
||||
}
|
||||
|
||||
QGenericArgument* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
|
||||
QByteArray connSlot("2"), recvSlot(QMetaObject::normalizedSignature(invokable)), bindTypes[10];
|
||||
const QMetaObject* meta = recv->metaObject();
|
||||
int methodID = meta->indexOfMethod(QxtMetaObject::methodSignature(recvSlot.constData()).constData());
|
||||
if (methodID == -1)
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: no such method " << recvSlot;
|
||||
return 0;
|
||||
}
|
||||
QMetaMethod method = meta->method(methodID);
|
||||
int argCount = method.parameterTypes().count();
|
||||
|
||||
connSlot += QxtMetaObject::methodName(invokable) + '(';
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (args[i]->name() == 0) break; // done
|
||||
if (i >= argCount)
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: too many arguments passed to " << invokable;
|
||||
return 0;
|
||||
}
|
||||
if (i > 0) connSlot += ','; // argument separator
|
||||
if (QByteArray(args[i]->name()) == "QxtBoundArgument")
|
||||
{
|
||||
Q_ASSERT_X((quintptr)(args[i]->data()) > 0 && (quintptr)(args[i]->data()) <= 10, "QXT_BIND", "invalid argument number");
|
||||
connSlot += method.parameterTypes()[i];
|
||||
bindTypes[i] = method.parameterTypes()[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
connSlot += args[i]->name(); // type name
|
||||
}
|
||||
}
|
||||
connSlot = QMetaObject::normalizedSignature(connSlot += ')');
|
||||
|
||||
if (!QMetaObject::checkConnectArgs(recvSlot.constData(), connSlot.constData()))
|
||||
{
|
||||
qWarning() << "QxtMetaObject::bind: provided parameters " << connSlot.mid(connSlot.indexOf('(')) << " is incompatible with " << invokable;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return new QxtBoundSlot(recv, invokable, args, bindTypes);
|
||||
}
|
||||
|
||||
/*!
|
||||
Connects a signal to a QxtBoundFunction.
|
||||
*/
|
||||
bool connect(QObject* sender, const char* signal, QxtBoundFunction* slot, Qt::ConnectionType type)
|
||||
{
|
||||
const QMetaObject* meta = sender->metaObject();
|
||||
int methodID = meta->indexOfMethod(meta->normalizedSignature(signal).mid(1).constData());
|
||||
if (methodID < 0)
|
||||
{
|
||||
qWarning() << "QxtMetaObject::connect: no such signal: " << QByteArray(signal).mid(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return QMetaObject::connect(sender, methodID, slot, QObject::staticMetaObject.methodCount(), (int)(type));
|
||||
}
|
||||
|
||||
/*!
|
||||
\relates QxtMetaObject
|
||||
This overload always invokes the member using the connection type Qt::AutoConnection.
|
||||
|
||||
\sa QMetaObject::invokeMethod()
|
||||
*/
|
||||
bool invokeMethod(QObject* object, const char* member, const QVariant& arg0,
|
||||
const QVariant& arg1, const QVariant& arg2, const QVariant& arg3,
|
||||
const QVariant& arg4, const QVariant& arg5, const QVariant& arg6,
|
||||
const QVariant& arg7, const QVariant& arg8, const QVariant& arg9)
|
||||
{
|
||||
return invokeMethod(object, member, Qt::AutoConnection,
|
||||
arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
|
||||
}
|
||||
|
||||
/*!
|
||||
\relates QxtMetaObject
|
||||
|
||||
Invokes the \a member (a signal or a slot name) on the \a object.
|
||||
Returns \c true if the member could be invoked. Returns \c false
|
||||
if there is no such member or the parameters did not match.
|
||||
|
||||
\sa QMetaObject::invokeMethod()
|
||||
*/
|
||||
bool invokeMethod(QObject* object, const char* member, Qt::ConnectionType type,
|
||||
const QVariant& arg0, const QVariant& arg1, const QVariant& arg2,
|
||||
const QVariant& arg3, const QVariant& arg4, const QVariant& arg5,
|
||||
const QVariant& arg6, const QVariant& arg7, const QVariant& arg8, const QVariant& arg9)
|
||||
{
|
||||
#define QXT_MO_ARG(i) QGenericArgument(arg ## i.typeName(), arg ## i.constData())
|
||||
return QMetaObject::invokeMethod(object, methodName(member), type,
|
||||
QXT_MO_ARG(0), QXT_MO_ARG(1), QXT_MO_ARG(2), QXT_MO_ARG(3), QXT_MO_ARG(4),
|
||||
QXT_MO_ARG(5), QXT_MO_ARG(6), QXT_MO_ARG(7), QXT_MO_ARG(8), QXT_MO_ARG(9));
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTMETAOBJECT_H
|
||||
#define QXTMETAOBJECT_H
|
||||
|
||||
#include <QMetaObject>
|
||||
#include <QVariant>
|
||||
#include <QGenericArgument>
|
||||
#include <typeinfo>
|
||||
#include "qxtnullable.h"
|
||||
#include "qxtglobal.h"
|
||||
QT_FORWARD_DECLARE_CLASS(QByteArray)
|
||||
class QxtBoundArgument;
|
||||
class QxtBoundFunction;
|
||||
|
||||
#define QXT_PROTO_10ARGS(T) T p1 = T(), T p2 = T(), T p3 = T(), T p4 = T(), T p5 = T(), T p6 = T(), T p7 = T(), T p8 = T(), T p9 = T(), T p10 = T()
|
||||
#define QXT_PROTO_9ARGS(T) T p2 = T(), T p3 = T(), T p4 = T(), T p5 = T(), T p6 = T(), T p7 = T(), T p8 = T(), T p9 = T(), T p10 = T()
|
||||
#define QXT_IMPL_10ARGS(T) T p1, T p2, T p3, T p4, T p5, T p6, T p7, T p8, T p9, T p10
|
||||
|
||||
class QXT_CORE_EXPORT QxtGenericFunctionPointer
|
||||
{
|
||||
template<typename FUNCTION>
|
||||
friend QxtGenericFunctionPointer qxtFuncPtr(FUNCTION funcPtr);
|
||||
public:
|
||||
QxtGenericFunctionPointer(const QxtGenericFunctionPointer& other)
|
||||
{
|
||||
funcPtr = other.funcPtr;
|
||||
typeName = other.typeName;
|
||||
}
|
||||
|
||||
typedef void(voidFunc)();
|
||||
voidFunc* funcPtr;
|
||||
QByteArray typeName;
|
||||
|
||||
protected:
|
||||
QxtGenericFunctionPointer(voidFunc* ptr, const QByteArray& typeIdName)
|
||||
{
|
||||
funcPtr = ptr;
|
||||
typeName = typeIdName;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename FUNCTION>
|
||||
QxtGenericFunctionPointer qxtFuncPtr(FUNCTION funcPtr)
|
||||
{
|
||||
return QxtGenericFunctionPointer(reinterpret_cast<QxtGenericFunctionPointer::voidFunc*>(funcPtr), typeid(funcPtr).name());
|
||||
}
|
||||
|
||||
namespace QxtMetaObject
|
||||
{
|
||||
QXT_CORE_EXPORT QByteArray methodName(const char* method);
|
||||
QXT_CORE_EXPORT QByteArray methodSignature(const char* method);
|
||||
|
||||
QXT_CORE_EXPORT bool isSignalOrSlot(const char* method);
|
||||
|
||||
QXT_CORE_EXPORT QxtBoundFunction* bind(QObject* recv, const char* invokable, QXT_PROTO_10ARGS(QGenericArgument));
|
||||
QXT_CORE_EXPORT QxtBoundFunction* bind(QObject* recv, const char* invokable, QVariant p1, QXT_PROTO_9ARGS(QVariant));
|
||||
QXT_CORE_EXPORT bool connect(QObject* sender, const char* signal, QxtBoundFunction* slot,
|
||||
Qt::ConnectionType type = Qt::AutoConnection);
|
||||
|
||||
QXT_CORE_EXPORT bool invokeMethod(QObject* object, const char* member,
|
||||
const QVariant& arg0 = QVariant(), const QVariant& arg1 = QVariant(),
|
||||
const QVariant& arg2 = QVariant(), const QVariant& arg3 = QVariant(),
|
||||
const QVariant& arg4 = QVariant(), const QVariant& arg5 = QVariant(),
|
||||
const QVariant& arg6 = QVariant(), const QVariant& arg7 = QVariant(),
|
||||
const QVariant& arg8 = QVariant(), const QVariant& arg9 = QVariant());
|
||||
|
||||
QXT_CORE_EXPORT bool invokeMethod(QObject* object, const char* member, Qt::ConnectionType type,
|
||||
const QVariant& arg0 = QVariant(), const QVariant& arg1 = QVariant(),
|
||||
const QVariant& arg2 = QVariant(), const QVariant& arg3 = QVariant(),
|
||||
const QVariant& arg4 = QVariant(), const QVariant& arg5 = QVariant(),
|
||||
const QVariant& arg6 = QVariant(), const QVariant& arg7 = QVariant(),
|
||||
const QVariant& arg8 = QVariant(), const QVariant& arg9 = QVariant());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \relates QxtMetaObject
|
||||
* Refers to the n'th parameter of QxtBoundFunction::invoke() or of a signal connected to
|
||||
* a QxtBoundFunction.
|
||||
* \sa QxtMetaObject::bind
|
||||
*/
|
||||
#define QXT_BIND(n) QGenericArgument("QxtBoundArgument", reinterpret_cast<void*>(n))
|
||||
|
||||
#endif // QXTMETAOBJECT_H
|
@ -1,132 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTMETATYPE_H
|
||||
#define QXTMETATYPE_H
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QDataStream>
|
||||
#include <QGenericArgument>
|
||||
#include <QtDebug>
|
||||
#include <qxtglobal.h>
|
||||
|
||||
template <typename T>
|
||||
class /*QXT_CORE_EXPORT*/ QxtMetaType
|
||||
{
|
||||
public:
|
||||
static inline T* construct(const T* copy = 0)
|
||||
{
|
||||
return QMetaType::construct(qMetaTypeId<T>(), reinterpret_cast<const void*>(copy));
|
||||
}
|
||||
|
||||
static inline void destroy(T* data)
|
||||
{
|
||||
QMetaType::destroy(qMetaTypeId<T>(), data);
|
||||
}
|
||||
|
||||
// no need to reimplement isRegistered since this class will fail at compile time if it isn't
|
||||
|
||||
static inline bool load(QDataStream& stream, T* data)
|
||||
{
|
||||
return QMetaType::load(stream, qMetaTypeId<T>(), reinterpret_cast<void*>(data));
|
||||
}
|
||||
|
||||
static inline bool save(QDataStream& stream, const T* data)
|
||||
{
|
||||
return QMetaType::save(stream, qMetaTypeId<T>(), reinterpret_cast<const void*>(data));
|
||||
}
|
||||
|
||||
static inline int type()
|
||||
{
|
||||
return qMetaTypeId<T>();
|
||||
}
|
||||
|
||||
static inline const char* name()
|
||||
{
|
||||
return QMetaType::typeName(qMetaTypeId<T>());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class /*QXT_CORE_EXPORT*/ QxtMetaType<void>
|
||||
{
|
||||
public:
|
||||
static inline void* construct(const void* copy = 0)
|
||||
{
|
||||
Q_UNUSED(copy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void destroy(void* data)
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
}
|
||||
|
||||
static inline bool load(QDataStream& stream, void* data)
|
||||
{
|
||||
Q_UNUSED(stream);
|
||||
Q_UNUSED(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool save(QDataStream& stream, const void* data)
|
||||
{
|
||||
Q_UNUSED(stream);
|
||||
Q_UNUSED(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline int type()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const char* name()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
inline void* qxtConstructByName(const char* typeName, const void* copy = 0)
|
||||
{
|
||||
return QMetaType::construct(QMetaType::type(typeName), copy);
|
||||
}
|
||||
|
||||
inline void qxtDestroyByName(const char* typeName, void* data)
|
||||
{
|
||||
QMetaType::destroy(QMetaType::type(typeName), data);
|
||||
}
|
||||
|
||||
inline void* qxtConstructFromGenericArgument(QGenericArgument arg)
|
||||
{
|
||||
return qxtConstructByName(arg.name(), arg.data());
|
||||
}
|
||||
|
||||
inline void qxtDestroyFromGenericArgument(QGenericArgument arg)
|
||||
{
|
||||
qxtDestroyByName(arg.name(), arg.data());
|
||||
}
|
||||
|
||||
#endif
|
@ -1,157 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtmodelserializer.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDataStream>
|
||||
|
||||
/*
|
||||
\class QxtModelSerializer
|
||||
\inmodule QxtCore
|
||||
\brief The QxtModelSerializer class provides serialization of QAbstractItemModel
|
||||
*/
|
||||
|
||||
struct QxtModelItem
|
||||
{
|
||||
QMap<int, QVariant> itemData;
|
||||
int rowCount;
|
||||
int columnCount;
|
||||
};
|
||||
|
||||
inline QDataStream& operator<<(QDataStream& out, const QxtModelItem& item)
|
||||
{
|
||||
out << item.itemData;
|
||||
out << item.rowCount;
|
||||
out << item.columnCount;
|
||||
return out;
|
||||
}
|
||||
|
||||
inline QDataStream& operator>>(QDataStream& in, QxtModelItem& item)
|
||||
{
|
||||
in >> item.itemData;
|
||||
in >> item.rowCount;
|
||||
in >> item.columnCount;
|
||||
return in;
|
||||
}
|
||||
|
||||
class QxtModelSerializerPrivate : public QxtPrivate<QxtModelSerializer>
|
||||
{
|
||||
public:
|
||||
QxtModelSerializerPrivate() : model(0) { }
|
||||
|
||||
void save(QDataStream& stream, const QModelIndex& index) const;
|
||||
bool restore(QDataStream& stream, const QModelIndex& index);
|
||||
void print(const QByteArray& data) const;
|
||||
|
||||
QAbstractItemModel* model;
|
||||
};
|
||||
|
||||
void QxtModelSerializerPrivate::save(QDataStream& stream, const QModelIndex& index) const
|
||||
{
|
||||
QxtModelItem item;
|
||||
item.itemData = model->itemData(index);
|
||||
item.rowCount = model->rowCount(index);
|
||||
item.columnCount = model->columnCount(index);
|
||||
stream << item;
|
||||
for (int r = 0; r < item.rowCount; ++r)
|
||||
for (int c = 0; c < item.columnCount; ++c)
|
||||
save(stream, model->index(r, c, index));
|
||||
}
|
||||
|
||||
bool QxtModelSerializerPrivate::restore(QDataStream& stream, const QModelIndex& index)
|
||||
{
|
||||
QxtModelItem item;
|
||||
stream >> item;
|
||||
|
||||
if (index.isValid())
|
||||
model->setItemData(index, item.itemData);
|
||||
if (item.rowCount > 0)
|
||||
model->insertRows(0, item.rowCount, index);
|
||||
if (item.columnCount > 0)
|
||||
model->insertColumns(0, item.columnCount, index);
|
||||
|
||||
for (int r = 0; r < item.rowCount; ++r)
|
||||
{
|
||||
for (int c = 0; c < item.columnCount; ++c)
|
||||
restore(stream, model->index(r, c, index));
|
||||
}
|
||||
return stream.status() == QDataStream::Ok;
|
||||
}
|
||||
|
||||
void QxtModelSerializerPrivate::print(const QByteArray& data) const
|
||||
{
|
||||
QDataStream stream(data);
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
QxtModelItem item;
|
||||
stream >> item;
|
||||
}
|
||||
}
|
||||
|
||||
QxtModelSerializer::QxtModelSerializer(QAbstractItemModel* model)
|
||||
{
|
||||
qxt_d().model = model;
|
||||
}
|
||||
|
||||
QxtModelSerializer::~QxtModelSerializer()
|
||||
{
|
||||
}
|
||||
|
||||
QAbstractItemModel* QxtModelSerializer::model() const
|
||||
{
|
||||
return qxt_d().model;
|
||||
}
|
||||
|
||||
void QxtModelSerializer::setModel(QAbstractItemModel* model)
|
||||
{
|
||||
qxt_d().model = model;
|
||||
}
|
||||
|
||||
QByteArray QxtModelSerializer::saveModel(const QModelIndex& index) const
|
||||
{
|
||||
if (!qxt_d().model)
|
||||
{
|
||||
qWarning("QxtModelSerializer::saveModel(): model == null");
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray data;
|
||||
QDataStream stream(&data, QIODevice::WriteOnly);
|
||||
qxt_d().save(stream, index);
|
||||
qxt_d().print(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool QxtModelSerializer::restoreModel(const QByteArray& data, const QModelIndex& index)
|
||||
{
|
||||
if (!qxt_d().model)
|
||||
{
|
||||
qWarning("QxtModelSerializer::restoreModel(): model == null");
|
||||
return false;
|
||||
}
|
||||
|
||||
QDataStream stream(data);
|
||||
qxt_d().print(data);
|
||||
return qxt_d().restore(stream, index);
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QXTMODELSERIALIZER_H
|
||||
#define QXTMODELSERIALIZER_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
#include <QModelIndex>
|
||||
|
||||
class QxtModelSerializerPrivate;
|
||||
QT_FORWARD_DECLARE_CLASS(QByteArray)
|
||||
QT_FORWARD_DECLARE_CLASS(QAbstractItemModel)
|
||||
|
||||
class QXT_CORE_EXPORT QxtModelSerializer
|
||||
{
|
||||
public:
|
||||
QxtModelSerializer(QAbstractItemModel* model = 0);
|
||||
~QxtModelSerializer();
|
||||
|
||||
QAbstractItemModel* model() const;
|
||||
void setModel(QAbstractItemModel* model);
|
||||
|
||||
QByteArray saveModel(const QModelIndex& index = QModelIndex()) const;
|
||||
bool restoreModel(const QByteArray& data, const QModelIndex& index = QModelIndex());
|
||||
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtModelSerializer)
|
||||
};
|
||||
|
||||
#endif // QXTMODELSERIALIZER_H
|
@ -1,99 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\class QxtMultiSignalWaiter
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtMultiSignalWaiter class blocks and processes events until a group of signals is emitted
|
||||
|
||||
Code written in a synchronous style will sometimes need to block until any of several conditions are met,
|
||||
or until all of a set of conditions are met. This class allows a group of signals to be defined and waited
|
||||
upon in a simple AND or OR fashion. More complex Boolean relationships can be written by connecting
|
||||
together multiple QxtSignalGroup objects and waiting for all or any of these groups to emit one of
|
||||
their signals.
|
||||
|
||||
\bold {Note:}
|
||||
QxtMultiSignalWaiter is subject to the same reentrancy problems as QxtSignalWaiter.
|
||||
|
||||
\sa QxtSignalWaiter
|
||||
*/
|
||||
|
||||
#include "qxtmultisignalwaiter.h"
|
||||
#include "qxtsignalwaiter.h"
|
||||
|
||||
/*!
|
||||
* Constructs a QxtMultiSignalWaiter with the specified \a parent.
|
||||
*/
|
||||
QxtMultiSignalWaiter::QxtMultiSignalWaiter(QObject* parent) : QxtSignalGroup(parent)
|
||||
{
|
||||
/* initializers only */
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destructs the multi signal waiter.
|
||||
*/
|
||||
QxtMultiSignalWaiter::~QxtMultiSignalWaiter()
|
||||
{
|
||||
/* no-op */
|
||||
}
|
||||
|
||||
/*!
|
||||
* Blocks the current function by processing events from the event queue according to
|
||||
* \a flags until any of the signals in the group are emitted.
|
||||
* If \a msec is not \c -1, waitForAny() will return before a signal is emitted if the
|
||||
* specified number of milliseconds have elapsed. Returns \c true if a signal was
|
||||
* caught, or \c false if the timeout elapsed.
|
||||
* Note that waitForAny() may continue to block after a signal is emitted or the
|
||||
* timeout elapses; the function only guarantees that it will not return BEFORE
|
||||
* one of these conditions has occurred. This function is not reentrant.
|
||||
*
|
||||
* \sa QxtSignalGroup::addSignal(), QxtSignalGroup::firstSignalReceived()
|
||||
*/
|
||||
bool QxtMultiSignalWaiter::waitForAny(int msec, QEventLoop::ProcessEventsFlags flags)
|
||||
{
|
||||
if (hasReceivedFirstSignal()) return true;
|
||||
return QxtSignalWaiter::wait(this, SIGNAL(firstSignalReceived()), msec, flags);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Blocks the current function by processing events from the event queue according to
|
||||
* \a flags until all of the signals in the group have been emitted. If \a msec is not
|
||||
* \c -1, waitForAll() will return before all of the signals are emitted if the specified
|
||||
* number of milliseconds have elapsed. Returns \c true if each signal was caught at
|
||||
* least once, or \c false if the timeout elapsed. Note that waitForAll() may continue
|
||||
* to block after the last signal is emitted or the timeout elapses; the function only
|
||||
* guarantees that it will not return BEFORE one of these conditions has occurred.
|
||||
* This function is not reentrant.
|
||||
*
|
||||
* \sa QxtSignalGroup::addSignal(), QxtSignalGroup::allSignalsReceived()
|
||||
*/
|
||||
bool QxtMultiSignalWaiter::waitForAll(int msec, QEventLoop::ProcessEventsFlags flags)
|
||||
{
|
||||
if (hasReceivedAllSignals()) return true;
|
||||
return QxtSignalWaiter::wait(this, SIGNAL(allSignalsReceived()), msec, flags);
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTMULTISIGNALWAITER_H
|
||||
#define QXTMULTISIGNALWAITER_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
#include <qxtsignalgroup.h>
|
||||
#include <QEventLoop>
|
||||
|
||||
class QXT_CORE_EXPORT QxtMultiSignalWaiter : public QxtSignalGroup
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtMultiSignalWaiter(QObject* parent = 0);
|
||||
virtual ~QxtMultiSignalWaiter();
|
||||
|
||||
bool waitForAny(int msec = -1, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
|
||||
bool waitForAll(int msec = -1, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,106 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTNAMESPACE_H
|
||||
#define QXTNAMESPACE_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
|
||||
#if (defined BUILD_QXT | defined Q_MOC_RUN) && !defined(QXT_DOXYGEN_RUN)
|
||||
#include <QObject>
|
||||
|
||||
class QXT_CORE_EXPORT Qxt : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Rotation)
|
||||
Q_ENUMS(DecorationStyle)
|
||||
Q_ENUMS(ErrorCode)
|
||||
|
||||
public:
|
||||
#else
|
||||
namespace Qxt
|
||||
{
|
||||
#endif
|
||||
enum Rotation
|
||||
{
|
||||
NoRotation = 0,
|
||||
UpsideDown = 180,
|
||||
Clockwise = 90,
|
||||
CounterClockwise = 270
|
||||
};
|
||||
|
||||
enum DecorationStyle
|
||||
{
|
||||
NoDecoration,
|
||||
Buttonlike,
|
||||
Menulike
|
||||
};
|
||||
|
||||
enum ErrorCode
|
||||
{
|
||||
NoError,
|
||||
UnknownError,
|
||||
LogicalError,
|
||||
Bug,
|
||||
UnexpectedEndOfFunction,
|
||||
NotImplemented,
|
||||
CodecError,
|
||||
NotInitialised,
|
||||
EndOfFile,
|
||||
FileIOError,
|
||||
FormatError,
|
||||
DeviceError,
|
||||
SDLError,
|
||||
InsufficientMemory,
|
||||
SeeErrorString,
|
||||
UnexpectedNullParameter,
|
||||
ClientTimeout,
|
||||
SocketIOError,
|
||||
ParserError,
|
||||
HeaderTooLong,
|
||||
Auth,
|
||||
Overflow
|
||||
};
|
||||
|
||||
enum QxtItemDataRole
|
||||
{
|
||||
ItemStartTimeRole = Qt::UserRole + 1,
|
||||
ItemDurationRole = ItemStartTimeRole + 1,
|
||||
UserRole = ItemDurationRole + 23
|
||||
};
|
||||
|
||||
enum Timeunit
|
||||
{
|
||||
Second,
|
||||
Minute,
|
||||
Hour,
|
||||
Day,
|
||||
Week,
|
||||
Month,
|
||||
Year
|
||||
};
|
||||
};
|
||||
|
||||
#endif // QXTNAMESPACE_H
|
@ -1,27 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qxtnull.h"
|
||||
|
||||
// nothing here
|
@ -1,62 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTNULL_H
|
||||
#define QXTNULL_H
|
||||
|
||||
#include <qxtglobal.h>
|
||||
|
||||
/*!
|
||||
\class QxtNull QxtNull
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief An object representing the "null" value for QxtNullable.
|
||||
|
||||
\sa QxtNullable
|
||||
*/
|
||||
|
||||
struct QXT_CORE_EXPORT QxtNull
|
||||
{
|
||||
/*! integer cast operator
|
||||
* In expressions, QxtNull behaves as an integer zero for compatibility with generic functions.
|
||||
*/
|
||||
operator int() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
enum { isNull = true };
|
||||
};
|
||||
|
||||
#ifndef QXT_NO_MACROS
|
||||
|
||||
/*! \relates QxtNull
|
||||
* A convenience alias for QxtNull().
|
||||
*/
|
||||
#define QXT_NULL QxtNull()
|
||||
|
||||
#endif // QXT_NO_MACROS
|
||||
|
||||
#endif // QXTNULL_H
|
@ -1,146 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\class QxtNullable QxtNullable
|
||||
\inmodule QxtCore
|
||||
\brief distinct null value compatible with any data type.
|
||||
|
||||
in general it's a templated abstraction to allow any data type to be
|
||||
expressed with a null value distinct from any real value. An example
|
||||
of such a use is for optional arguments.
|
||||
\n
|
||||
prepare a function for argument skipping:
|
||||
|
||||
\code
|
||||
void somefunction( qxtNull(int,a) , qxtNull(int,b) )
|
||||
{
|
||||
|
||||
if (!a.isNull())
|
||||
{
|
||||
int i = a.value();
|
||||
//do something with i
|
||||
}
|
||||
if (!b.isNull())
|
||||
{
|
||||
int x = b.value();
|
||||
//do something with x
|
||||
}
|
||||
}
|
||||
\endcode
|
||||
|
||||
usage:
|
||||
\code
|
||||
|
||||
somefunction(SKIP,1,2);
|
||||
somefunction(3,4);
|
||||
somefunction(3,SKIP,6);
|
||||
somefunction(1);
|
||||
\endcode
|
||||
|
||||
*/
|
||||
|
||||
#ifndef QXTNULLABLE_H
|
||||
#define QXTNULLABLE_H
|
||||
#include <qxtglobal.h>
|
||||
|
||||
/*! \relates QxtNullable
|
||||
* defines a skipable argument with type \a t and variable name \a n
|
||||
*/
|
||||
#define qxtNull(t,n) QxtNullable<t> n = QxtNullable<t>()
|
||||
|
||||
#include <qxtnull.h>
|
||||
|
||||
template<typename T>
|
||||
class /*QXT_CORE_EXPORT*/ QxtNullable
|
||||
{
|
||||
public:
|
||||
QxtNullable(QxtNull);
|
||||
QxtNullable(const T& p);
|
||||
QxtNullable();
|
||||
|
||||
///determinates if the Value is set to something meaningfull
|
||||
bool isNull() const;
|
||||
|
||||
///delete Value
|
||||
void nullify();
|
||||
|
||||
T& value() const;
|
||||
operator T() const;
|
||||
void operator=(const T& p);
|
||||
|
||||
private:
|
||||
T* val;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
QxtNullable<T>::QxtNullable(QxtNull)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
QxtNullable<T>::QxtNullable(const T& p)
|
||||
{
|
||||
val = const_cast<T*>(&p);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
QxtNullable<T>::QxtNullable()
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
QxtNullable<T>::operator T() const
|
||||
{
|
||||
return *val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& QxtNullable<T>::value() const
|
||||
{
|
||||
return *val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool QxtNullable<T>::isNull() const
|
||||
{
|
||||
return (val == 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QxtNullable<T>::nullify()
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QxtNullable<T>::operator=(const T & p)
|
||||
{
|
||||
val = const_cast<T*>(&p);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,173 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTPAIRLIST_H
|
||||
#define QXTPAIRLIST_H
|
||||
|
||||
/*!
|
||||
\class QxtPairList QxtPairList
|
||||
|
||||
\ingroup kit
|
||||
|
||||
\brief Searchable List of Pairs
|
||||
|
||||
|
||||
Pair list provides a list with two values, a bit like QHash, but with the possibility to operate on both values.
|
||||
|
||||
in contrast to QHash, every entry has a unique id, you can work with. like a QList.
|
||||
|
||||
\code
|
||||
QxtPairList<int,int> list;
|
||||
|
||||
list.append(1,2);
|
||||
list.append(1,5);
|
||||
list.append(5,6);
|
||||
|
||||
qDebug()<< list.find(1); // "0,1"
|
||||
qDebug()<< list.find(SKIP,5); // "2"
|
||||
qDebug()<< list.find(5); // "2"
|
||||
|
||||
\endcode
|
||||
you may allso play around with the list itself
|
||||
|
||||
\code
|
||||
list.list.append(qMakePair(1,2));
|
||||
\endcode
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QxtNullable>
|
||||
#include <qxtglobal.h>
|
||||
|
||||
|
||||
|
||||
template <typename T, typename K>
|
||||
class QXT_CORE_EXPORT QxtPairList
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
QxtPairList()
|
||||
{}
|
||||
|
||||
QxtPairList(const QxtPairList<T, K> & other)
|
||||
{
|
||||
list = other.list;
|
||||
}
|
||||
|
||||
QxtPairList operator= (const QxtPairList<T, K> & other)
|
||||
{
|
||||
list = other.list;
|
||||
}
|
||||
|
||||
|
||||
void append(T v1, K v2)
|
||||
{
|
||||
list.append(qMakePair(v1, v2));
|
||||
}
|
||||
|
||||
|
||||
/*! \brief search entries by match
|
||||
|
||||
both arguments are optional, due to the use of QxtNullable
|
||||
|
||||
\code
|
||||
find(SKIP,v2);
|
||||
find(v1,SKIP);
|
||||
find(v1);
|
||||
\endcode
|
||||
are all valid
|
||||
*/
|
||||
|
||||
QList<int> find(qxtNull(T, v1) , qxtNull(K, v2))
|
||||
{
|
||||
QList<int> found;
|
||||
|
||||
if ((!v1.isNull()) and(!v2.isNull()))
|
||||
{
|
||||
for (int i = 0;i < list.count();i++)
|
||||
if ((list[i].first() == v1)and(list[i].second() == v2))
|
||||
found.append(i);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
if ((!v1.isNull()) and(v2.isNull()))
|
||||
{
|
||||
for (int i = 0;i < list.count();i++)
|
||||
if (list[i].first() == v1)
|
||||
found.append(i);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
if ((v1.isNull()) and(!v2.isNull()))
|
||||
{
|
||||
for (int i = 0;i < list.count();i++)
|
||||
if (list[i].second() == v2)
|
||||
found.append(i);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
///remove an entries position by position
|
||||
void remove(int nr)
|
||||
{
|
||||
list.removeAt(nr);
|
||||
}
|
||||
|
||||
///remove a list of entries by position
|
||||
void remove(QList<int> nrs)
|
||||
{
|
||||
int i;
|
||||
Q_FOREACH(i, nrs)
|
||||
list.removeAt(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*! \brief operate on the list directly
|
||||
|
||||
you may use the internal list directly, but be carefull
|
||||
don't expect to work the QxPairList to work normal if you mess around with it.
|
||||
*/
|
||||
|
||||
|
||||
QList<QPair<T, K> > list;
|
||||
};
|
||||
|
||||
#endif // QXTPAIRLIST_H
|
@ -1,26 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qxtglobal.h>
|
@ -1,254 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtpipe_p.h"
|
||||
#include <QList>
|
||||
#include <QQueue>
|
||||
#include <QMutableListIterator>
|
||||
|
||||
/*!
|
||||
* \class QxtPipe
|
||||
* \inmodule QxtCore
|
||||
* \brief The QxtPipe class provides a pipeable QIODevice
|
||||
*
|
||||
* pipes can be connected to other pipes, to exchange data
|
||||
* The default implementation uses a buffer.
|
||||
* Reimplement to make your custom class able to be connected into a pipe chain.
|
||||
*
|
||||
* Example usage:
|
||||
* \code
|
||||
* QxtPipe p1;
|
||||
* QxtPipe p2;
|
||||
* QxtPipe p3;
|
||||
* p1|p2|p3;
|
||||
* p1.write("hi. how are you?");
|
||||
* qDebug()<<p3.readAll();
|
||||
* p3.write("I'm fine, thanks.");
|
||||
* qDebug()<<p1.readAll();
|
||||
* \endcode
|
||||
|
||||
|
||||
<h4>Subclassing</h4>
|
||||
When implementing your own pipe element, like a de/encoder or something, you have to reimplement receiveData() and call sendData() whenever you have something to send to the pipe network.
|
||||
|
||||
If you want to the user to be able to read from the device directly via the QIODevice facility you have to call enqueuData() too
|
||||
|
||||
If you don't want to the user to be able to write to the device directly via the QIODevice facility (that would be fatal for a decoder, for example),
|
||||
then reimplement the functions readData() and writeData() and return 0.
|
||||
|
||||
|
||||
\sa QxtDeplex
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* Contructs a new QxtPipe with \a parent.
|
||||
*/
|
||||
QxtPipe::QxtPipe(QObject * parent): QIODevice(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtPipe);
|
||||
setOpenMode(QIODevice::ReadWrite);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*!\reimp*/
|
||||
bool QxtPipe::isSequential() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!\reimp*/
|
||||
qint64 QxtPipe::bytesAvailable() const
|
||||
{
|
||||
return qxt_d().q.count();
|
||||
}
|
||||
|
||||
/*!
|
||||
Pipes the output of this instance to the \a other QxtPipe using the given \a mode and \a connectionType.
|
||||
Returns \c true if succeeds. Connection pipes with this function can be considered thread safe.
|
||||
|
||||
Example usage:
|
||||
\code
|
||||
QxtPipe p1;
|
||||
QxtPipe p2;
|
||||
p1.connect(&p2,QIODevice::ReadOnly);
|
||||
|
||||
//this data will go nowhere. p2 is connected to p1, but not p2 to p1.
|
||||
p1.write("hello");
|
||||
|
||||
//while this data will end up in p1
|
||||
p2.write("world");
|
||||
|
||||
qDebug()<<p1.readAll();
|
||||
|
||||
\endcode
|
||||
*/
|
||||
bool QxtPipe::connect(QxtPipe * other , QIODevice::OpenMode mode, Qt::ConnectionType connectionType)
|
||||
{
|
||||
|
||||
///tell the other pipe to write into this
|
||||
if (mode & QIODevice::ReadOnly)
|
||||
{
|
||||
other->connect(this, QIODevice::WriteOnly, connectionType);
|
||||
}
|
||||
|
||||
|
||||
Connection c;
|
||||
c.pipe = other;
|
||||
c.mode = mode;
|
||||
c.connectionType = connectionType;
|
||||
qxt_d().connections.append(c);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Cuts the connection to the \a other QxtPipe and returns \c true if succeeds.
|
||||
*/
|
||||
bool QxtPipe::disconnect(QxtPipe * other)
|
||||
{
|
||||
bool e = false;
|
||||
|
||||
QMutableListIterator<Connection> i(qxt_d().connections);
|
||||
while (i.hasNext())
|
||||
{
|
||||
i.next();
|
||||
if (i.value().pipe == other)
|
||||
{
|
||||
i.remove();
|
||||
e = true;
|
||||
other->disconnect(this);
|
||||
}
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Convenience function for QxtPipe::connect().
|
||||
* Pipes the output of this instance to the \a target QxtPipe in readwrite mode with auto connection.
|
||||
*/
|
||||
QxtPipe & QxtPipe::operator | (QxtPipe & target)
|
||||
{
|
||||
connect(&target);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!\reimp*/
|
||||
qint64 QxtPipe::readData(char * data, qint64 maxSize)
|
||||
{
|
||||
QQueue<char> * q = &qxt_d().q;
|
||||
|
||||
qint64 i = 0;
|
||||
for (;i < maxSize;i++)
|
||||
{
|
||||
if (q->isEmpty())
|
||||
break;
|
||||
(*data++) = q->dequeue();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/*!\reimp*/
|
||||
qint64 QxtPipe::writeData(const char * data, qint64 maxSize)
|
||||
{
|
||||
sendData(QByteArray(data, maxSize));
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
Call this from your subclass to write \a data to the pipe network.
|
||||
All write connected pipes will be invoked with receiveData
|
||||
In this case this is called from receiveData, the sender will be excluded from the receiver list.
|
||||
*/
|
||||
|
||||
void QxtPipe::sendData(QByteArray data) const
|
||||
{
|
||||
foreach(const Connection& c, qxt_d().connections)
|
||||
{
|
||||
|
||||
|
||||
//don't write back to sender
|
||||
if (c.pipe == qxt_d().lastsender)
|
||||
continue;
|
||||
|
||||
|
||||
|
||||
if (!(c.mode & QIODevice::WriteOnly))
|
||||
continue;
|
||||
|
||||
|
||||
bool r = QMetaObject::invokeMethod(&c.pipe->qxt_d(), "push", c.connectionType,
|
||||
Q_ARG(QByteArray, data), Q_ARG(const QxtPipe *, this));
|
||||
|
||||
#ifdef QT_NO_DEBUG
|
||||
Q_UNUSED(r);
|
||||
#else
|
||||
if (!r)
|
||||
{
|
||||
QObject::connect(this, SIGNAL(readyRead()), &c.pipe->qxt_d(), SLOT(push(QByteArray, const QxtPipe *)), c.connectionType);
|
||||
qFatal("metacall failed. see debug output of QObject::connect above");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
qxt_d().lastsender = 0;
|
||||
|
||||
}
|
||||
/*!
|
||||
Call this from your subclass to make \a datab available to the QIODevice::read facility
|
||||
*/
|
||||
void QxtPipe::enqueData(QByteArray datab)
|
||||
{
|
||||
QQueue<char> * q = &qxt_d().q;
|
||||
|
||||
const char * data = datab.constData();
|
||||
qint64 maxSize = datab.size();
|
||||
|
||||
qint64 i = 0;
|
||||
for (;i < maxSize;i++)
|
||||
q->enqueue(*data++);
|
||||
if (i > 0)
|
||||
emit(readyRead());
|
||||
}
|
||||
|
||||
/*!
|
||||
This function is called from any connected pipe to input \a datab from \a sender into this instance.
|
||||
Reimplement this function to handle data from the pipe network.
|
||||
|
||||
The default implementation calls enqueData() and sendData().
|
||||
*/
|
||||
void QxtPipe::receiveData(QByteArray datab , const QxtPipe * sender)
|
||||
{
|
||||
enqueData(datab);
|
||||
qxt_d().lastsender = sender;
|
||||
sendData(datab);
|
||||
}
|
||||
|
||||
void QxtPipePrivate::push(QByteArray data, const QxtPipe * sender)
|
||||
{
|
||||
(&qxt_p())->receiveData(data, sender);
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTPIPE_H
|
||||
#define QXTPIPE_H
|
||||
#include "qxtglobal.h"
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QQueue>
|
||||
|
||||
class QxtPipePrivate;
|
||||
class QXT_CORE_EXPORT QxtPipe : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtPipe(QObject * parent = 0);
|
||||
|
||||
virtual bool isSequential() const;
|
||||
virtual qint64 bytesAvailable() const;
|
||||
|
||||
bool connect(QxtPipe * other ,
|
||||
QIODevice::OpenMode mode = QIODevice::ReadWrite,
|
||||
Qt::ConnectionType connectionTyp = Qt::AutoConnection);
|
||||
bool disconnect(QxtPipe * other);
|
||||
|
||||
QxtPipe & operator | (QxtPipe & target);
|
||||
|
||||
protected:
|
||||
virtual qint64 readData(char * data, qint64 maxSize);
|
||||
virtual qint64 writeData(const char * data, qint64 maxSize);
|
||||
|
||||
virtual void receiveData(QByteArray data, const QxtPipe * sender);
|
||||
void sendData(QByteArray data) const;
|
||||
void enqueData(QByteArray data);
|
||||
private:
|
||||
QXT_DECLARE_PRIVATE(QxtPipe)
|
||||
|
||||
};
|
||||
|
||||
#endif // QXTPIPE_H
|
@ -1,54 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXTPIPE_P_H
|
||||
#define QXTPIPE_P_H
|
||||
|
||||
#include "qxtpipe.h"
|
||||
|
||||
struct Connection
|
||||
{
|
||||
QxtPipe * pipe;
|
||||
QIODevice::OpenMode mode;
|
||||
Qt::ConnectionType connectionType;
|
||||
};
|
||||
|
||||
class QxtPipePrivate: public QObject, public QxtPrivate<QxtPipe>
|
||||
{
|
||||
Q_OBJECT
|
||||
QXT_DECLARE_PUBLIC(QxtPipe)
|
||||
public:
|
||||
QxtPipePrivate()
|
||||
{
|
||||
lastsender = 0;
|
||||
}
|
||||
QQueue<char> q;
|
||||
QList<Connection> connections;
|
||||
mutable const QxtPipe * lastsender;
|
||||
public Q_SLOTS:
|
||||
void push(QByteArray data, const QxtPipe * sender);
|
||||
};
|
||||
|
||||
#endif // QXTPIPE_P_H
|
@ -1,45 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Qxt Foundation. Some rights reserved.
|
||||
**
|
||||
** This file is part of the QxtCore module of the Qxt library.
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the Common Public License, version 1.0, as published
|
||||
** by IBM, and/or under the terms of the GNU Lesser General Public License,
|
||||
** version 2.1, as published by the Free Software Foundation.
|
||||
**
|
||||
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
|
||||
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
|
||||
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
|
||||
** FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** You should have received a copy of the CPL and the LGPL along with this
|
||||
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
|
||||
** included with the source distribution for more information.
|
||||
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
|
||||
**
|
||||
** <http://libqxt.org> <foundation@libqxt.org>
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qxtpointerlist.h"
|
||||
|
||||
/*!
|
||||
\class QxtPointerList
|
||||
|
||||
\inmodule QxtCore
|
||||
|
||||
\brief The QxtPointerList class manages a list of pointers to QObjects, that cleans itself
|
||||
|
||||
|
||||
when you add a QObject* to this list, it will be removed from the list when the QObject is deleted.
|
||||
|
||||
\sa QPointer
|
||||
|
||||
*/
|
||||
|
||||
void QxtPointerListDeleter::removeSender()
|
||||
{
|
||||
removeThisObject(QObject::sender());
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user