1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
141
qad_utils/.kdev4/qad_utils.kdev4
Normal file
@@ -0,0 +1,141 @@
|
||||
[Buildset]
|
||||
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x12\x00q\x00a\x00d\x00_\x00u\x00t\x00i\x00l\x00s)
|
||||
|
||||
[CMake]
|
||||
Build Directory Count=1
|
||||
Current Build Directory Index=0
|
||||
ProjectRootRelative=./
|
||||
|
||||
[CMake][CMake Build Directory 0]
|
||||
Build Directory Path=file:///mnt/data/orders/libs/qad_utils/
|
||||
Build Type=
|
||||
CMake Binary=file:///usr/bin/cmake
|
||||
Environment Profile=
|
||||
Extra Arguments=
|
||||
Install Directory=file:///usr/local
|
||||
|
||||
[Defines And Includes][Compiler]
|
||||
Name=GCC
|
||||
Path=gcc
|
||||
Type=GCC
|
||||
|
||||
[Filters]
|
||||
size=23
|
||||
|
||||
[Filters][0]
|
||||
inclusive=0
|
||||
pattern=.*
|
||||
targets=3
|
||||
|
||||
[Filters][1]
|
||||
inclusive=0
|
||||
pattern=.git
|
||||
targets=2
|
||||
|
||||
[Filters][10]
|
||||
inclusive=0
|
||||
pattern=*.a
|
||||
targets=1
|
||||
|
||||
[Filters][11]
|
||||
inclusive=0
|
||||
pattern=*.so
|
||||
targets=1
|
||||
|
||||
[Filters][12]
|
||||
inclusive=0
|
||||
pattern=*.so.*
|
||||
targets=1
|
||||
|
||||
[Filters][13]
|
||||
inclusive=0
|
||||
pattern=moc_*
|
||||
targets=1
|
||||
|
||||
[Filters][14]
|
||||
inclusive=0
|
||||
pattern=*.moc
|
||||
targets=1
|
||||
|
||||
[Filters][15]
|
||||
inclusive=0
|
||||
pattern=ui_*
|
||||
targets=1
|
||||
|
||||
[Filters][16]
|
||||
inclusive=0
|
||||
pattern=qrc_*
|
||||
targets=1
|
||||
|
||||
[Filters][17]
|
||||
inclusive=0
|
||||
pattern=*~
|
||||
targets=1
|
||||
|
||||
[Filters][18]
|
||||
inclusive=0
|
||||
pattern=.*.kate-swp
|
||||
targets=1
|
||||
|
||||
[Filters][19]
|
||||
inclusive=0
|
||||
pattern=.*.swp
|
||||
targets=1
|
||||
|
||||
[Filters][2]
|
||||
inclusive=0
|
||||
pattern=CVS
|
||||
targets=2
|
||||
|
||||
[Filters][20]
|
||||
inclusive=0
|
||||
pattern=*.pyc
|
||||
targets=1
|
||||
|
||||
[Filters][21]
|
||||
inclusive=0
|
||||
pattern=*.pyo
|
||||
targets=1
|
||||
|
||||
[Filters][22]
|
||||
inclusive=0
|
||||
pattern=__pycache__
|
||||
targets=1
|
||||
|
||||
[Filters][3]
|
||||
inclusive=0
|
||||
pattern=.svn
|
||||
targets=2
|
||||
|
||||
[Filters][4]
|
||||
inclusive=0
|
||||
pattern=_svn
|
||||
targets=2
|
||||
|
||||
[Filters][5]
|
||||
inclusive=0
|
||||
pattern=SCCS
|
||||
targets=2
|
||||
|
||||
[Filters][6]
|
||||
inclusive=0
|
||||
pattern=_darcs
|
||||
targets=2
|
||||
|
||||
[Filters][7]
|
||||
inclusive=0
|
||||
pattern=.hg
|
||||
targets=2
|
||||
|
||||
[Filters][8]
|
||||
inclusive=0
|
||||
pattern=.bzr
|
||||
targets=2
|
||||
|
||||
[Filters][9]
|
||||
inclusive=0
|
||||
pattern=*.o
|
||||
targets=1
|
||||
|
||||
[MakeBuilder]
|
||||
Number Of Jobs=8
|
||||
45
qad_utils/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
project(qad_utils)
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
find_package(Qt4 REQUIRED)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDES})
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
|
||||
set(MOCS "qpiconfig.h" "qpiconfigwidget.h" "qpievaluator.h"
|
||||
"qpiconfignewdialog.h" "qpiconfigvaluewidget.h"
|
||||
"session_manager.h" "chunkstream.h")
|
||||
set(CPPS "qpiconfig.cpp" "qpiconfigwidget.cpp" "qpievaluator.cpp"
|
||||
"qpiconfignewdialog.cpp" "qpiconfigvaluewidget.cpp"
|
||||
"session_manager.cpp" "chunkstream.cpp")
|
||||
file(GLOB UIS "./*.ui")
|
||||
file(GLOB RES "./*.qrc")
|
||||
qt4_wrap_ui(CUIS ${UIS})
|
||||
qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw)
|
||||
qt4_add_resources(CRES ${RES})
|
||||
add_library(qad_utils SHARED ${CPPS} ${CUIS} ${CMOCS} ${CRES})
|
||||
set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} qad_widgets)
|
||||
if (${WIN32})
|
||||
list(APPEND LIBS opengl32 glu32)
|
||||
else (${WIN32})
|
||||
list(APPEND LIBS GL GLU)
|
||||
endif (${WIN32})
|
||||
target_link_libraries(qad_utils ${LIBS})
|
||||
if (DEFINED LIB)
|
||||
set(LIB 1)
|
||||
if (${WIN32})
|
||||
find_package(MinGW REQUIRED)
|
||||
set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
|
||||
install(FILES ${MOCS} DESTINATION ${MINGW_INCLUDE})
|
||||
install(TARGETS qad_utils DESTINATION ${MINGW_LIB})
|
||||
get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH)
|
||||
install(TARGETS qad_utils DESTINATION ${QTDIR})
|
||||
else ()
|
||||
set(CMAKE_INSTALL_PREFIX /usr)
|
||||
install(FILES ${MOCS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
|
||||
install(TARGETS qad_utils DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
endif ()
|
||||
else ()
|
||||
install(TARGETS qad_utils DESTINATION bin)
|
||||
endif ()
|
||||
35
qad_utils/chunkstream.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "chunkstream.h"
|
||||
|
||||
|
||||
void ChunkStream::setSource(const QByteArray & data) {
|
||||
data_ = const_cast<QByteArray*>(&data);
|
||||
_init();
|
||||
}
|
||||
|
||||
|
||||
void ChunkStream::setSource(QByteArray * data) {
|
||||
data_ = (data ? data : &tmp_data);
|
||||
_init();
|
||||
}
|
||||
|
||||
|
||||
void ChunkStream::setSource(QDataStream & str) {
|
||||
str >> tmp_data;
|
||||
data_ = &tmp_data;
|
||||
_init();
|
||||
}
|
||||
|
||||
|
||||
ChunkStream::~ChunkStream() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ChunkStream::_init() {
|
||||
last_id = -1;
|
||||
last_data.clear();
|
||||
buffer.close();
|
||||
buffer.setBuffer(data_);
|
||||
buffer.open(QIODevice::ReadWrite);
|
||||
stream_.setDevice(&buffer);
|
||||
}
|
||||
56
qad_utils/chunkstream.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef CHUNKSTREAM_H
|
||||
#define CHUNKSTREAM_H
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QBuffer>
|
||||
#include <QByteArray>
|
||||
|
||||
|
||||
class ChunkStream
|
||||
{
|
||||
public:
|
||||
ChunkStream(const QByteArray & data) {setSource(data);}
|
||||
ChunkStream(QDataStream & str) {setSource(str);}
|
||||
ChunkStream(QByteArray * data = 0) {setSource(data);}
|
||||
~ChunkStream();
|
||||
|
||||
template <typename T>
|
||||
struct Chunk {
|
||||
Chunk(int i, const T & d): id(i), data(d) {}
|
||||
int id;
|
||||
T data;
|
||||
};
|
||||
template <typename T> static Chunk<T> chunk(int id, const T & data) {return Chunk<T>(id, data);}
|
||||
|
||||
void setSource(const QByteArray & data);
|
||||
void setSource(QDataStream & str);
|
||||
void setSource(QByteArray * data);
|
||||
QDataStream & dataStream() {return stream_;}
|
||||
QByteArray data() const {return tmp_data;}
|
||||
bool atEnd() const {return stream_.atEnd();}
|
||||
|
||||
int read() {stream_ >> last_id >> last_data; return last_id;}
|
||||
int getID() {return last_id;}
|
||||
template <typename T>
|
||||
T getData() const {T ret; QDataStream s(last_data); s >> ret; return ret;}
|
||||
|
||||
private:
|
||||
void _init();
|
||||
|
||||
int last_id;
|
||||
QByteArray * data_, last_data, tmp_data;
|
||||
QBuffer buffer;
|
||||
QDataStream stream_;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
ChunkStream & operator <<(ChunkStream & s, const ChunkStream::Chunk<T> & c) {
|
||||
QByteArray ba;
|
||||
QDataStream bas(&ba, QIODevice::WriteOnly);
|
||||
bas << c.data;
|
||||
s.dataStream() << c.id << ba;
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // CHUNKSTREAM_H
|
||||
4
qad_utils/clean
Normal file
@@ -0,0 +1,4 @@
|
||||
#! /bin/bash
|
||||
VERBOSE=1 make clean
|
||||
rm -rvf CMakeFiles
|
||||
rm -vf CMakeCache.txt Makefile cmake_install.cmake install_manifest.txt *.dll *.a *.so *.user* *~ *cxx moc_* ui_* qrc_* *.o *.bak
|
||||
4
qad_utils/clean.bat
Normal file
@@ -0,0 +1,4 @@
|
||||
#make clean
|
||||
del /q /f /s CMakeFiles
|
||||
rmdir /q /s CMakeFiles
|
||||
del /q /f CMakeCache.txt Makefile cmake_install.cmake install_manifest.txt *.user* *~ *cxx moc_* ui_* qrc_* *.o *.exe *.a *.dll *.lib core *.bak
|
||||
BIN
qad_utils/icons/alpha.png
Normal file
|
After Width: | Height: | Size: 158 B |
BIN
qad_utils/icons/border-line.png
Normal file
|
After Width: | Height: | Size: 183 B |
BIN
qad_utils/icons/chardialog.png
Normal file
|
After Width: | Height: | Size: 943 B |
BIN
qad_utils/icons/clineedit.png
Normal file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
qad_utils/icons/colorbutton.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
qad_utils/icons/configure.png
Normal file
|
After Width: | Height: | Size: 717 B |
BIN
qad_utils/icons/dialog-close.png
Normal file
|
After Width: | Height: | Size: 813 B |
BIN
qad_utils/icons/document-open.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
qad_utils/icons/document-open_16.png
Normal file
|
After Width: | Height: | Size: 701 B |
BIN
qad_utils/icons/document-save.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
qad_utils/icons/ecombobox.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
qad_utils/icons/edit-clear-locationbar-rtl.png
Normal file
|
After Width: | Height: | Size: 644 B |
BIN
qad_utils/icons/edit-clear.png
Normal file
|
After Width: | Height: | Size: 802 B |
BIN
qad_utils/icons/edit-copy.png
Normal file
|
After Width: | Height: | Size: 485 B |
BIN
qad_utils/icons/edit-delete.png
Normal file
|
After Width: | Height: | Size: 640 B |
BIN
qad_utils/icons/edit-find.png
Normal file
|
After Width: | Height: | Size: 634 B |
BIN
qad_utils/icons/edit-guides.png
Normal file
|
After Width: | Height: | Size: 544 B |
BIN
qad_utils/icons/edit-paste.png
Normal file
|
After Width: | Height: | Size: 529 B |
BIN
qad_utils/icons/etabwidget.png
Normal file
|
After Width: | Height: | Size: 693 B |
BIN
qad_utils/icons/expand_s_x.png
Normal file
|
After Width: | Height: | Size: 571 B |
BIN
qad_utils/icons/expand_s_y.png
Normal file
|
After Width: | Height: | Size: 577 B |
BIN
qad_utils/icons/expand_x.png
Normal file
|
After Width: | Height: | Size: 579 B |
BIN
qad_utils/icons/expand_y.png
Normal file
|
After Width: | Height: | Size: 577 B |
BIN
qad_utils/icons/item-add.png
Normal file
|
After Width: | Height: | Size: 639 B |
BIN
qad_utils/icons/item.png
Normal file
|
After Width: | Height: | Size: 448 B |
BIN
qad_utils/icons/legend.png
Normal file
|
After Width: | Height: | Size: 810 B |
BIN
qad_utils/icons/list-add.png
Normal file
|
After Width: | Height: | Size: 564 B |
BIN
qad_utils/icons/node-add.png
Normal file
|
After Width: | Height: | Size: 694 B |
BIN
qad_utils/icons/node.png
Normal file
|
After Width: | Height: | Size: 658 B |
BIN
qad_utils/icons/qcodeedit.png
Normal file
|
After Width: | Height: | Size: 818 B |
BIN
qad_utils/icons/qpiconsole.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
qad_utils/icons/spinslider.png
Normal file
|
After Width: | Height: | Size: 830 B |
BIN
qad_utils/icons/view-grid.png
Normal file
|
After Width: | Height: | Size: 691 B |
BIN
qad_utils/icons/zoom-fit-best.png
Normal file
|
After Width: | Height: | Size: 539 B |
1
qad_utils/make_lib.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmake_mgw -DLIB= && make install && qmake && make install
|
||||
14
qad_utils/qad_utils.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "qpiconfigplugin.h"
|
||||
#include "qad_utils.h"
|
||||
|
||||
QADUtils::QADUtils(QObject * parent): QObject(parent)
|
||||
{
|
||||
m_widgets.append(new QPIConfigPlugin(this));
|
||||
}
|
||||
|
||||
|
||||
QList<QDesignerCustomWidgetInterface * > QADUtils::customWidgets() const {
|
||||
return m_widgets;
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN2(qad_utils_plugin, QADUtils)
|
||||
21
qad_utils/qad_utils.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef QAD_UTILS_H
|
||||
#define QAD_UTILS_H
|
||||
|
||||
#include <QtDesigner/QtDesigner>
|
||||
#include <QtCore/qplugin.h>
|
||||
|
||||
class QADUtils: public QObject, public QDesignerCustomWidgetCollectionInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||
|
||||
public:
|
||||
explicit QADUtils(QObject * parent = 0);
|
||||
virtual QList<QDesignerCustomWidgetInterface * > customWidgets() const;
|
||||
|
||||
private:
|
||||
QList<QDesignerCustomWidgetInterface * > m_widgets;
|
||||
|
||||
};
|
||||
|
||||
#endif // QAD_UTILS_H
|
||||
3
qad_utils/qad_utils.kdev4
Normal file
@@ -0,0 +1,3 @@
|
||||
[Project]
|
||||
Manager=KDevCMakeManager
|
||||
Name=qad_utils
|
||||
18
qad_utils/qad_utils.pro
Normal file
@@ -0,0 +1,18 @@
|
||||
### eqmake4 was here ###
|
||||
CONFIG += designer plugin release
|
||||
TARGET = $$qtLibraryTarget(qad_utils_plugin)
|
||||
TEMPLATE = lib
|
||||
|
||||
HEADERS = qad_utils.h qpiconfigplugin.h
|
||||
SOURCES = qad_utils.cpp qpiconfigplugin.cpp
|
||||
#RESOURCES = qad_utils.qrc
|
||||
#TRANSLATIONS = lang/ru.ts
|
||||
LIBS += -L. -lqad_utils -lqad_widgets
|
||||
QMAKE_CXXFLAGS += -g3
|
||||
QMAKE_CFLAGS += -g3
|
||||
|
||||
target.path = $$[QT_INSTALL_PLUGINS]/designer
|
||||
INSTALLS += target
|
||||
|
||||
CONFIG -= debug_and_release debug
|
||||
CONFIG += release
|
||||
17
qad_utils/qad_utils.qrc
Normal file
@@ -0,0 +1,17 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>icons/edit-clear.png</file>
|
||||
<file>icons/document-save.png</file>
|
||||
<file>icons/edit-clear-locationbar-rtl.png</file>
|
||||
<file>icons/edit-find.png</file>
|
||||
<file>icons/list-add.png</file>
|
||||
<file>icons/edit-delete.png</file>
|
||||
<file>icons/item-add.png</file>
|
||||
<file>icons/item.png</file>
|
||||
<file>icons/node-add.png</file>
|
||||
<file>icons/node.png</file>
|
||||
<file>icons/edit-copy.png</file>
|
||||
<file>icons/edit-paste.png</file>
|
||||
<file>icons/document-open_16.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
17
qad_utils/qad_utils.qrc.depends
Normal file
@@ -0,0 +1,17 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>icons/edit-clear.png</file>
|
||||
<file>icons/document-save.png</file>
|
||||
<file>icons/edit-clear-locationbar-rtl.png</file>
|
||||
<file>icons/edit-find.png</file>
|
||||
<file>icons/list-add.png</file>
|
||||
<file>icons/edit-delete.png</file>
|
||||
<file>icons/item-add.png</file>
|
||||
<file>icons/item.png</file>
|
||||
<file>icons/node-add.png</file>
|
||||
<file>icons/node.png</file>
|
||||
<file>icons/edit-copy.png</file>
|
||||
<file>icons/edit-paste.png</file>
|
||||
<file>icons/document-open_16.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
690
qad_utils/qpiconfig.cpp
Normal file
@@ -0,0 +1,690 @@
|
||||
#include "qpiconfig.h"
|
||||
|
||||
|
||||
int QString2int(const QString & string) {
|
||||
QString s = string.trimmed();
|
||||
if (s.left(2) == "0x") return s.mid(2).toLongLong(0, 16);
|
||||
if (s.left(1) == "0") return s.mid(1).toLongLong(0, 8);
|
||||
return s.toLongLong();
|
||||
}
|
||||
|
||||
|
||||
QRect QString2QRect(const QString & string) {
|
||||
int sl, st, sw, sh;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toInt();
|
||||
return QRect(sl, st, sw, sh);
|
||||
}
|
||||
|
||||
|
||||
QRectF QString2QRectF(const QString & string) {
|
||||
double sl, st, sw, sh;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toDouble();
|
||||
return QRectF(sl, st, sw, sh);
|
||||
}
|
||||
|
||||
|
||||
QPoint QString2QPoint(const QString & string) {
|
||||
int sx, sy;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toInt();
|
||||
return QPoint(sx, sy);
|
||||
}
|
||||
|
||||
|
||||
QPointF QString2QPointF(const QString & string) {
|
||||
double sx, sy;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toDouble();
|
||||
return QPointF(sx, sy);
|
||||
}
|
||||
|
||||
|
||||
QString QRect2QString(const QRect & rect) {
|
||||
return QString::number(rect.left()) + ";" +
|
||||
QString::number(rect.top()) + ";" +
|
||||
QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
}
|
||||
|
||||
|
||||
QString QRectF2QString(const QRectF & rect) {
|
||||
return QString::number(rect.left()) + ";" +
|
||||
QString::number(rect.top()) + ";" +
|
||||
QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry QPIConfig::Branch::_empty;
|
||||
QPIConfig::Entry QPIConfig::Entry::_empty;
|
||||
|
||||
|
||||
QPIConfig::Branch QPIConfig::Branch::allLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this) {
|
||||
if (i->isLeaf()) b << i;
|
||||
else allLeaves(b, i);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::Branch::getValue(const QString & vname, const QString & def, bool * exist) {
|
||||
if (vname.isEmpty()) {
|
||||
_empty.clear();
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
QStringList tree = vname.split(delim);
|
||||
QString name = tree.front();
|
||||
tree.pop_front();
|
||||
Entry * ce = 0;
|
||||
foreach (Entry * i, *this)
|
||||
if (i->_name == name) {
|
||||
ce = i;
|
||||
break;
|
||||
}
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
foreach (QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
}
|
||||
if (exist != 0) *exist = true;
|
||||
return *ce;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Branch QPIConfig::Branch::getValues(const QString & name) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this) {
|
||||
if (i->isLeaf()) {
|
||||
if (i->_name.indexOf(name) >= 0)
|
||||
b << i;
|
||||
} else {
|
||||
foreach (Entry * j, i->_children)
|
||||
if (j->_name.indexOf(name) >= 0)
|
||||
b << j;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Branch QPIConfig::Branch::getLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this)
|
||||
if (i->isLeaf())
|
||||
b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Branch QPIConfig::Branch::getBranches() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this)
|
||||
if (!i->isLeaf())
|
||||
b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Branch & QPIConfig::Branch::filter(const QString & f) {
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
if (at(i)->_name.indexOf(f) < 0) {
|
||||
remove(i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfig::Branch::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::Entry::getValue(const QString & vname, const QString & def, bool * exist) {
|
||||
QStringList tree = vname.split(delim);
|
||||
Entry * ce = this;
|
||||
foreach (QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
}
|
||||
if (exist != 0) *exist = true;
|
||||
return *ce;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Branch QPIConfig::Entry::getValues(const QString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, _children)
|
||||
if (i->_name.indexOf(vname) >= 0)
|
||||
b << i;
|
||||
return b;
|
||||
};
|
||||
|
||||
|
||||
bool QPIConfig::Entry::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::QPIConfig(const QString & path, QIODevice::OpenMode mode, QPIConfig::FileType type_): QFile(path) {
|
||||
init();
|
||||
type = type_;
|
||||
open(mode);
|
||||
//stream.setDevice(this);
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::QPIConfig(const QString & path, QIODevice::OpenMode mode): QFile(path) {
|
||||
init();
|
||||
type = Config;
|
||||
open(mode);
|
||||
//stream.setDevice(this);
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::QPIConfig(const QString & path, QPIConfig::FileType type_): QFile(path) {
|
||||
init();
|
||||
type = type_;
|
||||
open(QIODevice::ReadWrite);
|
||||
//stream.setDevice(this);
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::QPIConfig(QString * str, QPIConfig::FileType type_) {
|
||||
init();
|
||||
type = type_;
|
||||
buffer = str;
|
||||
//stream.setDevice(this);
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::init() {
|
||||
buffer = 0;
|
||||
delim = ".";
|
||||
root._name = "root";
|
||||
root.delim = delim;
|
||||
empty.delim = delim;
|
||||
empty._parent = 0;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::setFile(const QString & path, QIODevice::OpenMode mode) {
|
||||
buffer = 0;
|
||||
setFileName(path);
|
||||
if (open(mode))
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::setString(QString * str) {
|
||||
buffer = str;
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::getValue(const QString & vname, const QString & def, bool * exist) {
|
||||
QStringList tree = vname.split(delim);
|
||||
Entry * ce = &root;
|
||||
foreach (QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
if (exist != 0) *exist = false;
|
||||
empty._name = vname;
|
||||
empty._value = def;
|
||||
empty.delim = delim;
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
if (exist != 0) *exist = true;
|
||||
return *ce;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Branch QPIConfig::getValues(const QString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, root._children)
|
||||
if (i->_name.indexOf(vname) >= 0)
|
||||
b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::addEntry(const QString & name, const QString & value, const QString & type, bool write, bool node) {
|
||||
if (getValue(name)._parent != 0)
|
||||
return empty;
|
||||
QString sn = name, tn;
|
||||
bool toRoot = false;
|
||||
while (sn.indexOf(delim) == 0) sn.remove(0, delim.length());
|
||||
QStringList tree = sn.split(delim);
|
||||
QString ename = tree.back();
|
||||
tn = tree.front();
|
||||
tree.pop_back();
|
||||
Entry * te, * ce, * entry = &root;
|
||||
if (tree.isEmpty()) toRoot = true;
|
||||
foreach (QString i, tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = entry->_tab;
|
||||
ce->_line = entry->_line;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
//qDebug() << " [QPIC] add " + tn;
|
||||
ce->_full_name = tn;
|
||||
entry->_children << ce;
|
||||
entry = ce;
|
||||
} else entry = te;
|
||||
tn += delim + i;
|
||||
}
|
||||
QPIConfig::Branch ch = entry->_children;
|
||||
qSort(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
te = (entry->isLeaf() ? 0 : ch.back());
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_name = ename;
|
||||
if (!node) ce->_value = value;
|
||||
ce->_type = type;
|
||||
if (te == 0) {
|
||||
//qDebug() << "[QPIC] te == 0";
|
||||
ce->_tab = entry->_tab;
|
||||
if (toRoot) ce->_line = other.size();
|
||||
else {
|
||||
ch = entry->_parent->_children;
|
||||
qSort(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
ce->_line = ch.back()->_line + 1;
|
||||
}
|
||||
} else {
|
||||
ce->_tab = te->_tab;
|
||||
if (toRoot) ce->_line = other.size();
|
||||
else ce->_line = te->_line + 1;
|
||||
}
|
||||
//qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " << entry->_name;
|
||||
ce->_full_name = sn;
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
//qDebug() << "[QPIC] children " << entry->childCount();
|
||||
if (!node) {
|
||||
other.insert(ce->_line, "");
|
||||
Branch b = allLeaves();
|
||||
//qDebug() << "[QPIC] allLeaves " << b.size();
|
||||
bool found = false;
|
||||
for (int i = 0; i < b.size(); ++i) {
|
||||
if (found) {
|
||||
b[i]->_line++;
|
||||
continue;
|
||||
}
|
||||
if (b[i] == ce) {
|
||||
found = true;
|
||||
if (i > 0)
|
||||
if (b[i - 1]->_line == b[i]->_line)
|
||||
b[i - 1]->_line++;
|
||||
}
|
||||
//qDebug() << b[i]->_line;
|
||||
}
|
||||
}
|
||||
//qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " + entry->_name;
|
||||
if (write) writeAll();
|
||||
return *ce;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::setValue(const QString & name, const QString & value, const QString & type, bool write) {
|
||||
Entry & e(getValue(name));
|
||||
if (&e == &empty) {
|
||||
addEntry(name, value, type, write);
|
||||
return;
|
||||
}
|
||||
e._value = value;
|
||||
e._type = type;
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
|
||||
int QPIConfig::entryIndex(const QString & name) {
|
||||
QStringList tree = name.split(delim);
|
||||
Entry * ce = &root;
|
||||
foreach (QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0)
|
||||
return -1;
|
||||
}
|
||||
Branch b = allLeaves();
|
||||
return allLeaves().indexOf(ce);
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::setValue(uint number, const QString & value, bool write) {
|
||||
Entry & e(entryByIndex(number));
|
||||
if (&e == &empty) return;
|
||||
e._value = value;
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::setName(uint number, const QString & name, bool write) {
|
||||
Entry & e(entryByIndex(number));
|
||||
if (&e == &empty) return;
|
||||
e._name = name;
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::setType(uint number, const QString & type, bool write) {
|
||||
Entry & e(entryByIndex(number));
|
||||
if (&e == &empty) return;
|
||||
e._type = type;
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::setComment(uint number, const QString & comment, bool write) {
|
||||
Entry & e(entryByIndex(number));
|
||||
if (&e == &empty) return;
|
||||
e._comment = comment;
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::removeEntry(const QString & name, bool write) {
|
||||
Entry & e(getValue(name));
|
||||
if (&e == &empty) return;
|
||||
Branch b = allLeaves();
|
||||
removeEntry(b, &e);
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::removeEntry(uint number, bool write) {
|
||||
Entry & e(entryByIndex(number));
|
||||
if (&e == &empty) return;
|
||||
Branch b = allLeaves();
|
||||
removeEntry(b, &e);
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::removeEntry(Branch & b, QPIConfig::Entry * e) {
|
||||
bool leaf = true;
|
||||
//qDebug() << " before " << b.size();
|
||||
if (e->isLeaf()) other.removeAt(e->_line);
|
||||
if (!e->isLeaf() && !e->_value.isEmpty()) {
|
||||
e->_value.clear();
|
||||
//leaf = false;
|
||||
} else {
|
||||
int cc = e->_children.size();
|
||||
for (int i = 0; i < cc; ++i)
|
||||
removeEntry(b, e->_children.back());
|
||||
}
|
||||
bool found = false;
|
||||
for (int i = 0; i < b.size(); ++i) {
|
||||
if (found) {
|
||||
b[i]->_line--;
|
||||
continue;
|
||||
}
|
||||
if (b[i] == e) found = true;
|
||||
}
|
||||
if (!leaf) return;
|
||||
int ti = e->_parent->_children.indexOf(e);
|
||||
if (ti >= 0) e->_parent->_children.remove(ti);
|
||||
ti = b.indexOf(e);
|
||||
if (ti >= 0) b.remove(ti);
|
||||
//qDebug() << " after " << b.size();
|
||||
delete e;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::writeAll() {
|
||||
if (buffer == 0) {
|
||||
stream.setDevice(this);
|
||||
resize(0);
|
||||
} else {
|
||||
stream.setString(buffer);
|
||||
buffer->clear();
|
||||
}
|
||||
stream.seek(0);
|
||||
//writeEntry(&root);
|
||||
buildFullNames(&root);
|
||||
Branch b = allLeaves();
|
||||
int j = 0;
|
||||
for (int i = 0; i < other.size(); ++i) {
|
||||
//cout << j << endl;
|
||||
if (j >= 0 && j < b.size()) {
|
||||
if (b[j]->_line == i) {
|
||||
b[j]->buildLine();
|
||||
stream << b[j]->_all << '\n';
|
||||
++j;
|
||||
} else {
|
||||
stream << other[i];
|
||||
if (i < other.size() - 1) stream << '\n';
|
||||
}
|
||||
} else {
|
||||
stream << other[i];
|
||||
if (i < other.size() - 1) stream << '\n';
|
||||
}
|
||||
}
|
||||
if (buffer == 0)
|
||||
flush();
|
||||
readAll();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfig::writeAllToString() {
|
||||
QString str;
|
||||
QTextStream s(&str);
|
||||
//writeEntry(&root);
|
||||
buildFullNames(&root);
|
||||
Branch b = allLeaves();
|
||||
int j = 0;
|
||||
for (int i = 0; i < other.size(); ++i) {
|
||||
//cout << j << endl;
|
||||
if (j >= 0 && j < b.size()) {
|
||||
if (b[j]->_line == i) {
|
||||
b[j]->buildLine();
|
||||
s << b[j]->_all << '\n';
|
||||
++j;
|
||||
} else {
|
||||
s << other[i];
|
||||
if (i < other.size() - 1) s << '\n';
|
||||
}
|
||||
} else {
|
||||
s << other[i];
|
||||
if (i < other.size() - 1) s << '\n';
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::readAllFromString(const QString & str) {
|
||||
parse(str);
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::clear() {
|
||||
root.deleteBranch();
|
||||
root.clear();
|
||||
other.clear();
|
||||
if (buffer == 0)
|
||||
resize(0);
|
||||
else
|
||||
buffer->clear();
|
||||
stream.seek(0);
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::readAll() {
|
||||
if (buffer == 0)
|
||||
flush();
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfig::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::parse(QString content) {
|
||||
root.deleteBranch();
|
||||
root.clear();
|
||||
QString src, str, tab, comm, all, name, type;
|
||||
QStringList tree;
|
||||
Entry * entry, * te, * ce;
|
||||
int ind, sind;
|
||||
bool isNew;
|
||||
if (content.isEmpty()) {
|
||||
if (buffer == 0) {
|
||||
if (!isOpen()) return;
|
||||
stream.setDevice(this);
|
||||
} else
|
||||
stream.setString(buffer);
|
||||
} else {
|
||||
stream.setString(&content);
|
||||
}
|
||||
stream.seek(0);
|
||||
other.clear();
|
||||
lines = centry = 0;
|
||||
while (!stream.atEnd()) {
|
||||
other.push_back(QString());
|
||||
src = str = stream.readLine();
|
||||
//cout << str << endl;
|
||||
tab = str.left(str.indexOf(str.trimmed().left(1)));
|
||||
str = str.trimmed();
|
||||
all = str;
|
||||
ind = str.indexOf('=');
|
||||
if ((ind > 0) && !(str[0] == '#')) {
|
||||
sind = str.indexOf('#');
|
||||
if (sind > 0) {
|
||||
comm = str.right(str.length() - sind - 1).trimmed();
|
||||
if (comm.length() > 0) type = comm[0];
|
||||
else type = "s";
|
||||
comm = comm.right(comm.length() - 1).trimmed();
|
||||
str = str.left(sind);
|
||||
} else {
|
||||
type = "s";
|
||||
comm = "";
|
||||
}
|
||||
//name = str.left(ind).trimmed();
|
||||
tree = str.left(ind).trimmed().split(delim);
|
||||
name = tree.back();
|
||||
tree.pop_back();
|
||||
entry = &root;
|
||||
foreach (QString i, tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_line = lines;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
entry = ce;
|
||||
} else entry = te;
|
||||
}
|
||||
isNew = false;
|
||||
ce = entry->findChild(name);
|
||||
if (ce == 0) {
|
||||
ce = new Entry();
|
||||
isNew = true;
|
||||
}
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_name = name;
|
||||
ce->_value = str.right(str.length() - ind - 1).trimmed();
|
||||
ce->_type = type;
|
||||
ce->_comment = comm;
|
||||
ce->_line = lines;
|
||||
ce->_all = all;
|
||||
if (isNew) {
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
}
|
||||
} else other.back() = src;
|
||||
lines++;
|
||||
}
|
||||
setEntryDelim(&root, delim);
|
||||
//if (content.isEmpty()) stream.setDevice(this);
|
||||
}
|
||||
285
qad_utils/qpiconfig.h
Normal file
@@ -0,0 +1,285 @@
|
||||
#ifndef QPICONFIG_H
|
||||
#define QPICONFIG_H
|
||||
|
||||
#include "QFile"
|
||||
#include "QVector"
|
||||
#include "QStringList"
|
||||
#include "QTextStream"
|
||||
|
||||
#include <QColor>
|
||||
#include <QPointF>
|
||||
#include <QRectF>
|
||||
#include <QDebug>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline QByteArray QString2QByteArray(const QString & string) {return qUncompress(QByteArray::fromBase64(string.toLatin1()));}
|
||||
int QString2int(const QString & string);
|
||||
inline QColor QString2QColor(const QString & string) {
|
||||
QColor col;
|
||||
if (string.left(1) == "#")
|
||||
col = QColor(string.right(string.length() - 1).toInt(0, 16));
|
||||
else
|
||||
col = QColor(QString2int(string));
|
||||
return col;
|
||||
|
||||
}
|
||||
QRect QString2QRect(const QString & string);
|
||||
QRectF QString2QRectF(const QString & string);
|
||||
QPoint QString2QPoint(const QString & string);
|
||||
QPointF QString2QPointF(const QString & string);
|
||||
|
||||
inline QString QColor2QString(const QColor & color) {QString s = color.name(); return "0x" + QString::number(color.alpha(), 16).rightJustified(2, '0') + s.right(s.length() - 1);}
|
||||
inline QString QPoint2QString(const QPoint & point) {return QString::number(point.x()) + ";" + QString::number(point.y());}
|
||||
inline QString QPointF2QString(const QPointF & point) {return QString::number(point.x()) + ";" + QString::number(point.y());}
|
||||
inline QString QByteArray2QString(const QByteArray & array) {return QString(qCompress(array, 9).toBase64());}
|
||||
QString QRect2QString(const QRect & rect);
|
||||
QString QRectF2QString(const QRectF & rect);
|
||||
|
||||
#define QPICONFIG_GET_VALUE \
|
||||
inline Entry & getValue(const QString & vname, const char * def, bool * exist = 0) {return getValue(vname, QString(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const QStringList & def, bool * exist = 0) {return getValue(vname, def.join("%|%"), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const bool def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const short def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const int def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const long def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const uchar def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const ushort def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const uint def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const ulong def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const float def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const double def, bool * exist = 0) {return getValue(vname, QString::number(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const QColor & def, bool * exist = 0) {return getValue(vname, QColor2QString(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const Qt::GlobalColor def, bool * exist = 0) {return getValue(vname, QColor(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const QRect & def, bool * exist = 0) {return getValue(vname, QRect2QString(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const QRectF & def, bool * exist = 0) {return getValue(vname, QRectF2QString(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const QPoint & def, bool * exist = 0) {return getValue(vname, QPoint2QString(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const QPointF & def, bool * exist = 0) {return getValue(vname, QPointF2QString(def), exist);} \
|
||||
inline Entry & getValue(const QString & vname, const QByteArray & def, bool * exist = 0) {return getValue(vname, QByteArray2QString(def), exist);}
|
||||
|
||||
class QPIConfig: public QFile
|
||||
{
|
||||
friend class Entry;
|
||||
friend class Branch;
|
||||
friend class QPIConfigWidget;
|
||||
public:
|
||||
enum FileType {Config, XML};
|
||||
|
||||
QPIConfig(const QString & path, QIODevice::OpenMode mode, QPIConfig::FileType type);
|
||||
QPIConfig(const QString & path, QIODevice::OpenMode mode = QIODevice::ReadWrite);
|
||||
QPIConfig(const QString & path, QPIConfig::FileType type);
|
||||
QPIConfig(QString * str, QPIConfig::FileType type = QPIConfig::Config);
|
||||
~QPIConfig() {stream.setDevice(0); root.deleteBranch();}
|
||||
|
||||
void setFile(const QString & path, QIODevice::OpenMode mode = QIODevice::ReadWrite);
|
||||
void setString(QString * str);
|
||||
|
||||
class Entry;
|
||||
|
||||
class Branch: public QVector<Entry * > {
|
||||
friend class QPIConfig;
|
||||
friend class Entry;
|
||||
public:
|
||||
inline Branch() {;}
|
||||
|
||||
Entry & getValue(const QString & vname, const QString & def = QString(), bool * exist = 0);
|
||||
QPICONFIG_GET_VALUE
|
||||
|
||||
Branch allLeaves();
|
||||
Branch getValues(const QString & name);
|
||||
Branch getLeaves();
|
||||
Branch getBranches();
|
||||
Branch & filter(const QString & f);
|
||||
inline bool isEntryExists(const QString & name) const {foreach (const Entry * i, *this) if (entryExists(i, name)) return true; return false;}
|
||||
inline int indexOf(const Entry * e) {for (int i = 0; i < size(); ++i) if (at(i) == e) return i; return -1;}
|
||||
|
||||
//inline void clear() {foreach (Entry * i, *this) delete i; QVector<Entry * >::clear();}
|
||||
|
||||
private:
|
||||
bool entryExists(const Entry * e, const QString & name) const;
|
||||
inline void allLeaves(Branch & b, Entry * e) {foreach (Entry * i, e->_children) {if (i->isLeaf()) b << i; else allLeaves(b, i);}}
|
||||
//inline void coutt(std::ostream & s, const QString & p) const {foreach (const Entry * i, *this) i->coutt(s, p);}
|
||||
|
||||
static Entry _empty;
|
||||
QString delim;
|
||||
|
||||
};
|
||||
|
||||
class Entry {
|
||||
friend class QPIConfig;
|
||||
friend class Branch;
|
||||
friend class QPIConfigWidget;
|
||||
friend class ConfigValueWidget;
|
||||
public:
|
||||
inline Entry() {_parent = 0;}
|
||||
|
||||
inline Entry * parent() const {return _parent;}
|
||||
inline int childCount() {return _children.size();}
|
||||
inline Branch & children() {_children.delim = delim; return _children;}
|
||||
inline Entry * child(const int index) const {return _children[index];}
|
||||
inline const Entry * findChild(const QString & name) const {foreach (const Entry * i, _children) if (i->_name == name) return i; return 0;}
|
||||
inline Entry * findChild(const QString & name) {foreach (Entry * i, _children) if (i->_name == name) return i; return 0;}
|
||||
inline bool isLeaf() const {return _children.empty();}
|
||||
|
||||
inline const QString & name() const {return _name;}
|
||||
inline const QString & value() const {return _value;}
|
||||
inline const QString & type() const {return _type;}
|
||||
inline const QString & comment() const {return _comment;}
|
||||
|
||||
inline Entry & setName(const QString & value) {_name = value; return *this;}
|
||||
inline Entry & setType(const QString & value) {_type = value; return *this;}
|
||||
inline Entry & setComment(const QString & value) {_comment = value; return *this;}
|
||||
inline Entry & setValue(const QString & value) {_value = value; return *this;}
|
||||
inline Entry & setValue(const QStringList & value) {setValue(value.join("%|%")); setType("l"); return *this;}
|
||||
inline Entry & setValue(const char * value) {setValue(QString(value)); setType("s"); return *this;}
|
||||
inline Entry & setValue(const bool value) {setValue(QString::number(value)); setType("b"); return *this;}
|
||||
inline Entry & setValue(const short value) {setValue(QString::number(value)); setType("n"); return *this;}
|
||||
inline Entry & setValue(const int value) {setValue(QString::number(value)); setType("n"); return *this;}
|
||||
inline Entry & setValue(const long value) {setValue(QString::number(value)); setType("n"); return *this;}
|
||||
inline Entry & setValue(const uchar value) {setValue(QString::number(value)); setType("n"); return *this;}
|
||||
inline Entry & setValue(const ushort value) {setValue(QString::number(value)); setType("n"); return *this;}
|
||||
inline Entry & setValue(const uint value) {setValue(QString::number(value)); setType("n"); return *this;}
|
||||
inline Entry & setValue(const ulong value) {setValue(QString::number(value)); setType("n"); return *this;}
|
||||
inline Entry & setValue(const float value) {setValue(QString::number(value)); setType("f"); return *this;}
|
||||
inline Entry & setValue(const double value) {setValue(QString::number(value)); setType("f"); return *this;}
|
||||
inline Entry & setValue(const QColor & value) {setValue(QColor2QString(value)); setType("c"); return *this;}
|
||||
inline Entry & setValue(const Qt::GlobalColor & value) {setValue(QColor(value)); return *this;}
|
||||
inline Entry & setValue(const QRect & value) {setValue(QRect2QString(value)); setType("r"); return *this;}
|
||||
inline Entry & setValue(const QRectF & value) {setValue(QRectF2QString(value)); setType("a"); return *this;}
|
||||
inline Entry & setValue(const QPoint & value) {setValue(QPoint2QString(value)); setType("p"); return *this;}
|
||||
inline Entry & setValue(const QPointF & value) {setValue(QPointF2QString(value)); setType("v"); return *this;}
|
||||
inline Entry & setValue(const QByteArray & value) {setValue(QByteArray2QString(value)); setType("s"); return *this;}
|
||||
|
||||
Entry & getValue(const QString & vname, const QString & def = QString(), bool * exist = 0);
|
||||
QPICONFIG_GET_VALUE
|
||||
|
||||
Branch getValues(const QString & vname);
|
||||
|
||||
inline bool isEntryExists(const QString & name) const {return entryExists(this, name);}
|
||||
inline const QString & stringValue() const {return _value;}
|
||||
|
||||
operator bool() {return (_value.toLower().trimmed() == "true" || _value.toInt() > 0);}
|
||||
operator char() {return (_value.isEmpty() ? 0 : _value[0].toLatin1());}
|
||||
operator short() {return _value.toShort();}
|
||||
operator int() {return QString2int(_value);}
|
||||
operator long() {return QString2int(_value);}
|
||||
operator uchar() {return QString2int(_value);}
|
||||
operator ushort() {return QString2int(_value);}
|
||||
operator uint() {return QString2int(_value);}
|
||||
operator ulong() {return QString2int(_value);}
|
||||
operator float() {return _value.toFloat();}
|
||||
operator double() {return _value.toDouble();}
|
||||
operator QString() {return _value;}
|
||||
operator QStringList() {return _value.split("%|%");}
|
||||
operator QColor() {return QString2QColor(_value);}
|
||||
operator QRect() {return QString2QRect(_value);}
|
||||
operator QRectF() {return QString2QRectF(_value);}
|
||||
operator QPoint() {return QString2QPoint(_value);}
|
||||
operator QPointF() {return QString2QPointF(_value);}
|
||||
operator QByteArray() {return QString2QByteArray(_value);}
|
||||
|
||||
private:
|
||||
inline static bool compare(const QPIConfig::Entry * f, const QPIConfig::Entry * s) {return f->_line < s->_line;}
|
||||
bool entryExists(const Entry * e, const QString & name) const;
|
||||
inline void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;}
|
||||
inline void clear() {_children.clear(); _name = _value = _type = _comment = _all = QString(); _line = 0; _parent = 0;}
|
||||
//inline void coutt(std::ostream & s, const QString & p) const {QString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << endl; else cout << p << _name << endl; piForeachCA (i, _children) i->coutt(s, nl);}
|
||||
void deleteBranch() {foreach (Entry * i, _children) {i->deleteBranch(); delete i;}}
|
||||
|
||||
static Entry _empty;
|
||||
Entry * _parent;
|
||||
Branch _children;
|
||||
QString _tab;
|
||||
QString _name;
|
||||
QString _value;
|
||||
QString _type;
|
||||
QString _comment;
|
||||
QString _all;
|
||||
QString _full_name;
|
||||
QString delim;
|
||||
int _line;
|
||||
};
|
||||
|
||||
Entry & getValue(const QString & vname, const QString & def = QString(), bool * exist = 0);
|
||||
QPICONFIG_GET_VALUE
|
||||
|
||||
Branch getValues(const QString & vname);
|
||||
|
||||
void setValue(const QString & name, const QString & value, const QString & type = "s", bool write = true);
|
||||
inline void setValue(const QString & name, const QStringList & value, bool write = true) {setValue(name, value.join("%|%"), "l", write);}
|
||||
inline void setValue(const QString & name, const char * value, bool write = true) {setValue(name, QString(value), "s", write);}
|
||||
inline void setValue(const QString & name, const bool value, bool write = true) {setValue(name, QString::number(value), "b", write);}
|
||||
inline void setValue(const QString & name, const short value, bool write = true) {setValue(name, QString::number(value), "n", write);}
|
||||
inline void setValue(const QString & name, const int value, bool write = true) {setValue(name, QString::number(value), "n", write);}
|
||||
inline void setValue(const QString & name, const long value, bool write = true) {setValue(name, QString::number(value), "n", write);}
|
||||
inline void setValue(const QString & name, const uchar value, bool write = true) {setValue(name, QString::number(value), "n", write);}
|
||||
inline void setValue(const QString & name, const ushort value, bool write = true) {setValue(name, QString::number(value), "n", write);}
|
||||
inline void setValue(const QString & name, const uint value, bool write = true) {setValue(name, QString::number(value), "n", write);}
|
||||
inline void setValue(const QString & name, const ulong value, bool write = true) {setValue(name, QString::number(value), "n", write);}
|
||||
inline void setValue(const QString & name, const float value, bool write = true) {setValue(name, QString::number(value), "f", write);}
|
||||
inline void setValue(const QString & name, const double value, bool write = true) {setValue(name, QString::number(value), "f", write);}
|
||||
inline void setValue(const QString & name, const QColor & value, bool write = true) {setValue(name, QColor2QString(value), "c", write);}
|
||||
inline void setValue(const QString & name, const Qt::GlobalColor & value, bool write = true) {setValue(name, QColor(value), write);}
|
||||
inline void setValue(const QString & name, const QRect & value, bool write = true) {setValue(name, QRect2QString(value), "r", write);}
|
||||
inline void setValue(const QString & name, const QRectF & value, bool write = true) {setValue(name, QRectF2QString(value), "a", write);}
|
||||
inline void setValue(const QString & name, const QPoint & value, bool write = true) {setValue(name, QPoint2QString(value), "p", write);}
|
||||
inline void setValue(const QString & name, const QPointF & value, bool write = true) {setValue(name, QPointF2QString(value), "v", write);}
|
||||
inline void setValue(const QString & name, const QByteArray & value, bool write = true) {setValue(name, QByteArray2QString(value), "s", write);}
|
||||
|
||||
inline Entry & rootEntry() {return root;}
|
||||
inline int entriesCount() const {return childCount(&root);}
|
||||
inline bool isEntryExists(const QString & name) const {return entryExists(&root, name);}
|
||||
|
||||
inline Branch allTree() {Branch b; foreach (Entry * i, root._children) b << i; return b;}
|
||||
inline Branch allLeaves() {Branch b; allLeaves(b, &root); qSort(b.begin(), b.end(), Entry::compare); return b;}
|
||||
int entryIndex(const QString & name);
|
||||
|
||||
inline QString getName(uint number) {return entryByIndex(number)._name;}
|
||||
inline QString getValue(uint number) {return entryByIndex(number)._value;}
|
||||
inline QChar getType(uint number) {return entryByIndex(number)._type[0];}
|
||||
inline QString getComment(uint number) {return entryByIndex(number)._comment;}
|
||||
|
||||
QPIConfig::Entry & addEntry(const QString & name, const QString & value, const QString & type = "s", bool write = true, bool node = false);
|
||||
void setName(uint number, const QString & name, bool write = true);
|
||||
void setValue(uint number, const QString & value, bool write = true);
|
||||
void setType(uint number, const QString & type, bool write = true);
|
||||
void setComment(uint number, const QString & comment, bool write = true);
|
||||
|
||||
void removeEntry(const QString & name, bool write = true);
|
||||
void removeEntry(uint number, bool write = true);
|
||||
|
||||
void clear();
|
||||
void readAll();
|
||||
void writeAll();
|
||||
QString writeAllToString();
|
||||
void readAllFromString(const QString & str);
|
||||
|
||||
const QString & delimiter() const {return delim;}
|
||||
void setDelimiter(const QString & d) {delim = d; setEntryDelim(&root, d); readAll();}
|
||||
|
||||
private:
|
||||
void init();
|
||||
int childCount(const Entry * e) const {int c = 0; foreach (const Entry * i, e->_children) c += childCount(i); c += e->_children.size(); return c;}
|
||||
bool entryExists(const Entry * e, const QString & name) const;
|
||||
void buildFullNames(Entry * e) {foreach (Entry * i, e->_children) {if (e != &root) i->_full_name = e->_full_name + delim + i->_name; else i->_full_name = i->_name; buildFullNames(i);}}
|
||||
void allLeaves(Branch & b, Entry * e) {foreach (Entry * i, e->_children) {if ((!i->_value.isEmpty() && !i->isLeaf()) || i->isLeaf()) b << i; allLeaves(b, i);}}
|
||||
void setEntryDelim(Entry * e, const QString & d) {foreach (Entry * i, e->_children) setEntryDelim(i, d); e->delim = d;}
|
||||
inline Entry & entryByIndex(const int index) {Branch b = allLeaves(); if (index < 0 || index >= b.size()) return empty; return *(b[index]);}
|
||||
void removeEntry(Branch & b, Entry * e);
|
||||
void deleteEntry(Entry * e) {foreach (Entry * i, e->_children) deleteEntry(i); delete e;}
|
||||
void parse(QString content = QString());
|
||||
|
||||
int centry;
|
||||
QString delim, * buffer;
|
||||
Entry root, empty;
|
||||
uint lines;
|
||||
QStringList other;
|
||||
QTextStream stream;
|
||||
FileType type;
|
||||
};
|
||||
|
||||
#endif // QPICONFIG_H
|
||||
77
qad_utils/qpiconfignewdialog.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "qpiconfignewdialog.h"
|
||||
#include "ui_qpiconfignewdialog.h"
|
||||
|
||||
|
||||
QPIConfigNewDialog::QPIConfigNewDialog(QWidget * parent): QDialog(parent) {
|
||||
ui = new Ui::QPIConfigNewDialog();
|
||||
ui->setupUi(this);
|
||||
radios = findChildren<QRadioButton * >();
|
||||
ui->widgetValue->hideAll();
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigNewDialog::changeEvent(QEvent * e) {
|
||||
QDialog::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigNewDialog::typeChanged() {
|
||||
foreach (QRadioButton * i, radios) {
|
||||
if (i->isChecked()) {
|
||||
ui->widgetValue->setType(i->property("type").toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigNewDialog::type() {
|
||||
foreach (QRadioButton * i, radios)
|
||||
if (i->isChecked())
|
||||
return i->property("type").toString();
|
||||
return " ";
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigNewDialog::reset(bool node) {
|
||||
ui->lineName->clear();
|
||||
ui->lineComment->clear();
|
||||
ui->radioType_0->setChecked(true);
|
||||
ui->lineName->setFocus();
|
||||
ui->widgetValue->setType("s");
|
||||
ui->widgetValue->value.clear();
|
||||
ui->widgetValue->setVisible(!node);
|
||||
ui->groupType->setVisible(!node);
|
||||
ui->labelValue->setVisible(!node);
|
||||
ui->labelComment->setVisible(!node);
|
||||
ui->lineComment->setVisible(!node);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigNewDialog::name() {
|
||||
return ui->lineName->text();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigNewDialog::value() {
|
||||
return ui->widgetValue->value;
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigNewDialog::comment() {
|
||||
return ui->lineComment->text();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigNewDialog::on_lineName_textChanged(const QString & text) {
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
|
||||
}
|
||||
40
qad_utils/qpiconfignewdialog.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef QPICONFIGNEWDIALOG_H
|
||||
#define QPICONFIGNEWDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QRadioButton>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class QPIConfigNewDialog;
|
||||
}
|
||||
|
||||
|
||||
class QPIConfigNewDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QPIConfigNewDialog(QWidget * parent = 0);
|
||||
|
||||
QString type();
|
||||
QString name();
|
||||
QString value();
|
||||
QString comment();
|
||||
void reset(bool node = false);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e);
|
||||
|
||||
Ui::QPIConfigNewDialog * ui;
|
||||
|
||||
private slots:
|
||||
void on_lineName_textChanged(const QString & text);
|
||||
void typeChanged();
|
||||
|
||||
private:
|
||||
QList<QRadioButton * > radios;
|
||||
|
||||
};
|
||||
|
||||
#endif // QPICONFIGNEWDIALOG_H
|
||||
432
qad_utils/qpiconfignewdialog.ui
Normal file
@@ -0,0 +1,432 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QPIConfigNewDialog</class>
|
||||
<widget class="QDialog" name="QPIConfigNewDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<height>316</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupType">
|
||||
<property name="title">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="radioType_0">
|
||||
<property name="text">
|
||||
<string>string</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>s</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="radioType_1">
|
||||
<property name="text">
|
||||
<string>integer</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>n</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QRadioButton" name="radioType_2">
|
||||
<property name="text">
|
||||
<string>float</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>f</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QRadioButton" name="radioType_3">
|
||||
<property name="text">
|
||||
<string>string list</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>l</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QRadioButton" name="radioType_4">
|
||||
<property name="text">
|
||||
<string>boolean</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>b</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QRadioButton" name="radioType_5">
|
||||
<property name="text">
|
||||
<string>color</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>c</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QRadioButton" name="radioType_6">
|
||||
<property name="text">
|
||||
<string>rectangle</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>r</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QRadioButton" name="radioType_7">
|
||||
<property name="text">
|
||||
<string>area</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>a</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QRadioButton" name="radioType_8">
|
||||
<property name="text">
|
||||
<string>point</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>p</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QRadioButton" name="radioType_9">
|
||||
<property name="text">
|
||||
<string>vector</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>v</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QRadioButton" name="radioType_10">
|
||||
<property name="text">
|
||||
<string>ip</string>
|
||||
</property>
|
||||
<property name="type" stdset="0">
|
||||
<string>i</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineName"/>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="labelComment">
|
||||
<property name="text">
|
||||
<string>Comment:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelValue">
|
||||
<property name="text">
|
||||
<string>Value:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="lineComment"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="ConfigValueWidget" name="widgetValue" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ConfigValueWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qpiconfigvaluewidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>lineName</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>126</x>
|
||||
<y>326</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>110</x>
|
||||
<y>231</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>169</x>
|
||||
<y>326</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>149</x>
|
||||
<y>232</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_0</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>33</x>
|
||||
<y>70</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>1</x>
|
||||
<y>61</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_1</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>25</x>
|
||||
<y>88</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>-1</x>
|
||||
<y>99</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_2</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>17</x>
|
||||
<y>119</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>2</x>
|
||||
<y>130</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_3</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>26</x>
|
||||
<y>143</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>0</x>
|
||||
<y>165</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_4</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>50</x>
|
||||
<y>170</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>2</x>
|
||||
<y>195</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_5</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>243</x>
|
||||
<y>37</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>312</x>
|
||||
<y>10</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_6</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>275</x>
|
||||
<y>67</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>315</x>
|
||||
<y>40</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_7</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>262</x>
|
||||
<y>95</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>311</x>
|
||||
<y>72</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_8</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>250</x>
|
||||
<y>113</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>313</x>
|
||||
<y>104</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_9</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>286</x>
|
||||
<y>145</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>311</x>
|
||||
<y>138</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioType_10</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>QPIConfigNewDialog</receiver>
|
||||
<slot>typeChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>273</x>
|
||||
<y>168</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>312</x>
|
||||
<y>167</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>typeChanged()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
69
qad_utils/qpiconfigplugin.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "qpiconfigwidget.h"
|
||||
#include "qpiconfigplugin.h"
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
QPIConfigPlugin::QPIConfigPlugin(QObject * parent): QObject(parent) {
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfigPlugin::isInitialized() const {
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
|
||||
QWidget * QPIConfigPlugin::createWidget(QWidget * parent) {
|
||||
return new QPIConfigWidget(parent, 0, false);
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigPlugin::name() const {
|
||||
return QLatin1String("QPIConfigWidget");
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigPlugin::group() const {
|
||||
return QLatin1String("Editor Widgets");
|
||||
}
|
||||
|
||||
|
||||
QIcon QPIConfigPlugin::icon() const {
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigPlugin::toolTip() const {
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigPlugin::whatsThis() const {
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfigPlugin::isContainer() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigPlugin::domXml() const {
|
||||
return QLatin1String("<widget class=\"QPIConfigWidget\" name=\"piConfigWidget\">\n</widget>\n");
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigPlugin::includeFile() const {
|
||||
return QLatin1String("qpiconfigwidget.h");
|
||||
}
|
||||
|
||||
31
qad_utils/qpiconfigplugin.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef QPICONFIGPLUGIN_H
|
||||
#define QPICONFIGPLUGIN_H
|
||||
|
||||
#include <QDesignerCustomWidgetInterface>
|
||||
|
||||
class QPIConfigPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
public:
|
||||
QPIConfigPlugin(QObject * parent = 0);
|
||||
|
||||
bool isContainer() const;
|
||||
bool isInitialized() const;
|
||||
QIcon icon() const;
|
||||
QString domXml() const;
|
||||
QString group() const;
|
||||
QString includeFile() const;
|
||||
QString name() const;
|
||||
QString toolTip() const;
|
||||
QString whatsThis() const;
|
||||
QWidget * createWidget(QWidget * parent);
|
||||
void initialize(QDesignerFormEditorInterface * core);
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QPICONFIGPLUGIN_H
|
||||
98
qad_utils/qpiconfigvaluewidget.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "qpiconfigvaluewidget.h"
|
||||
#include "qpievaluator.h"
|
||||
|
||||
|
||||
ConfigValueWidget::ConfigValueWidget(QWidget * parent): QWidget(parent), lay(QBoxLayout::Down, this) {
|
||||
lay.setContentsMargins(0, 0, 0, 0);
|
||||
w_integer.setRange(INT_MIN, INT_MAX);
|
||||
w_float.setRange(-DBL_MAX, DBL_MAX);
|
||||
w_float.setDecimals(5);
|
||||
active = true;
|
||||
lay.addWidget(&w_string);
|
||||
lay.addWidget(&w_list);
|
||||
lay.addWidget(&w_bool);
|
||||
lay.addWidget(&w_integer);
|
||||
lay.addWidget(&w_float);
|
||||
lay.addWidget(&w_color);
|
||||
lay.addWidget(&w_rect);
|
||||
lay.addWidget(&w_point);
|
||||
lay.addWidget(&w_ip);
|
||||
lay.addWidget(&w_enum);
|
||||
lay.addWidget(&w_path);
|
||||
connect(&w_string, SIGNAL(textChanged(QString)), this, SLOT(valueChanged()));
|
||||
connect(&w_list, SIGNAL(valueChanged()), this, SLOT(valueChanged()));
|
||||
connect(&w_bool, SIGNAL(toggled(bool)), this, SLOT(valueChanged()));
|
||||
connect(&w_integer, SIGNAL(valueChanged(int)), this, SLOT(valueChanged()));
|
||||
connect(&w_float, SIGNAL(valueChanged(double)), this, SLOT(valueChanged()));
|
||||
connect(&w_color, SIGNAL(colorChanged(QColor)), this, SLOT(valueChanged()));
|
||||
connect(&w_rect, SIGNAL(valueChanged(QRectF)), this, SLOT(valueChanged()));
|
||||
connect(&w_point, SIGNAL(valueChanged(QPointF)), this, SLOT(valueChanged()));
|
||||
connect(&w_ip, SIGNAL(valueChanged(QString)), this, SLOT(valueChanged()));
|
||||
connect(&w_enum, SIGNAL(currentIndexChanged(int)), this, SLOT(valueChanged()));
|
||||
connect(&w_path, SIGNAL(valueChanged()), this, SLOT(valueChanged()));
|
||||
}
|
||||
|
||||
|
||||
void ConfigValueWidget::setType(const QString & t) {
|
||||
hideAll();
|
||||
type = t.left(1);
|
||||
active = false;
|
||||
if (type == "e") {QStringList en_sl = QPIEvaluator::inBrackets(comment).split(';');
|
||||
if (en_sl.size()>1) {
|
||||
w_enum.show(); w_enum.addItems(en_sl); setValue(value); active = true; return;
|
||||
} else {type = "s";}}
|
||||
if (type == "s") {w_string.show(); setValue(value); active = true; return;}
|
||||
if (type == "l") {w_list.show(); setValue(value); active = true; return;}
|
||||
if (type == "b") {w_bool.show(); setValue(value); active = true; return;}
|
||||
if (type == "n") {w_integer.show(); setValue(value); active = true; return;}
|
||||
if (type == "f") {w_float.show(); setValue(value); active = true; return;}
|
||||
if (type == "c") {w_color.show(); setValue(value); active = true; return;}
|
||||
if (type == "r") {w_rect.show(); w_rect.setDecimals(0); setValue(value); active = true; return;}
|
||||
if (type == "a") {w_rect.show(); w_rect.setDecimals(3); setValue(value); active = true; return;}
|
||||
if (type == "p") {w_point.show(); w_point.setDecimals(0); setValue(value); active = true; return;}
|
||||
if (type == "v") {w_point.show(); w_point.setDecimals(3); setValue(value); active = true; return;}
|
||||
if (type == "i") {w_ip.show(); setValue(value); active = true; return;}
|
||||
if (type == "F") {w_path.show(); setValue(value); active = true; return;}
|
||||
if (type == "D") {w_path.show(); setValue(value); active = true; return;}
|
||||
}
|
||||
|
||||
|
||||
void ConfigValueWidget::setValue(const QString & v) {
|
||||
value = v;
|
||||
active = false;
|
||||
if (type == "l") {w_list.setValue(v.split("%|%")); active = true; return;}
|
||||
if (type == "b") {w_bool.setChecked(v.toInt() > 0 || v.toLower().trimmed() == "true"); active = true; return;}
|
||||
if (type == "n") {w_integer.setValue(QString2int(v)); active = true; return;}
|
||||
if (type == "f") {w_float.setValue(v.toDouble()); active = true; return;}
|
||||
if (type == "c") {w_color.setColor(QString2QColor(v)); active = true; return;}
|
||||
if (type == "r") {w_rect.setValue(QString2QRectF(v)); active = true; return;}
|
||||
if (type == "a") {w_rect.setValue(QString2QRectF(v)); active = true; return;}
|
||||
if (type == "p") {w_point.setValue(QString2QPointF(v)); active = true; return;}
|
||||
if (type == "v") {w_point.setValue(QString2QPointF(v)); active = true; return;}
|
||||
if (type == "i") {w_ip.setIP(v); active = true; return;}
|
||||
if (type == "e") {w_enum.setCurrentIndex(w_enum.findText(v)); active = true; return;}
|
||||
if (type == "F") {w_path.is_dir = false; w_path.setValue(v); active = true; return;}
|
||||
if (type == "D") {w_path.is_dir = true; w_path.setValue(v); active = true; return;}
|
||||
w_string.setText(v);
|
||||
active = true;
|
||||
}
|
||||
|
||||
|
||||
void ConfigValueWidget::valueChanged() {
|
||||
if (!active) return;
|
||||
if (type == "l") {value = w_list.value().join("%|%"); emit changed(this, value); return;}
|
||||
if (type == "b") {value = w_bool.isChecked() ? "true" : "false"; emit changed(this, value); return;}
|
||||
if (type == "n") {value = QString::number(w_integer.value()); emit changed(this, value); return;}
|
||||
if (type == "f") {value = QString::number(w_float.value()); emit changed(this, value); return;}
|
||||
if (type == "c") {value = QColor2QString(w_color.color()); emit changed(this, value); return;}
|
||||
if (type == "r") {value = QRectF2QString(w_rect.value()); emit changed(this, value); return;}
|
||||
if (type == "a") {value = QRectF2QString(w_rect.value()); emit changed(this, value); return;}
|
||||
if (type == "p") {value = QPointF2QString(w_point.value()); emit changed(this, value); return;}
|
||||
if (type == "v") {value = QPointF2QString(w_point.value()); emit changed(this, value); return;}
|
||||
if (type == "i") {value = w_ip.IP(); emit changed(this, value); return;}
|
||||
if (type == "e") {value = w_enum.currentText(); emit changed(this, value); return;}
|
||||
if (type == "F") {value = w_path.value(); emit changed(this, value); return;}
|
||||
if (type == "D") {value = w_path.value(); emit changed(this, value); return;}
|
||||
value = w_string.text();
|
||||
emit changed(this, value);
|
||||
}
|
||||
58
qad_utils/qpiconfigvaluewidget.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef QPICONFIGVALUEWIDGET_H
|
||||
#define QPICONFIGVALUEWIDGET_H
|
||||
|
||||
#include "qpiconfig.h"
|
||||
#include "qvariantedit.h"
|
||||
#include "qrectedit.h"
|
||||
#include "qpointedit.h"
|
||||
#include "colorbutton.h"
|
||||
#include "ecombobox.h"
|
||||
#include "qipedit.h"
|
||||
#include "limits.h"
|
||||
#include "float.h"
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
#include <QDoubleSpinBox>
|
||||
|
||||
|
||||
class ConfigValueWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class QPIConfigWidget;
|
||||
friend class QPIConfigNewDialog;
|
||||
public:
|
||||
ConfigValueWidget(QWidget * parent = 0);
|
||||
~ConfigValueWidget() {hide();}
|
||||
|
||||
void setType(const QString & t);
|
||||
void setValue(const QString & v);
|
||||
void setEntry(QPIConfig::Entry * e) {value = e->value(); full_name = e->_full_name; comment = e->comment(); setType(e->type());}
|
||||
|
||||
private:
|
||||
void hideAll() {w_string.hide(); w_list.hide(); w_bool.hide(); w_integer.hide(); w_float.hide(); w_color.hide(); w_rect.hide(); w_point.hide(); w_ip.hide(); w_enum.hide(); w_path.hide();}
|
||||
|
||||
QString type, value, full_name, comment;
|
||||
bool active;
|
||||
QBoxLayout lay;
|
||||
CLineEdit w_string;
|
||||
StringListEdit w_list;
|
||||
ColorButton w_color;
|
||||
QCheckBox w_bool;
|
||||
QSpinBox w_integer;
|
||||
QDoubleSpinBox w_float;
|
||||
QRectEdit w_rect;
|
||||
QPointEdit w_point;
|
||||
QIPEdit w_ip;
|
||||
QComboBox w_enum;
|
||||
PathEdit w_path;
|
||||
|
||||
private slots:
|
||||
void valueChanged();
|
||||
|
||||
signals:
|
||||
void changed(ConfigValueWidget * , QString );
|
||||
|
||||
};
|
||||
|
||||
#endif // QPICONFIGVALUEWIDGET_H
|
||||
380
qad_utils/qpiconfigwidget.cpp
Normal file
@@ -0,0 +1,380 @@
|
||||
#include "qpiconfigwidget.h"
|
||||
|
||||
|
||||
QPIConfigWidget::QPIConfigWidget(QWidget * parent, QPIConfig * c, bool on): QTreeWidget(parent), actionAddItem(this), actionAddNode(this),
|
||||
actionToItem(this), actionToNode(this), actionRemove(this),
|
||||
actionExpandAll(this), actionCollapseAll(this) {
|
||||
active = on;
|
||||
if (active) {
|
||||
setColumnCount(4);
|
||||
setColumnWidth(0, 150);
|
||||
setColumnWidth(1, 200);
|
||||
} else setColumnCount(0);
|
||||
setSelectionMode(ExtendedSelection);
|
||||
setVerticalScrollMode(ScrollPerPixel);
|
||||
actionAddItem.setIcon(QIcon(":/icons/item-add.png"));
|
||||
actionAddNode.setIcon(QIcon(":/icons/node-add.png"));
|
||||
actionToItem.setIcon(QIcon(":/icons/item.png"));
|
||||
actionToNode.setIcon(QIcon(":/icons/node.png"));
|
||||
actionRemove.setIcon(QIcon(":/icons/edit-delete.png"));
|
||||
popupMenu.addAction(&actionAddItem);
|
||||
popupMenu.addAction(&actionAddNode);
|
||||
popupMenu.addSeparator();
|
||||
/*popupMenu.addAction(&actionToItem);
|
||||
popupMenu.addAction(&actionToNode);
|
||||
popupMenu.addSeparator();*/
|
||||
popupMenu.addAction(&actionRemove);
|
||||
popupMenu.addSeparator();
|
||||
popupMenu.addAction(&actionExpandAll);
|
||||
popupMenu.addAction(&actionCollapseAll);
|
||||
viewport()->installEventFilter(this);
|
||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem * , int)), this, SLOT(itemClicked(QTreeWidgetItem * , int)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem * , int)), this, SLOT(itemChanged(QTreeWidgetItem * , int)));
|
||||
connect(&actionAddItem, SIGNAL(triggered()), this, SLOT(on_actionAddItem_triggered()));
|
||||
connect(&actionAddNode, SIGNAL(triggered()), this, SLOT(on_actionAddNode_triggered()));
|
||||
connect(&actionRemove, SIGNAL(triggered()), this, SLOT(on_actionRemove_triggered()));
|
||||
connect(&actionExpandAll, SIGNAL(triggered()), this, SLOT(expandAll()));
|
||||
connect(&actionCollapseAll, SIGNAL(triggered()), this, SLOT(collapseAll()));
|
||||
read_only_name = read_only_value = read_only_type = read_only_comment = false;
|
||||
c_hidden << false << false << false << false;
|
||||
pi = c_pi = 0;
|
||||
translate();
|
||||
setQPIConfig(c);
|
||||
//resize(600, 400);
|
||||
//show();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::changeEvent(QEvent * e) {
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
translate();
|
||||
return;
|
||||
}
|
||||
//for (int i = 0; i < 4; ++i)
|
||||
// setColumnHidden(i, c_hidden[i]);
|
||||
QTreeWidget::changeEvent(e);
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfigWidget::eventFilter(QObject * o, QEvent * e) {
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (viewport() == qobject_cast<QWidget * >(o)) {
|
||||
pi = itemAt(((QMouseEvent * )e)->pos());
|
||||
if (((QMouseEvent * )e)->buttons() == Qt::RightButton) {
|
||||
qApp->processEvents();
|
||||
itemClicked(pi, 1);
|
||||
popupMenu.popup(((QMouseEvent * )e)->globalPos());
|
||||
}
|
||||
}
|
||||
}
|
||||
return QTreeWidget::eventFilter(o, e);
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::itemClicked(QTreeWidgetItem * item, int column) {
|
||||
if (item != 0) {
|
||||
if ((column == 0 && !read_only_name) || (column == 3 && !read_only_comment)) item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
||||
else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
}
|
||||
bool node = true, ro = read_only_name || read_only_type || read_only_value;
|
||||
if (item != 0)
|
||||
if (itemTWidget(item) != 0)
|
||||
if (itemTWidget(item)->isEnabled())
|
||||
node = false;
|
||||
actionAddItem.setVisible(node && !ro);
|
||||
actionAddNode.setVisible(node && !ro);
|
||||
actionRemove.setVisible(!ro && !selectedItems().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
|
||||
if (item != c_pi) {
|
||||
c_pi = item;
|
||||
if (item != 0) {
|
||||
c_name = item->text(0);
|
||||
c_comment = item->text(3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (item == 0) return;
|
||||
if (c_name == item->text(0) && c_comment == item->text(3)) return;
|
||||
//qDebug() << "change" << item->text(0);
|
||||
QPIConfig::Entry * e = itemEntry(item);
|
||||
if (e == 0) return;
|
||||
if (column == 0) {
|
||||
buildFullNames(item);
|
||||
e->setName(item->text(column));
|
||||
conf->buildFullNames(e->parent());
|
||||
//qDebug() << itemCWidget(item)->full_name;
|
||||
}
|
||||
if (column == 3) e->setComment(item->text(column));
|
||||
c_name = item->text(0);
|
||||
c_comment = item->text(3);
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::typeChange(int t, UComboBox * c) {
|
||||
ConfigValueWidget * cw = (ConfigValueWidget * )c->property("qpic_widget").toLongLong();
|
||||
cw->setType(types.key(s_types[t]));
|
||||
conf->getValue(cw->full_name).setType(types.key(s_types[t]));
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::valueChange(ConfigValueWidget * w, QString v) {
|
||||
conf->getValue(w->full_name).setValue(v);
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::on_actionAddItem_triggered() {
|
||||
if (conf == 0 || !active) return;
|
||||
QString fp;
|
||||
if (pi == 0) pi = invisibleRootItem();
|
||||
else fp = itemCWidget(pi)->full_name + conf->delim;
|
||||
new_dialog.reset();
|
||||
if (new_dialog.exec() == QDialog::Rejected) return;
|
||||
QPIConfig::Entry * e;
|
||||
if (pi->childCount() == 0) {
|
||||
//qDebug() << "pi empty, remove " << itemCWidget(pi)->full_name;
|
||||
conf->removeEntry(itemCWidget(pi)->full_name, false);
|
||||
}
|
||||
//qDebug() << "add " << fp + new_dialog.name();
|
||||
e = &(conf->addEntry(fp + new_dialog.name(), new_dialog.value().isEmpty() ? "0" : new_dialog.value(), new_dialog.type(), false));
|
||||
expandItem(pi);
|
||||
pi = addEntry(pi, e);
|
||||
pi->setText(0, new_dialog.name());
|
||||
pi->setText(3, new_dialog.comment());
|
||||
int ind = s_types.indexOf(types[new_dialog.type()]);
|
||||
if (ind < 0) w_types.back()->setCurrentIndex(0);
|
||||
else w_types.back()->setCurrentIndex(ind);
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::on_actionAddNode_triggered() {
|
||||
if (conf == 0 || !active) return;
|
||||
QString fp;
|
||||
if (pi == 0) pi = invisibleRootItem();
|
||||
else fp = itemCWidget(pi)->full_name + conf->delim;
|
||||
new_dialog.reset(true);
|
||||
if (new_dialog.exec() == QDialog::Rejected) return;
|
||||
QPIConfig::Entry e;
|
||||
//e = &(conf->addEntry(fp + new_dialog.name(), "", "", false));
|
||||
e._full_name = fp + new_dialog.name();
|
||||
expandItem(pi);
|
||||
pi = addEntry(pi, &e, true);
|
||||
pi->setText(0, new_dialog.name());
|
||||
pi->setText(3, new_dialog.comment());
|
||||
setItemWidget(pi, 2, 0);
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::on_actionRemove_triggered() {
|
||||
//hide();
|
||||
if (conf == 0 || !active) return;
|
||||
QList<QTreeWidgetItem * > si = selectedItems();
|
||||
conf->buildFullNames(&(conf->root));
|
||||
QPIConfig::Entry * e;
|
||||
foreach (QTreeWidgetItem * i, si) {
|
||||
e = itemEntry(i);
|
||||
if (e == 0) continue;
|
||||
//qDebug() << "remove " + e->_full_name;
|
||||
conf->removeEntry(e->_full_name, false);
|
||||
deleteEntry(i);
|
||||
}
|
||||
emit changed();
|
||||
//show();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::clear() {
|
||||
if (!active) return;
|
||||
bool hidden = isHidden();
|
||||
hide();
|
||||
QTreeWidget::clear();
|
||||
foreach (ConfigValueWidget * i, w_values)
|
||||
delete i;
|
||||
foreach (QComboBox * i, w_types)
|
||||
delete i;
|
||||
w_values.clear();
|
||||
w_types.clear();
|
||||
if (!hidden) show();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::buildTree() {
|
||||
if (!active) return;
|
||||
if (conf == 0) return;
|
||||
bool hidden = isHidden();
|
||||
hide();
|
||||
clear();
|
||||
conf->buildFullNames(&(conf->root));
|
||||
buildEntry(invisibleRootItem(), &conf->rootEntry());
|
||||
if (!hidden) show();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::setReadOnlyValue(bool yes) {
|
||||
read_only_value = yes;
|
||||
foreach (ConfigValueWidget * i, w_values)
|
||||
i->setEnabled(!yes);
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::setReadOnlyType(bool yes) {
|
||||
read_only_type = yes;
|
||||
foreach (QComboBox * i, w_types) {
|
||||
i->setEnabled(!yes);
|
||||
i->setFrame(!yes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::buildEntry(QTreeWidgetItem * i, QPIConfig::Entry * e) {
|
||||
foreach (QPIConfig::Entry * j, e->children())
|
||||
buildEntry(addEntry(i, j, !j->isLeaf()), j);
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::buildFullNames(QTreeWidgetItem * i) {
|
||||
ConfigValueWidget * cw, * pw;
|
||||
cw = itemCWidget(i);
|
||||
if (i->parent() != 0) {
|
||||
pw = itemCWidget(i->parent());
|
||||
cw->full_name = pw->full_name + conf->delim + i->text(0);
|
||||
} else cw->full_name = i->text(0);
|
||||
for (int j = 0; j < i->childCount(); ++j)
|
||||
buildFullNames(i->child(j));
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry * QPIConfigWidget::itemEntry(QTreeWidgetItem * i) {
|
||||
ConfigValueWidget * cfw = itemCWidget(i);
|
||||
if (cfw == 0) return 0;
|
||||
return &(conf->getValue(cfw->full_name));
|
||||
}
|
||||
|
||||
|
||||
QTreeWidgetItem * QPIConfigWidget::addEntry(QTreeWidgetItem * i, QPIConfig::Entry * e, bool node) {
|
||||
if (conf == 0) return 0;
|
||||
ti = new QTreeWidgetItem();
|
||||
ti->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
ti->setSizeHint(0, QSize(26, 26));
|
||||
ti->setText(0, e->name());
|
||||
ti->setText(3, e->comment());
|
||||
w_values.push_back(new ConfigValueWidget);
|
||||
w_values.back()->setEntry(e);
|
||||
w_values.back()->setEnabled(!read_only_value);
|
||||
if (!node) {
|
||||
w_types.push_back(new UComboBox());
|
||||
w_types.back()->addItems(s_types);
|
||||
w_types.back()->setCurrentIndex(s_types.indexOf(types[e->type().leftJustified(1).left(1)]));
|
||||
w_types.back()->setProperty("qpic_widget", QVariant((qlonglong)w_values.back()));
|
||||
w_types.back()->setEnabled(!read_only_type);
|
||||
w_types.back()->setFrame(!read_only_type);
|
||||
connect(w_types.back(), SIGNAL(currentIndexChanged(int, UComboBox * )), this, SLOT(typeChange(int,UComboBox * )));
|
||||
}
|
||||
connect(w_values.back(), SIGNAL(changed(ConfigValueWidget * , QString)), this, SLOT(valueChange(ConfigValueWidget * , QString)));
|
||||
i->addChild(ti);
|
||||
setItemWidget(ti, 1, w_values.back());
|
||||
if (!node) {
|
||||
setItemWidget(ti, 2, w_types.back());
|
||||
if (itemTWidget(i) != 0) { //itemTWidget(i)->setEnabled(false);
|
||||
w_types.remove(w_types.indexOf(itemTWidget(i)));
|
||||
setItemWidget(i, 2, 0);
|
||||
}
|
||||
}
|
||||
return ti;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::deleteEntry(QTreeWidgetItem * i) {
|
||||
ConfigValueWidget * vw;
|
||||
UComboBox * cb;
|
||||
int cc = i->childCount();
|
||||
for (int j = 0; j < cc; ++j)
|
||||
deleteEntry(i->child(0));
|
||||
vw = qobject_cast<ConfigValueWidget * >(itemWidget(i, 1));
|
||||
cb = qobject_cast<UComboBox * >(itemWidget(i, 2));
|
||||
if (vw != 0) {
|
||||
w_values.remove(w_values.indexOf(vw));
|
||||
delete vw;
|
||||
}
|
||||
if (cb != 0) {
|
||||
w_types.remove(w_types.indexOf(cb));
|
||||
delete cb;
|
||||
}
|
||||
delete i;
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfigWidget::filter(const QString & f, QTreeWidgetItem * i) {
|
||||
if (i->childCount() == 0) return filterItem(f, i);
|
||||
bool found = false;
|
||||
for (int j = 0; j < i->childCount(); ++j)
|
||||
if (filter(f, i->child(j))) found = true;
|
||||
i->setHidden(!found);
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfigWidget::filterItem(const QString & f, QTreeWidgetItem * i) {
|
||||
if (f.isEmpty()) {
|
||||
i->setHidden(false);
|
||||
return true;
|
||||
}
|
||||
bool ret = (!isColumnHidden(0) && i->text(0).indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(1) && itemCWidget(i)->value.indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(3) && i->text(3).indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
if (itemTWidget(i) != 0)
|
||||
ret = ret || (!isColumnHidden(2) && itemTWidget(i)->currentText().indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
i->setHidden(!ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::translate() {
|
||||
QStringList l;
|
||||
l << tr("Name") << tr("Value") << tr("Type") << tr("Comment");
|
||||
if (active) setHeaderLabels(l);
|
||||
types.clear();
|
||||
s_types.clear();
|
||||
addTrEntry("s", tr("string"));
|
||||
addTrEntry("l", tr("string list"));
|
||||
addTrEntry("n", tr("integer"));
|
||||
addTrEntry("f", tr("float"));
|
||||
addTrEntry("b", tr("boolean"));
|
||||
addTrEntry("c", tr("color"));
|
||||
addTrEntry("r", tr("rectangle"));
|
||||
addTrEntry("a", tr("area"));
|
||||
addTrEntry("p", tr("point"));
|
||||
addTrEntry("v", tr("vector"));
|
||||
addTrEntry("i", tr("ip"));
|
||||
actionAddItem.setText(tr("Add item ..."));
|
||||
actionAddNode.setText(tr("Add node ..."));
|
||||
actionToItem.setText(tr("Convert to item"));
|
||||
actionToNode.setText(tr("Convert to node"));
|
||||
actionRemove.setText(tr("Remove"));
|
||||
actionExpandAll.setText(tr("Expand all"));
|
||||
actionCollapseAll.setText(tr("Collapse all"));
|
||||
if (!active) return;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
setColumnHidden(i, c_hidden[i]);
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfigWidget::writeToString() {
|
||||
if (conf == 0) return QString();
|
||||
conf->buildFullNames(&(conf->root));
|
||||
return conf->writeAllToString();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::readFromString(QString str) {
|
||||
if (conf == 0) return;
|
||||
conf->readAllFromString(str);
|
||||
buildTree();
|
||||
}
|
||||
111
qad_utils/qpiconfigwidget.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef QPICONFIGWIDGET_H
|
||||
#define QPICONFIGWIDGET_H
|
||||
|
||||
#include "qpiconfig.h"
|
||||
#include "qpiconfignewdialog.h"
|
||||
#include "qpiconfigvaluewidget.h"
|
||||
#include <QTreeWidget>
|
||||
#include <QComboBox>
|
||||
#include <QEvent>
|
||||
#include <QBoxLayout>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
|
||||
class UComboBox: public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UComboBox(QWidget * parent = 0): QComboBox(parent) {connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChange(int)));}
|
||||
private slots:
|
||||
void indexChange(int i) {emit currentIndexChanged(i, this);}
|
||||
signals:
|
||||
void currentIndexChanged(int, UComboBox * );
|
||||
};
|
||||
|
||||
|
||||
class QPIConfigWidget: public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool readOnlyName READ readOnlyName WRITE setReadOnlyName)
|
||||
Q_PROPERTY(bool readOnlyValue READ readOnlyValue WRITE setReadOnlyValue)
|
||||
Q_PROPERTY(bool readOnlyType READ readOnlyType WRITE setReadOnlyType)
|
||||
Q_PROPERTY(bool readOnlyComment READ readOnlyComment WRITE setReadOnlyComment)
|
||||
Q_PROPERTY(bool columnNameVisible READ columnNameVisible WRITE setColumnNameVisible)
|
||||
Q_PROPERTY(bool columnValueVisible READ columnValueVisible WRITE setColumnValueVisible)
|
||||
Q_PROPERTY(bool columnTypeVisible READ columnTypeVisible WRITE setColumnTypeVisible)
|
||||
Q_PROPERTY(bool columnCommentVisible READ columnCommentVisible WRITE setColumnCommentVisible)
|
||||
public:
|
||||
QPIConfigWidget(QWidget * parent = 0, QPIConfig * c = 0, bool on = true);
|
||||
~QPIConfigWidget() {clear();}
|
||||
|
||||
void setQPIConfig(QPIConfig * c) {conf = c; buildTree();}
|
||||
bool readOnlyName() {return read_only_name;}
|
||||
bool readOnlyValue() {return read_only_value;}
|
||||
bool readOnlyType() {return read_only_type;}
|
||||
bool readOnlyComment() {return read_only_comment;}
|
||||
bool columnNameVisible() {return !c_hidden[0];}
|
||||
bool columnValueVisible() {return !c_hidden[1];}
|
||||
bool columnTypeVisible() {return !c_hidden[2];}
|
||||
bool columnCommentVisible() {return !c_hidden[3];}
|
||||
QString writeToString();
|
||||
void readFromString(QString str);
|
||||
|
||||
private:
|
||||
void changeEvent(QEvent * e);
|
||||
bool eventFilter(QObject * o, QEvent * e);
|
||||
void buildEntry(QTreeWidgetItem * i, QPIConfig::Entry * e);
|
||||
void buildFullNames(QTreeWidgetItem * i);
|
||||
QPIConfig::Entry * itemEntry(QTreeWidgetItem * i);
|
||||
ConfigValueWidget * itemCWidget(QTreeWidgetItem * i) {return qobject_cast<ConfigValueWidget * >(itemWidget(i, 1));}
|
||||
UComboBox * itemTWidget(QTreeWidgetItem * i) {return qobject_cast<UComboBox * >(itemWidget(i, 2));}
|
||||
QTreeWidgetItem * addEntry(QTreeWidgetItem * i, QPIConfig::Entry * e, bool node = false);
|
||||
void deleteEntry(QTreeWidgetItem * i);
|
||||
bool filter(const QString & f, QTreeWidgetItem * i);
|
||||
bool filterItem(const QString & f, QTreeWidgetItem * i);
|
||||
void translate();
|
||||
void addTrEntry(const QString & s, const QString & f) {types.insert(s, f); s_types << f;}
|
||||
|
||||
QPIConfig * conf;
|
||||
QPIConfigNewDialog new_dialog;
|
||||
QAction actionAddItem, actionAddNode, actionToItem, actionToNode, actionRemove, actionExpandAll, actionCollapseAll;
|
||||
QMenu popupMenu;
|
||||
QString c_name, c_comment;
|
||||
QTreeWidgetItem * pi, * ti, * c_pi;
|
||||
QHash<QString, QString> types;
|
||||
QStringList s_types;
|
||||
QVector<ConfigValueWidget * > w_values;
|
||||
QVector<UComboBox * > w_types;
|
||||
QVector<bool> c_hidden;
|
||||
bool active, read_only_name, read_only_value, read_only_type, read_only_comment;
|
||||
|
||||
public slots:
|
||||
void parse() {if (conf == 0) clear(); else conf->readAll();}
|
||||
void write() {if (conf == 0) return; conf->buildFullNames(&(conf->root)); conf->writeAll();}
|
||||
void clear();
|
||||
void buildTree();
|
||||
void filter(const QString & f) {if (!active) return; filter(f, invisibleRootItem());}
|
||||
void setReadOnlyName(bool yes) {read_only_name = yes;}
|
||||
void setReadOnlyValue(bool yes);
|
||||
void setReadOnlyType(bool yes);
|
||||
void setReadOnlyComment(bool yes) {read_only_comment = yes;}
|
||||
void setColumnNameVisible(bool yes) {setColumnHidden(0, !yes); c_hidden[0] = !yes;}
|
||||
void setColumnValueVisible(bool yes) {setColumnHidden(1, !yes); c_hidden[1] = !yes;}
|
||||
void setColumnTypeVisible(bool yes) {setColumnHidden(2, !yes); c_hidden[2] = !yes;}
|
||||
void setColumnCommentVisible(bool yes) {setColumnHidden(3, !yes); c_hidden[3] = !yes;}
|
||||
|
||||
private slots:
|
||||
void itemClicked(QTreeWidgetItem * item, int column);
|
||||
void itemChanged(QTreeWidgetItem * item, int column);
|
||||
void typeChange(int t, UComboBox * c);
|
||||
void valueChange(ConfigValueWidget * w, QString v);
|
||||
void on_actionAddItem_triggered();
|
||||
void on_actionAddNode_triggered();
|
||||
void on_actionRemove_triggered();
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
};
|
||||
|
||||
#endif // QPICONFIGWIDGET_H
|
||||
8
qad_utils/qpiconfigwidget.pri
Normal file
@@ -0,0 +1,8 @@
|
||||
### eqmake4 was here ###
|
||||
HEADERS += qpiconfig.h qpiconfigwidget.h qpiconfignewdialog.h qpiconfigvaluewidget.h
|
||||
SOURCES += qpiconfig.cpp qpiconfigwidget.cpp qpiconfignewdialog.cpp qpiconfigvaluewidget.cpp
|
||||
FORMS += qpiconfignewdialog.ui
|
||||
|
||||
|
||||
CONFIG -= debug_and_release debug
|
||||
CONFIG += release
|
||||
1066
qad_utils/qpievaluator.cpp
Normal file
@@ -0,0 +1,1066 @@
|
||||
/*
|
||||
Peri4 Paint
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "qpievaluator.h"
|
||||
|
||||
|
||||
QPIEvaluatorContent::QPIEvaluatorContent() {
|
||||
addFunction("arcsin", 1);
|
||||
addFunction("arccos", 1);
|
||||
addFunction("arctg", 1);
|
||||
addFunction("arcctg", 1);
|
||||
addFunction("random", 2);
|
||||
addFunction("sin", 1);
|
||||
addFunction("cos", 1);
|
||||
addFunction("ctg", 1);
|
||||
addFunction("tg", 1);
|
||||
addFunction("exp", 1);
|
||||
addFunction("cth", 1);
|
||||
addFunction("sh", 1);
|
||||
addFunction("ch", 1);
|
||||
addFunction("th", 1);
|
||||
addFunction("sqrt", 1);
|
||||
addFunction("sqr", 1);
|
||||
addFunction("pow", 2);
|
||||
addFunction("abs", 1);
|
||||
addFunction("ln", 1);
|
||||
addFunction("lg", 1);
|
||||
addFunction("log", 2);
|
||||
addFunction("im", 1);
|
||||
addFunction("re", 1);
|
||||
addFunction("arg", 1);
|
||||
addFunction("len", 1);
|
||||
addFunction("conj", 1);
|
||||
addFunction("sign", 1);
|
||||
addFunction("rad", 1);
|
||||
addFunction("deg", 1);
|
||||
clearCustomVariables();
|
||||
//addVariable("n", 0.);
|
||||
//addVariable("x1", 123);
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluatorContent::setVariableValue(int index, complexd new_value) {
|
||||
if (index < 0 || index >= variables.size()) return false;
|
||||
variables[index].value = new_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluatorContent::setVariableName(int index, const QString & new_name) {
|
||||
if (index < 0 || index >= variables.size()) return false;
|
||||
variables[index].name = new_name;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluatorContent::clearCustomVariables() {
|
||||
var_index.clear();
|
||||
func_index.clear();
|
||||
variables.clear();
|
||||
addVariable("i", complexd_i);
|
||||
addVariable("pi", atan(1.) * 4.);
|
||||
addVariable("e", exp(1.));
|
||||
cv_count = variables.size();
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluatorContent::sortVariables() {
|
||||
var_index.clear();
|
||||
qSort(variables.begin(), variables.end());
|
||||
for (int i = 0; i < variables.size(); i++)
|
||||
var_index[variables[i].name] = i;
|
||||
/*
|
||||
qDebug() << "---";
|
||||
for (int i = 0; i < variables.size(); i++) {
|
||||
qDebug() << variables[i].name;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
QPIEvaluatorTypes::BaseFunctions QPIEvaluatorContent::getBaseFunction(const QString & name) {
|
||||
if (name == "sin") return QPIEvaluatorTypes::bfSin;
|
||||
if (name == "cos") return QPIEvaluatorTypes::bfCos;
|
||||
if (name == "tg") return QPIEvaluatorTypes::bfTg;
|
||||
if (name == "ctg") return QPIEvaluatorTypes::bfCtg;
|
||||
if (name == "arcsin") return QPIEvaluatorTypes::bfArcsin;
|
||||
if (name == "arccos") return QPIEvaluatorTypes::bfArccos;
|
||||
if (name == "arctg") return QPIEvaluatorTypes::bfArctg;
|
||||
if (name == "arcctg") return QPIEvaluatorTypes::bfArcctg;
|
||||
if (name == "exp") return QPIEvaluatorTypes::bfExp;
|
||||
if (name == "random") return QPIEvaluatorTypes::bfRandom;
|
||||
if (name == "sh") return QPIEvaluatorTypes::bfSh;
|
||||
if (name == "ch") return QPIEvaluatorTypes::bfCh;
|
||||
if (name == "th") return QPIEvaluatorTypes::bfTh;
|
||||
if (name == "cth") return QPIEvaluatorTypes::bfCth;
|
||||
if (name == "sqrt") return QPIEvaluatorTypes::bfSqrt;
|
||||
if (name == "sqr") return QPIEvaluatorTypes::bfSqr;
|
||||
if (name == "pow") return QPIEvaluatorTypes::bfPow;
|
||||
if (name == "abs") return QPIEvaluatorTypes::bfAbs;
|
||||
if (name == "ln") return QPIEvaluatorTypes::bfLn;
|
||||
if (name == "lg") return QPIEvaluatorTypes::bfLg;
|
||||
if (name == "log") return QPIEvaluatorTypes::bfLog;
|
||||
if (name == "im") return QPIEvaluatorTypes::bfIm;
|
||||
if (name == "re") return QPIEvaluatorTypes::bfRe;
|
||||
if (name == "arg") return QPIEvaluatorTypes::bfArg;
|
||||
if (name == "len") return QPIEvaluatorTypes::bfLen;
|
||||
if (name == "conj") return QPIEvaluatorTypes::bfConj;
|
||||
if (name == "sign") return QPIEvaluatorTypes::bfSign;
|
||||
if (name == "rad") return QPIEvaluatorTypes::bfRad;
|
||||
if (name == "deg") return QPIEvaluatorTypes::bfDeg;
|
||||
return QPIEvaluatorTypes::bfUnknown;
|
||||
}
|
||||
|
||||
const QString & QPIEvaluator::prepare(const QString & string) {
|
||||
currentString = string.trimmed();
|
||||
if (currentString.isEmpty()) currentString = "0";
|
||||
replaceOperators();
|
||||
removeSpaces();
|
||||
checkBrackets();
|
||||
while (fillElements()) checkBrackets();
|
||||
while (setSignes()) fillElements();
|
||||
removeJunk();
|
||||
findUnknownVariables();
|
||||
return currentString;
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::removeSpaces() {
|
||||
QString tmps = currentString;
|
||||
for (int i = 0; i < tmps.length(); i++) {
|
||||
if (tmps[i] == ' ' || tmps[i] == '\t') {
|
||||
tmps.remove(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
currentString = tmps;
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::removeJunk() {
|
||||
QChar cc;
|
||||
bool junk = true;
|
||||
int bcnt;
|
||||
while (junk) {
|
||||
if (currentString.left(1) != "(" || currentString.right(1) != ")") return;
|
||||
bcnt = 1;
|
||||
junk = false;
|
||||
for (int i = 1; i < currentString.length(); i++) {
|
||||
cc = currentString[i];
|
||||
if (cc == '(') bcnt++;
|
||||
if (cc == ')') bcnt--;
|
||||
if (bcnt == 0) {
|
||||
if (i == currentString.length() - 1) {
|
||||
currentString = currentString.mid(1, currentString.length() - 2);
|
||||
elements.pop_front();
|
||||
elements.pop_back();
|
||||
junk = true;
|
||||
break;
|
||||
} else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::replaceOperators() {
|
||||
currentString.replace("==", "=");
|
||||
currentString.replace("!=", ":");
|
||||
currentString.replace(">=", "}");
|
||||
currentString.replace("<=", "{");
|
||||
currentString.replace("&&", "&");
|
||||
currentString.replace("||", "|");
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::makeOutput(QString & string) {
|
||||
string.replace(":", "≠");
|
||||
string.replace("}", "≥");
|
||||
string.replace("{", "≤");
|
||||
string.replace("&", "⋀");
|
||||
string.replace("|", "⋁");
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::findUnknownVariables() {
|
||||
QString cvar;
|
||||
unknownVars.clear();
|
||||
for (int i = 0; i < currentString.length(); i++) {
|
||||
if (elements[i].var_num == -666) cvar += currentString[i];
|
||||
else {
|
||||
if (cvar.length() == 0) continue;
|
||||
unknownVars << cvar;
|
||||
cvar = "";
|
||||
}
|
||||
}
|
||||
if (cvar.length() > 0) unknownVars << cvar;
|
||||
unknownVars.removeDuplicates();
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluator::isSign(const QChar & ch) {
|
||||
return ch == '+' || ch == '-' ||
|
||||
ch == '*' || ch == '/' ||
|
||||
ch == '%' || ch == '^' ||
|
||||
ch == '=' || ch == ':' ||
|
||||
ch == '>' || ch == '<' ||
|
||||
ch == '}' || ch == '{' ||
|
||||
ch == '&' || ch == '|';
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::checkBrackets() {
|
||||
QString tmps = currentString;
|
||||
QChar fc, sc;
|
||||
int bcnt = 0, bpos = 0, inserted = 0;
|
||||
currentString = tmps;
|
||||
for (int i = 0; i < tmps.length(); i++) {
|
||||
if (tmps[i] == '(') {
|
||||
if (bcnt == 0) bpos = i;
|
||||
bcnt++;
|
||||
}
|
||||
if (tmps[i] == ')') {
|
||||
if (bcnt == 0) {
|
||||
currentString.insert(bpos + inserted, "(");
|
||||
inserted++;
|
||||
} else bcnt--;
|
||||
}
|
||||
}
|
||||
if (bcnt > 0) currentString += QString(bcnt, ')');
|
||||
tmps = currentString;
|
||||
for (int i = 0; i < tmps.length() - 1; i++) {
|
||||
fc = tmps[i].toLower();
|
||||
sc = tmps[i + 1].toLower();
|
||||
if ((fc == ')' && sc == '(') ||
|
||||
(fc == ')' && sc >= '0' && sc <= '9') ||
|
||||
(fc == ')' && sc >= 'a' && sc <= 'z') ) tmps.insert(++i, '*');
|
||||
}
|
||||
currentString = tmps;
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluator::fillElements() {
|
||||
int fstart, flen, cnum = 0, cpart = 0, cfunc;
|
||||
QChar cc, nc, pc, fc = '!';
|
||||
bool numFound = false;
|
||||
QString curfind, tmps = currentString;
|
||||
elements.resize(tmps.length());
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
elements[i].type = QPIEvaluatorTypes::etVariable;
|
||||
elements[i].var_num = -666;
|
||||
}
|
||||
currentVariables.clear();
|
||||
//qDebug().nospace() << "search for functions ...";
|
||||
for (int i = 0; i < content.functionsCount(); i++) {
|
||||
curfind = content.function(i).identifier;
|
||||
cfunc = i; //(int)content.function(i).type;
|
||||
flen = curfind.length();
|
||||
fstart = 0;
|
||||
while (fstart >= 0) {
|
||||
fstart = tmps.indexOf(curfind, fstart);
|
||||
if (fstart < 0) break;
|
||||
if (tmps[fstart + flen] != '(') {
|
||||
//currentString.insert(fstart + flen, "(");
|
||||
fstart++;
|
||||
continue;
|
||||
}
|
||||
for (int j = fstart; j < fstart + flen; j++) {
|
||||
elements[j].set(QPIEvaluatorTypes::etFunction, cnum, cfunc);
|
||||
tmps.replace(j, 1, fc);
|
||||
}
|
||||
cnum++;
|
||||
}
|
||||
}
|
||||
cnum = 0;
|
||||
//qDebug().nospace() << "search for variables ...";
|
||||
for (int i = 0; i < content.variablesCount(); i++) {
|
||||
curfind = content.variable(i).name;
|
||||
flen = curfind.length();
|
||||
fstart = 0;
|
||||
while (fstart >= 0) {
|
||||
fstart = tmps.indexOf(curfind, fstart);
|
||||
if (fstart < 0) break;
|
||||
for (int j = fstart; j < fstart + flen; j++) {
|
||||
elements[j].set(QPIEvaluatorTypes::etVariable, cnum, i);
|
||||
tmps.replace(j, 1, fc);
|
||||
}
|
||||
cnum++;
|
||||
}
|
||||
}
|
||||
curfind = "";
|
||||
cnum = 1;
|
||||
//qDebug().nospace() << "search for numbers ...";
|
||||
for (int i = 0; i < tmps.length(); i++) {
|
||||
cc = tmps[i];
|
||||
/*if (cc == " " || cc == "(" || cc == ")") {
|
||||
curfind = "";
|
||||
cpart = 0;
|
||||
numFound = false;
|
||||
continue;
|
||||
}*/
|
||||
switch (cpart) {
|
||||
case 0:
|
||||
if ((cc >= '0' && cc <= '9')) {// || cc == '-' || cc == '+') {
|
||||
curfind += cc;
|
||||
cpart = 1;
|
||||
continue;
|
||||
}
|
||||
if (cc == '.') {
|
||||
curfind += cc;
|
||||
cpart = 2;
|
||||
continue;
|
||||
}
|
||||
if (cc == 'E') {
|
||||
curfind += cc;
|
||||
cpart = 3;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (cc >= '0' && cc <= '9') {
|
||||
curfind += cc;
|
||||
continue;
|
||||
}
|
||||
if (cc == '.') {
|
||||
curfind += cc;
|
||||
cpart = 2;
|
||||
continue;
|
||||
}
|
||||
if (cc == 'E') {
|
||||
curfind += cc;
|
||||
cpart = 3;
|
||||
continue;
|
||||
}
|
||||
numFound = true;
|
||||
break;
|
||||
case 2:
|
||||
if (cc >= '0' && cc <= '9') {
|
||||
curfind += cc;
|
||||
continue;
|
||||
}
|
||||
if (cc == 'E') {
|
||||
curfind += cc;
|
||||
cpart = 3;
|
||||
continue;
|
||||
}
|
||||
numFound = true;
|
||||
break;
|
||||
case 3:
|
||||
if ((cc >= '0' && cc <= '9') || cc == '-' || cc == '+') {
|
||||
curfind += cc;
|
||||
cpart = 4;
|
||||
continue;
|
||||
}
|
||||
numFound = true;
|
||||
break;
|
||||
case 4:
|
||||
if (cc >= '0' && cc <= '9') {
|
||||
curfind += cc;
|
||||
continue;
|
||||
}
|
||||
numFound = true;
|
||||
break;
|
||||
}
|
||||
if (numFound) {
|
||||
//qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
|
||||
currentVariables.push_back(QPIEvaluatorTypes::Variable("tmp" + QString::number(cnum), curfind.toDouble()));
|
||||
for (int j = i - curfind.length(); j < i; j++) {
|
||||
elements[j].set(QPIEvaluatorTypes::etNumber, cnum, -cnum);
|
||||
tmps.replace(j, 1, fc);
|
||||
}
|
||||
curfind = "";
|
||||
cnum++;
|
||||
cpart = 0;
|
||||
numFound = false;
|
||||
}
|
||||
}
|
||||
if (cpart > 0) {
|
||||
//qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
|
||||
currentVariables.push_back(QPIEvaluatorTypes::Variable("tmp" + QString::number(cnum), curfind.toDouble()));
|
||||
for (int j = tmps.length() - curfind.length(); j < tmps.length(); j++) {
|
||||
elements[j].set(QPIEvaluatorTypes::etNumber, cnum, -cnum);
|
||||
tmps.replace(j, 1, fc);
|
||||
}
|
||||
}
|
||||
cc = nc = fc;
|
||||
//qDebug().nospace() << "search for signes ...";
|
||||
for (int i = 0; i < tmps.length(); i++) {
|
||||
cc = tmps[i];
|
||||
if (i > 0) pc = tmps[i - 1];
|
||||
else pc = fc;
|
||||
if (i < tmps.length() - 1) nc = tmps[i + 1];
|
||||
else nc = fc;
|
||||
if (cc == '(' || cc == ')' || cc == ',') {
|
||||
elements[i].set(QPIEvaluatorTypes::etOperator, -1);
|
||||
continue;
|
||||
}
|
||||
if (cc == '-' || cc == '+') {
|
||||
elements[i].set(QPIEvaluatorTypes::etOperator, -1);
|
||||
if (i < tmps.length() - 1) if (elements[i + 1].type == QPIEvaluatorTypes::etVariable ||
|
||||
elements[i + 1].type == QPIEvaluatorTypes::etFunction) continue;
|
||||
if ((pc == '(' || isSign(pc) || i == 0) && i < tmps.length() - 1) {
|
||||
if (elements[i + 1].type != QPIEvaluatorTypes::etOperator) {
|
||||
cnum = elements[i + 1].num;
|
||||
elements[i].set(QPIEvaluatorTypes::etNumber, cnum);
|
||||
tmps.replace(i, 1, fc);
|
||||
///cout << "found sign " << cc << " :" << cnum - 1 << endl;
|
||||
if (cc == '-' && currentVariables.size() >= cnum)
|
||||
currentVariables[cnum - 1].value = -currentVariables[cnum - 1].value;
|
||||
//i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isSign(cc)) {
|
||||
elements[i].set(QPIEvaluatorTypes::etOperator, -1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/*
|
||||
qDebug().nospace() << tmps;
|
||||
cout << " ";
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
switch (elements[i].type) {
|
||||
case etFunction: cout << "f"; break;
|
||||
case etNumber: cout << "n"; break;
|
||||
case etOperator: cout << "o"; break;
|
||||
case etVariable: cout << "v"; break;
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
*/
|
||||
return false;
|
||||
//for (int i = 0; i < currentVariables.size(); i++) qDebug() << "var " << i << ": " << currentVariables[i].value.real();
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluator::setSignes() {
|
||||
int inserted = 0, ni, pi = 0, needInsert = 0;
|
||||
QChar fc, sc, pc;
|
||||
QString tmps = currentString;
|
||||
for (int i = 0; i < tmps.length() - 1; i++) {
|
||||
needInsert = 0;
|
||||
ni = i + 1;
|
||||
if (i > 0) pi = i - 1;
|
||||
fc = tmps[i].toLower();
|
||||
sc = tmps[ni].toLower();
|
||||
pc = tmps[pi].toLower();
|
||||
//if (elements[i].type == etOperator || elements[ni].type == etVariable) continue;
|
||||
if (fc == ',' || sc == ',') continue;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etOperator && elements[ni].type == QPIEvaluatorTypes::etOperator) continue;
|
||||
if (fc == ')' && (elements[ni].type == QPIEvaluatorTypes::etNumber || elements[ni].type == QPIEvaluatorTypes::etVariable || elements[ni].type == QPIEvaluatorTypes::etFunction)) needInsert = 1;
|
||||
if (sc == '(' && (elements[i].type == QPIEvaluatorTypes::etNumber || elements[i].type == QPIEvaluatorTypes::etVariable)) needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etNumber && elements[ni].type == QPIEvaluatorTypes::etNumber && elements[i].num != elements[ni].num) needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etVariable && elements[ni].type == QPIEvaluatorTypes::etVariable && elements[i].num != elements[ni].num) needInsert = 1;
|
||||
if ((elements[i].type == QPIEvaluatorTypes::etNumber && elements[ni].type == QPIEvaluatorTypes::etVariable) || (elements[i].type == QPIEvaluatorTypes::etVariable && elements[ni].type == QPIEvaluatorTypes::etNumber)) needInsert = 1;
|
||||
if ((elements[i].type == QPIEvaluatorTypes::etNumber || elements[i].type == QPIEvaluatorTypes::etVariable) && elements[ni].type == QPIEvaluatorTypes::etFunction) needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etFunction && elements[ni].type == QPIEvaluatorTypes::etFunction && elements[i].num != elements[ni].num) needInsert = 2;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etFunction && elements[ni].type != QPIEvaluatorTypes::etFunction && sc != '(') needInsert = 2;
|
||||
if (elements[pi].type == QPIEvaluatorTypes::etOperator && (elements[ni].type == QPIEvaluatorTypes::etFunction || elements[ni].type == QPIEvaluatorTypes::etVariable) && fc == '-') needInsert = 3;
|
||||
switch (needInsert) {
|
||||
case 1:
|
||||
currentString.insert(ni + inserted, "*");
|
||||
elements.insert(ni + inserted, QPIEvaluatorTypes::Element(QPIEvaluatorTypes::etOperator, -1));
|
||||
//inserted++;
|
||||
//i++;
|
||||
return true;
|
||||
/*case 2:
|
||||
currentString.insert(ni + inserted, ")");
|
||||
currentString.insert(ni + inserted, "(");
|
||||
elements.insert(ni + inserted, Element(etOperator, -1));
|
||||
elements.insert(ni + inserted, Element(etOperator, -1));
|
||||
inserted++;
|
||||
i++;
|
||||
return true;*/
|
||||
case 3:
|
||||
currentString.insert(ni + inserted, "1*");
|
||||
elements.insert(ni + inserted, QPIEvaluatorTypes::Element(QPIEvaluatorTypes::etOperator, -1));
|
||||
//inserted;
|
||||
//i++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*if (elements[tmps.length() - 1].type == etFunction) {
|
||||
currentString.insert(tmps.length() + inserted, ")");
|
||||
currentString.insert(tmps.length() + inserted, "(");
|
||||
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
|
||||
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
|
||||
return true;
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::convert() {
|
||||
int j;
|
||||
QPIEvaluatorTypes::Element ce, pe;
|
||||
for (int i = 0; i < currentString.length(); i++) {
|
||||
pe = elements[i];
|
||||
if (pe.type != QPIEvaluatorTypes::etFunction) continue;
|
||||
j = i + 1;
|
||||
while (j < currentString.length()) {
|
||||
ce = elements[j];
|
||||
if (ce != pe) break;
|
||||
j++;
|
||||
}
|
||||
currentString.replace(i, j - i, " ");
|
||||
for (int k = i + 1; k < j; k++) elements.remove(i);
|
||||
//i++;
|
||||
}
|
||||
for (int i = 0; i < currentString.length(); i++) {
|
||||
pe = elements[i];
|
||||
if (pe.type != QPIEvaluatorTypes::etNumber) continue;
|
||||
j = i + 1;
|
||||
while (j < currentString.length()) {
|
||||
ce = elements[j];
|
||||
if (ce != pe) break;
|
||||
j++;
|
||||
}
|
||||
currentString.replace(i, j - i, " ");
|
||||
for (int k = i + 1; k < j; k++) elements.remove(i);
|
||||
//i++;
|
||||
}
|
||||
for (int i = 0; i < currentString.length(); i++) {
|
||||
pe = elements[i];
|
||||
if (pe.type != QPIEvaluatorTypes::etVariable) continue;
|
||||
j = i + 1;
|
||||
while (j < currentString.length()) {
|
||||
ce = elements[j];
|
||||
if (ce != pe) break;
|
||||
j++;
|
||||
}
|
||||
currentString.replace(i, j - i, " ");
|
||||
for (int k = i + 1; k < j; k++) elements.remove(i);
|
||||
//i++;
|
||||
}
|
||||
/*qDebug().nospace() << currentString;
|
||||
cout << " ";
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
switch (elements[i].type) {
|
||||
case etFunction: cout << "f"; break;
|
||||
case etNumber: cout << "n"; break;
|
||||
case etOperator: cout << "o"; break;
|
||||
case etVariable: cout << "v"; break;
|
||||
}
|
||||
}
|
||||
cout << endl;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
const QString & QPIEvaluator::preprocess(const QString & string) {
|
||||
static QString ret;
|
||||
int lind;
|
||||
ret = prepare(string);
|
||||
convert();
|
||||
instructions.clear();
|
||||
//qDebug() << preproc->currentString;
|
||||
variables = currentVariables;
|
||||
lind = parse(currentString);
|
||||
if (instructions.size() == 0) {
|
||||
variables.push_back(QPIEvaluatorTypes::Variable());
|
||||
instructions.push_back(QPIEvaluatorTypes::Instruction(QPIEvaluatorTypes::oNone, QVector<int>(1, lind), -variables.size()));
|
||||
}
|
||||
kvars = &(content.variables);
|
||||
/*
|
||||
cout << endl << "variables:" << endl;
|
||||
for (int i = 0; i < variables.size(); i++)
|
||||
cout << i << " value = " << variables[i].value << endl;
|
||||
|
||||
cout << endl << "instructions:" << endl;
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
cout << i << endl;
|
||||
cout << " operation " << instructions[i].operation << endl;
|
||||
cout << " operators: ";
|
||||
for (int j = 0; j < instructions[i].operators.size(); j++)
|
||||
cout << instructions[i].operators[j] << "; ";
|
||||
cout << endl << " function " << instructions[i].function << endl;
|
||||
cout << " out " << instructions[i].out << endl;
|
||||
}
|
||||
*/
|
||||
makeOutput(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QPIEvaluatorTypes::Operation QPIEvaluator::operationInOrder(const int & index) {
|
||||
switch (index) {
|
||||
case 0: return QPIEvaluatorTypes::oPower;
|
||||
case 1: return QPIEvaluatorTypes::oMultiply;
|
||||
case 2: return QPIEvaluatorTypes::oDivide;
|
||||
case 3: return QPIEvaluatorTypes::oResidue;
|
||||
case 4: return QPIEvaluatorTypes::oAdd;
|
||||
case 5: return QPIEvaluatorTypes::oSubtract;
|
||||
case 6: return QPIEvaluatorTypes::oEqual;
|
||||
case 7: return QPIEvaluatorTypes::oNotEqual;
|
||||
case 8: return QPIEvaluatorTypes::oGreaterEqual;
|
||||
case 9: return QPIEvaluatorTypes::oSmallerEqual;
|
||||
case 10: return QPIEvaluatorTypes::oGreater;
|
||||
case 11: return QPIEvaluatorTypes::oSmaller;
|
||||
case 12: return QPIEvaluatorTypes::oAnd;
|
||||
case 13: return QPIEvaluatorTypes::oOr;
|
||||
default: return QPIEvaluatorTypes::oNone;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int QPIEvaluator::parse(const QString & string, int offset) {
|
||||
int slen = string.length(), /*facnt,*/ farg, bcnt, k;
|
||||
QChar cc;
|
||||
QPIEvaluatorTypes::Element ce;
|
||||
QPIEvaluatorTypes::Function cfunc;
|
||||
QPIEvaluatorTypes::Operation coper;
|
||||
QString sbrackets, carg;
|
||||
QVector<int> args, atmp;
|
||||
QVector<QPIEvaluatorTypes::Operation> opers;
|
||||
|
||||
///qDebug() << "to parse :" + string;
|
||||
///cout << " "; for (int i = 0; i < slen; i++) cout << preproc->elements[i + offset].type; cout << endl;
|
||||
|
||||
for (int i = 0; i < slen; i++) {
|
||||
ce = elements[i + offset];
|
||||
cc = string[i];
|
||||
switch (ce.type) {
|
||||
case QPIEvaluatorTypes::etNumber:
|
||||
args.push_back(ce.var_num);
|
||||
continue;
|
||||
case QPIEvaluatorTypes::etVariable:
|
||||
args.push_back(ce.var_num);
|
||||
continue;
|
||||
case QPIEvaluatorTypes::etFunction:
|
||||
i++;
|
||||
cfunc = content.function(ce.var_num);
|
||||
//facnt = cfunc.arguments;
|
||||
atmp.clear();
|
||||
bcnt = farg = 1;
|
||||
///qDebug() << "function: " + cfunc.identifier;
|
||||
//for (int k = 0; k < facnt; k++) {
|
||||
bcnt = 1;
|
||||
carg = "";
|
||||
k = i + 1;
|
||||
//if (string.size() <= k || k < 0) return -666;
|
||||
while (bcnt > 0) {
|
||||
//if (k < facnt - 1) fcomma = string.indexOf(',', j);
|
||||
cc = string[k];
|
||||
switch (cc.toLatin1()) {
|
||||
case '(': bcnt++; break;
|
||||
case ')':
|
||||
bcnt--;
|
||||
if (bcnt == 0) {
|
||||
///qDebug() << "arument: " << carg;
|
||||
atmp.push_back(parse(carg, k + offset - carg.length()));
|
||||
k++;
|
||||
carg = "";
|
||||
if (atmp.size() > 0) if (atmp.back() < 0 && farg > 0) farg = atmp.back();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if (bcnt == 1) {
|
||||
///qDebug() << "arument: " << carg;
|
||||
atmp.push_back(parse(carg, k + offset - carg.length()));
|
||||
k++;
|
||||
carg = "";
|
||||
if (atmp.size() > 0) if (atmp.back() < 0 && farg > 0) farg = atmp.back();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
carg += cc;
|
||||
k++;
|
||||
}
|
||||
i = k - 1;
|
||||
if (farg > 0) {
|
||||
variables.push_back(QPIEvaluatorTypes::Variable());
|
||||
farg = -variables.size();
|
||||
}
|
||||
instructions.push_back(QPIEvaluatorTypes::Instruction(QPIEvaluatorTypes::oFunction, atmp, farg, ce.var_num));
|
||||
args.push_back(farg);
|
||||
//for (int i = 0; i < args.size(); i++) cout << preproc->currentVariables[-args[i]].value << endl;
|
||||
//i = j + 1;
|
||||
continue;
|
||||
case QPIEvaluatorTypes::etOperator:
|
||||
//qDebug() << "operator: " << cc;
|
||||
if (cc == '(') {
|
||||
sbrackets = inBrackets(string.right(slen - i));
|
||||
args.push_back(parse(sbrackets, i + offset + 1));
|
||||
i += sbrackets.length() + 1;
|
||||
continue;
|
||||
}
|
||||
if (cc == '+') {opers.push_back(QPIEvaluatorTypes::oAdd); continue;}
|
||||
if (cc == '-') {opers.push_back(QPIEvaluatorTypes::oSubtract); continue;}
|
||||
if (cc == '*') {opers.push_back(QPIEvaluatorTypes::oMultiply); continue;}
|
||||
if (cc == '/') {opers.push_back(QPIEvaluatorTypes::oDivide); continue;}
|
||||
if (cc == '%') {opers.push_back(QPIEvaluatorTypes::oResidue); continue;}
|
||||
if (cc == '^') {opers.push_back(QPIEvaluatorTypes::oPower); continue;}
|
||||
if (cc == '=') {opers.push_back(QPIEvaluatorTypes::oEqual); continue;}
|
||||
if (cc == ':') {opers.push_back(QPIEvaluatorTypes::oNotEqual); continue;}
|
||||
if (cc == '}') {opers.push_back(QPIEvaluatorTypes::oGreaterEqual); continue;}
|
||||
if (cc == '{') {opers.push_back(QPIEvaluatorTypes::oSmallerEqual); continue;}
|
||||
if (cc == '>') {opers.push_back(QPIEvaluatorTypes::oGreater); continue;}
|
||||
if (cc == '<') {opers.push_back(QPIEvaluatorTypes::oSmaller); continue;}
|
||||
if (cc == '&') {opers.push_back(QPIEvaluatorTypes::oAnd); continue;}
|
||||
if (cc == '|') {opers.push_back(QPIEvaluatorTypes::oOr); continue;}
|
||||
}
|
||||
}
|
||||
/*
|
||||
cout << "stack: " << endl << "args: ";
|
||||
for (int i = 0; i < args.size(); i++) cout << args[i] << ", ";
|
||||
cout << endl << "opers: ";
|
||||
for (int i = 0; i < opers.size(); i++) cout << opers[i] << ", ";
|
||||
*/
|
||||
if (opers.size() == 0) {
|
||||
if (args.size() > 0) return args.back();
|
||||
else return -666;
|
||||
}
|
||||
for (int i = 0; i < QPIEvaluatorTypes::operationCount; i++) {
|
||||
coper = operationInOrder(i);
|
||||
for (int j = 0; j < opers.size(); j++) {
|
||||
if (coper == QPIEvaluatorTypes::oDivide || coper == QPIEvaluatorTypes::oMultiply) {
|
||||
if (opers[j] != QPIEvaluatorTypes::oDivide && opers[j] != QPIEvaluatorTypes::oMultiply) continue;
|
||||
} else {
|
||||
if (opers[j] != coper) continue;
|
||||
}
|
||||
atmp.clear();
|
||||
if (j < args.size() && j >= 0) atmp.push_back(args[j]);
|
||||
else atmp.push_back(-666);
|
||||
if (j + 1 < args.size() && j >= -1) atmp.push_back(args[j + 1]);
|
||||
else atmp.push_back(-666);
|
||||
farg = 1;
|
||||
if (atmp[0] < 0) farg = atmp[0];
|
||||
else {
|
||||
if (atmp[1] < 0) farg = atmp[1];
|
||||
else {
|
||||
variables.push_back(QPIEvaluatorTypes::Variable());
|
||||
farg = -variables.size();
|
||||
}
|
||||
}
|
||||
instructions.push_back(QPIEvaluatorTypes::Instruction(opers[j], atmp, farg));
|
||||
if (j >= 0 && j < args.size()) {
|
||||
args.remove(j);
|
||||
if (j < args.size()) args[j] = farg;
|
||||
}
|
||||
opers.remove(j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
return instructions.back().out;
|
||||
///cout << endl;
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluator::check() {
|
||||
QPIEvaluatorTypes::Instruction ci;
|
||||
bool error;
|
||||
if (unknownVars.size() > 0) {
|
||||
lastError = "Unknown variables: \"" + unknownVars.join("\", \"") + "\"";
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
error = false;
|
||||
ci = instructions[i];
|
||||
switch (ci.operation) {
|
||||
case QPIEvaluatorTypes::oNone: break;
|
||||
case QPIEvaluatorTypes::oFunction:
|
||||
for (int j = 0; j < ci.operators.size(); j++) {
|
||||
if (ci.operators[j] == -666) { //(ci.operators[j] < -variables.size() || ci.operators[j] >= kvars->size()) {
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ci.operators.size() != content.function(ci.function).arguments || error) {
|
||||
lastError = "Invalid arguments count for function \"" + content.function(ci.function).identifier + "\"";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (ci.operators[0] == -666 || ci.operators[1] == -666) error = true;
|
||||
if (ci.operators.size() != 2 || error) {
|
||||
lastError = "Invalid arguments count for operation \" " + operationChar(ci.operation) + " \"";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ci.out < -variables.size()) {
|
||||
lastError = "Invalid variable index \"" + QString::number(ci.out) + "\"";
|
||||
return false;
|
||||
}
|
||||
for (int j = 0; j < ci.operators.size(); j++) {
|
||||
if (ci.operators[j] < -variables.size() || ci.operators[j] >= kvars->size()) {
|
||||
lastError = "Invalid variable index \"" + QString::number(ci.operators[j]) + "\"";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QString QPIEvaluator::inBrackets(const QString & string) {
|
||||
int slen = string.length(), bcnt = 0;
|
||||
QChar cc;
|
||||
for (int i = 0; i < slen; i++) {
|
||||
cc = string[i];
|
||||
if (cc == '(') bcnt++;
|
||||
if (cc == ')') {
|
||||
bcnt--;
|
||||
if (bcnt == 0) return string.mid(1, i - 1);
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
QString QPIEvaluator::operationChar(const QPIEvaluatorTypes::Operation & operation) {
|
||||
switch (operation) {
|
||||
case QPIEvaluatorTypes::oAdd: return "+";
|
||||
case QPIEvaluatorTypes::oSubtract: return "-";
|
||||
case QPIEvaluatorTypes::oMultiply: return "*";
|
||||
case QPIEvaluatorTypes::oDivide: return "/";
|
||||
case QPIEvaluatorTypes::oPower: return "^";
|
||||
case QPIEvaluatorTypes::oResidue: return "%";
|
||||
case QPIEvaluatorTypes::oEqual: return "=";
|
||||
case QPIEvaluatorTypes::oNotEqual: return ("≠");
|
||||
case QPIEvaluatorTypes::oGreaterEqual: return ("≥");
|
||||
case QPIEvaluatorTypes::oSmallerEqual: return ("≤");
|
||||
case QPIEvaluatorTypes::oGreater: return ">";
|
||||
case QPIEvaluatorTypes::oSmaller: return "<";
|
||||
case QPIEvaluatorTypes::oAnd: return ("⋀");
|
||||
case QPIEvaluatorTypes::oOr: return ("⋁");
|
||||
default: return "???";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline complexd QPIEvaluator::residue(const complexd & f, const complexd & s) {
|
||||
complexd ret;
|
||||
if (s.real() != 0.) ret = complexd(f.real() - ((int)(f.real() / s.real())) * s.real(), 0.);
|
||||
if (s.imag() != 0.) ret = complexd(ret.real(), f.imag() - ((int)(f.imag() / s.imag())) * s.imag());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
inline void QPIEvaluator::execFunction(const QPIEvaluatorTypes::Instruction & ci) {
|
||||
QPIEvaluatorTypes::Function cfunc = content.function(ci.function);
|
||||
int oi = -ci.out - 1;
|
||||
complexd tmp, stmp;
|
||||
double ldtmp;
|
||||
//qDebug() << "function " << (int)cfunc.type;
|
||||
switch (cfunc.type) {
|
||||
case QPIEvaluatorTypes::bfSin:
|
||||
tmpvars[oi].value = sin(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfCos:
|
||||
tmpvars[oi].value = cos(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfTg:
|
||||
tmpvars[oi].value = tan(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfCtg:
|
||||
tmp = tan(value(ci.operators[0]));
|
||||
if (tmp == complexd_0) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = complexd_1 / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArcsin:
|
||||
tmpvars[oi].value = asinc_qpie(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArccos:
|
||||
tmpvars[oi].value = acosc_qpie(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArctg:
|
||||
tmpvars[oi].value = atanc_qpie(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArcctg:
|
||||
tmp = atanc_qpie(value(ci.operators[0]));
|
||||
if (tmp == complexd_0) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = complexd_1 / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSh:
|
||||
tmpvars[oi].value = sinh(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfCh:
|
||||
tmpvars[oi].value = cosh(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfTh:
|
||||
tmpvars[oi].value = tanh(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfCth:
|
||||
tmp = tanh(value(ci.operators[0]));
|
||||
if (tmp == complexd_0) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = complexd_1 / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfAbs:
|
||||
tmpvars[oi].value = abs(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSqrt:
|
||||
tmpvars[oi].value = sqrt(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSqr:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * value(ci.operators[0]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfExp:
|
||||
tmpvars[oi].value = exp(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfPow:
|
||||
tmpvars[oi].value = pow(value(ci.operators[0]), value(ci.operators[1]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfLn:
|
||||
tmpvars[oi].value = log(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfLg:
|
||||
tmpvars[oi].value = log10(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfLog:
|
||||
tmp = log(value(ci.operators[1]));
|
||||
if (tmp == complexd_0) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = log(value(ci.operators[0])) / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfRe:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfIm:
|
||||
tmpvars[oi].value = value(ci.operators[0]).imag();
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArg:
|
||||
tmpvars[oi].value = arg(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfLen:
|
||||
tmpvars[oi].value = abs(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfConj:
|
||||
tmpvars[oi].value = conj(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSign:
|
||||
ldtmp = value(ci.operators[0]).real();
|
||||
tmpvars[oi].value = ldtmp >= 0. ? complexd_1 : -complexd_1;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfRad:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * complexd(deg2rad_qpie, 0.);
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfDeg:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * complexd(rad2deg_qpie, 0.);
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfRandom:
|
||||
tmp = static_cast<double>(qrand()) / RAND_MAX;
|
||||
stmp = value(ci.operators[1]) - value(ci.operators[0]);
|
||||
tmpvars[oi].value = value(ci.operators[0]) + tmp * stmp;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool QPIEvaluator::execInstructions() {
|
||||
QPIEvaluatorTypes::Instruction ci;
|
||||
int oi;
|
||||
complexd tmp;
|
||||
tmpvars = variables;
|
||||
//cout << "var count " << tmpvars.size() << endl;
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
ci = instructions[i];
|
||||
oi = -ci.out - 1;
|
||||
//cout << value(ci.operators[0]) << operationChar(ci.operation) << value(ci.operators[1]) << ", " << oi << endl;
|
||||
switch (ci.operation) {
|
||||
case QPIEvaluatorTypes::oAdd:
|
||||
tmpvars[oi].value = value(ci.operators[0]) + value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oSubtract:
|
||||
tmpvars[oi].value = value(ci.operators[0]) - value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oMultiply:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oDivide:
|
||||
tmp = value(ci.operators[1]);
|
||||
if (tmp == complexd(0., 0.)) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = value(ci.operators[0]) / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::oResidue:
|
||||
tmpvars[oi].value = residue(value(ci.operators[0]), value(ci.operators[1]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::oPower:
|
||||
tmpvars[oi].value = pow(value(ci.operators[0]), value(ci.operators[1]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::oEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]) == value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oNotEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]) != value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oGreaterEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() >= value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oSmallerEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() <= value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oGreater:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() > value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oSmaller:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() < value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oAnd:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() > 0. && value(ci.operators[1]).real() > 0.;
|
||||
break;
|
||||
case QPIEvaluatorTypes::oOr:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() > 0. || value(ci.operators[1]).real() > 0.;
|
||||
break;
|
||||
case QPIEvaluatorTypes::oFunction:
|
||||
execFunction(ci);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oNone:
|
||||
tmpvars[oi].value = value(ci.operators[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!instructions.isEmpty())
|
||||
out = value(instructions.back().out);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluator::check(const QString & string) {
|
||||
currentString = preprocess(string);
|
||||
correct = check();
|
||||
if (!correct)
|
||||
return false;
|
||||
lastError = "Correct";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int QPIEvaluator::setVariable(const QString & name, complexd value) {
|
||||
int i = content.findVariable(name);
|
||||
if (i < 0) {
|
||||
content.addVariable(name, value);
|
||||
return content.findVariable(name);
|
||||
} else {
|
||||
content.setVariableValue(i, value);
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
complexd QPIEvaluator::evaluate() {
|
||||
if (!execInstructions()) out = 0.;
|
||||
if (fabs(out.real()) < 1E-300) out = complexd(0., out.imag());
|
||||
if (fabs(out.imag()) < 1E-300) out = complexd(out.real(), 0.);
|
||||
return out;
|
||||
}
|
||||
195
qad_utils/qpievaluator.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
Peri4 Paint
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPIEVALUATOR_H
|
||||
#define QPIEVALUATOR_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
#include <QDebug>
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
|
||||
#ifndef PIP_VERSION
|
||||
typedef std::complex<double> complexd;
|
||||
const complexd complexd_i(0., 1.);
|
||||
const complexd complexd_0(0.);
|
||||
const complexd complexd_1(1.);
|
||||
#endif
|
||||
const double deg2rad_qpie = atan(1.) / 45.;
|
||||
const double rad2deg_qpie = 45. / atan(1.);
|
||||
|
||||
inline complexd round_qpie(const complexd & c) {return complexd(round(c.real()), round(c.imag()));}
|
||||
inline complexd floor_qpie(const complexd & c) {return complexd(floor(c.real()), floor(c.imag()));}
|
||||
inline complexd ceil_qpie(const complexd & c) {return complexd(ceil(c.real()), ceil(c.imag()));}
|
||||
inline complexd atanc_qpie(const complexd & c) {return -complexd(-0.5, 1.) * log((complexd_1 + complexd_i * c) / (complexd_1 - complexd_i * c));}
|
||||
inline complexd asinc_qpie(const complexd & c) {return -complexd_i * log(complexd_i * c + sqrt(complexd_1 - c * c));}
|
||||
inline complexd acosc_qpie(const complexd & c) {return -complexd_i * log(c + complexd_i * sqrt(complexd_1 - c * c));}
|
||||
|
||||
namespace QPIEvaluatorTypes {
|
||||
static const int operationCount = 14;
|
||||
|
||||
enum eType {etNumber, etOperator, etVariable, etFunction};
|
||||
enum Operation {oNone, oAdd, oSubtract, oMultiply, oDivide, oResidue, oPower,
|
||||
oEqual, oNotEqual, oGreater, oSmaller, oGreaterEqual, oSmallerEqual,
|
||||
oAnd, oOr, oFunction};
|
||||
enum BaseFunctions {bfUnknown, bfSin, bfCos, bfTg, bfCtg,
|
||||
bfArcsin, bfArccos, bfArctg, bfArcctg,
|
||||
bfExp, bfRandom, bfSh, bfCh, bfTh, bfCth,
|
||||
bfSqrt, bfSqr, bfPow, bfAbs,
|
||||
bfLn, bfLg, bfLog, bfSign,
|
||||
bfIm, bfRe, bfArg, bfLen, bfConj,
|
||||
bfRad, bfDeg};
|
||||
|
||||
struct Instruction {
|
||||
Instruction() {;}
|
||||
Instruction(Operation oper, QVector<int> opers, int out_ind, int func = -1) {
|
||||
operation = oper; operators = opers; out = out_ind; function = func;}
|
||||
Operation operation;
|
||||
QVector<int> operators;
|
||||
int out;
|
||||
int function;};
|
||||
struct Element {
|
||||
Element() {;}
|
||||
Element(eType new_type, int new_num, int new_var_num = -1) {set(new_type, new_num, new_var_num);}
|
||||
void set(eType new_type, int new_num, int new_var_num = -1) {type = new_type; num = new_num; var_num = new_var_num;}
|
||||
eType type;
|
||||
int num;
|
||||
int var_num;};
|
||||
struct Function {
|
||||
Function() {arguments = 0; type = bfUnknown;}
|
||||
Function(const QString & name, int args, BaseFunctions ftype) {identifier = name; arguments = args; type = ftype;}
|
||||
QString identifier;
|
||||
BaseFunctions type;
|
||||
int arguments;};
|
||||
struct Variable {
|
||||
Variable() {value = 0.;}
|
||||
Variable(const QString & var_name, complexd val) {name = var_name; value = val;}
|
||||
QString name;
|
||||
complexd value;};
|
||||
inline bool operator <(const Variable & s1, const Variable & s2) {
|
||||
if (s1.name.size() != s2.name.size())
|
||||
return s1.name.size() > s2.name.size();
|
||||
return s1.name > s2.name;
|
||||
}
|
||||
};
|
||||
/*
|
||||
≠ :
|
||||
≥ }
|
||||
≤ {
|
||||
⋀ &
|
||||
⋁ |
|
||||
*/
|
||||
class QPIEvaluatorContent
|
||||
{
|
||||
friend class QPIEvaluator;
|
||||
public:
|
||||
QPIEvaluatorContent();
|
||||
~QPIEvaluatorContent() {;}
|
||||
|
||||
void addFunction(const QString & name, int args = 1) {functions.push_back(QPIEvaluatorTypes::Function(name, args, getBaseFunction(name)));}
|
||||
void addVariable(const QString & name, const complexd & val = 0., bool sort = true) {variables.push_back(QPIEvaluatorTypes::Variable(name, val)); if (sort) sortVariables();}
|
||||
int functionsCount() const {return functions.size();}
|
||||
int variablesCount() const {return variables.size();}
|
||||
int customVariablesCount() const {return variables.size() - cv_count;}
|
||||
int findFunction(const QString & name) const {return func_index.value(name, -1);}
|
||||
int findVariable(const QString & name) const {return var_index.value(name, -1);}
|
||||
QPIEvaluatorTypes::Function function(int index) {if (index < 0 || index >= functions.size()) return QPIEvaluatorTypes::Function(); return functions[index];}
|
||||
QPIEvaluatorTypes::Variable variable(int index) {if (index < 0 || index >= variables.size()) return QPIEvaluatorTypes::Variable(); return variables[index];}
|
||||
QPIEvaluatorTypes::Function function(const QString & name) {return function(findFunction(name));}
|
||||
QPIEvaluatorTypes::Variable variable(const QString & name) {return variable(findVariable(name));}
|
||||
QPIEvaluatorTypes::Variable customVariable(int index) {if (index < cv_count || index >= variables.size() + cv_count) return QPIEvaluatorTypes::Variable(); return variables[index + cv_count];}
|
||||
bool setVariableValue(int index, complexd new_value);
|
||||
bool setVariableName(int index, const QString & new_name);
|
||||
bool setVariableValue(const QString & var_name, const complexd & new_value) {return setVariableValue(findVariable(var_name), new_value);}
|
||||
bool setVariableName(const QString & var_name, const QString & new_name) {return setVariableName(findVariable(var_name), new_name);}
|
||||
void removeVariable(int index) {variables.remove(index);}
|
||||
void removeVariable(const QString & var_name) {removeVariable(findVariable(var_name));}
|
||||
void clearCustomVariables();
|
||||
void sortVariables();
|
||||
QPIEvaluatorTypes::BaseFunctions getBaseFunction(const QString & name);
|
||||
|
||||
private:
|
||||
QVector<QPIEvaluatorTypes::Function> functions;
|
||||
QVector<QPIEvaluatorTypes::Variable> variables;
|
||||
QMap<QString, int> var_index, func_index;
|
||||
int cv_count;
|
||||
|
||||
};
|
||||
|
||||
class QPIEvaluator
|
||||
{
|
||||
public:
|
||||
QPIEvaluator() {correct = false ;}
|
||||
~QPIEvaluator() {;}
|
||||
|
||||
bool check(const QString & string);
|
||||
bool isCorrect() const {return correct;}
|
||||
int setVariable(const QString & name, complexd value = 0.);
|
||||
void setVariable(int index, complexd value = 0.) {if (index >= 0 && index < content.variablesCount()) content.setVariableValue(index, value);}
|
||||
void setCustomVariableValue(int index, complexd value = 0.) {content.variables[index + content.cv_count].value = value;}
|
||||
complexd evaluate();
|
||||
void removeVariable(const QString & name) {content.removeVariable(name);}
|
||||
void clearCustomVariables() {content.clearCustomVariables();}
|
||||
int variableIndex(const QString & name) const {return content.findVariable(name);}
|
||||
const QStringList & unknownVariables() const {return unknownVars;}
|
||||
const QString & expression() const {return currentString;}
|
||||
const QString & error() const {return lastError;}
|
||||
const complexd & lastResult() const {return out;}
|
||||
static QString inBrackets(const QString & string);
|
||||
|
||||
QPIEvaluatorContent content;
|
||||
|
||||
private:
|
||||
const QString & prepare(const QString & string);
|
||||
const QString & preprocess(const QString & string);
|
||||
int parse(const QString & string, int offset = 0);
|
||||
void convert();
|
||||
void checkBrackets();
|
||||
void removeSpaces();
|
||||
void findUnknownVariables();
|
||||
void removeJunk();
|
||||
void replaceOperators();
|
||||
void makeOutput(QString & string);
|
||||
bool fillElements();
|
||||
bool setSignes();
|
||||
bool isSign(const QChar & ch);
|
||||
QString inverse(const QString & string) {int len = string.length(); QString s; for (int i = 0; i < len; i++) s += string[len - i - 1]; return s;}
|
||||
bool check();
|
||||
bool execInstructions();
|
||||
QString operationChar(const QPIEvaluatorTypes::Operation & operation);
|
||||
QPIEvaluatorTypes::Operation operationInOrder(const int & index);
|
||||
complexd value(const int & index) {if (index < 0) return tmpvars[-index - 1].value; else return kvars->at(index).value;}
|
||||
inline complexd residue(const complexd & f, const complexd & s);
|
||||
inline void execFunction(const QPIEvaluatorTypes::Instruction & ci);
|
||||
|
||||
QVector<QPIEvaluatorTypes::Element> elements;
|
||||
QVector<QPIEvaluatorTypes::Variable> currentVariables, variables, tmpvars, * kvars;
|
||||
QVector<QPIEvaluatorTypes::Instruction> instructions;
|
||||
QStringList unknownVars;
|
||||
QString currentString, lastError;
|
||||
complexd out;
|
||||
bool correct;
|
||||
|
||||
};
|
||||
|
||||
inline bool operator ==(QPIEvaluatorTypes::Element e1, QPIEvaluatorTypes::Element e2) {return (e1.type == e2.type && e1.num == e2.num);}
|
||||
inline bool operator !=(QPIEvaluatorTypes::Element e1, QPIEvaluatorTypes::Element e2) {return (e1.type != e2.type || e1.num != e2.num);}
|
||||
|
||||
#endif // QPIEVALUATOR_H
|
||||
103
qad_utils/session_manager.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Peri4 Paint
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "session_manager.h"
|
||||
|
||||
|
||||
void SessionManager::save() {
|
||||
if (file_.isEmpty()) return;
|
||||
QPIConfig sr(file_);
|
||||
for (int i = 0; i < mwindows.size(); ++i) {
|
||||
sr.setValue(mwindows[i].first + " state", mwindows[i].second->saveState(), false);
|
||||
sr.setValue(mwindows[i].first + " window state", (int)mwindows[i].second->windowState(), false);
|
||||
sr.setValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()), mwindows[i].second->saveGeometry(), false);
|
||||
QList<QSplitter * > sp = mwindows[i].second->findChildren<QSplitter * >();
|
||||
foreach (QSplitter * s, sp)
|
||||
sr.setValue(mwindows[i].first + " splitter " + s->objectName(), s->saveState(), false);
|
||||
}
|
||||
for (int i = 0; i < checks.size(); ++i)
|
||||
sr.setValue(checks[i].first, checks[i].second->isChecked(), false);
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
sr.setValue(lines[i].first, lines[i].second->text(), "s", false);
|
||||
for (int i = 0; i < combos.size(); ++i)
|
||||
sr.setValue(combos[i].first, combos[i].second->currentIndex(), false);
|
||||
for (int i = 0; i < dspins.size(); ++i)
|
||||
sr.setValue(dspins[i].first, dspins[i].second->value(), false);
|
||||
for (int i = 0; i < spins.size(); ++i)
|
||||
sr.setValue(spins[i].first, spins[i].second->value(), false);
|
||||
for (int i = 0; i < tabs.size(); ++i)
|
||||
sr.setValue(tabs[i].first, tabs[i].second->currentIndex(), false);
|
||||
for (int i = 0; i < actions.size(); ++i)
|
||||
sr.setValue(actions[i].first, actions[i].second->isChecked(), false);
|
||||
for (int i = 0; i < stringlists.size(); ++i)
|
||||
sr.setValue(stringlists[i].first, *stringlists[i].second, false);
|
||||
for (int i = 0; i < strings.size(); ++i)
|
||||
sr.setValue(strings[i].first, *strings[i].second, "s", false);
|
||||
for (int i = 0; i < colors.size(); ++i)
|
||||
sr.setValue(colors[i].first, *colors[i].second, false);
|
||||
for (int i = 0; i < bools.size(); ++i)
|
||||
sr.setValue(bools[i].first, *bools[i].second, false);
|
||||
for (int i = 0; i < ints.size(); ++i)
|
||||
sr.setValue(ints[i].first, *ints[i].second, false);
|
||||
for (int i = 0; i < floats.size(); ++i)
|
||||
sr.setValue(floats[i].first, *floats[i].second, false);
|
||||
sr.writeAll();
|
||||
emit saving(sr);
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::load(bool onlyMainwindow) {
|
||||
if (file_.isEmpty()) return;
|
||||
QPIConfig sr(file_);
|
||||
for (int i = 0; i < mwindows.size(); ++i) {
|
||||
mwindows[i].second->restoreState(sr.getValue(mwindows[i].first + " state", QByteArray()));
|
||||
mwindows[i].second->restoreGeometry(sr.getValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()), QByteArray()));
|
||||
mwindows[i].second->setWindowState((Qt::WindowState)(int)sr.getValue(mwindows[i].first + " window state", 0));
|
||||
QList<QSplitter * > sp = mwindows[i].second->findChildren<QSplitter * >();
|
||||
foreach (QSplitter * s, sp)
|
||||
s->restoreState(sr.getValue(mwindows[i].first + " splitter " + s->objectName(), QByteArray()));
|
||||
}
|
||||
if (onlyMainwindow) return;
|
||||
for (int i = 0; i < checks.size(); ++i)
|
||||
checks[i].second->setChecked(sr.getValue(checks[i].first, true));
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
lines[i].second->setText(sr.getValue(lines[i].first, QString()));
|
||||
for (int i = 0; i < combos.size(); ++i)
|
||||
combos[i].second->setCurrentIndex(sr.getValue(combos[i].first, 0));
|
||||
for (int i = 0; i < dspins.size(); ++i)
|
||||
dspins[i].second->setValue(sr.getValue(dspins[i].first, 0.));
|
||||
for (int i = 0; i < spins.size(); ++i)
|
||||
spins[i].second->setValue(sr.getValue(spins[i].first, 0));
|
||||
for (int i = 0; i < tabs.size(); ++i)
|
||||
tabs[i].second->setCurrentIndex(sr.getValue(tabs[i].first, 0));
|
||||
for (int i = 0; i < actions.size(); ++i)
|
||||
actions[i].second->setChecked(sr.getValue(actions[i].first, true));
|
||||
for (int i = 0; i < stringlists.size(); ++i)
|
||||
*stringlists[i].second = sr.getValue(stringlists[i].first, QStringList());
|
||||
for (int i = 0; i < strings.size(); ++i)
|
||||
*strings[i].second = sr.getValue(strings[i].first, QString()).stringValue();
|
||||
for (int i = 0; i < colors.size(); ++i)
|
||||
*colors[i].second = sr.getValue(colors[i].first, QString());
|
||||
for (int i = 0; i < bools.size(); ++i)
|
||||
*bools[i].second = sr.getValue(bools[i].first, true);
|
||||
for (int i = 0; i < ints.size(); ++i)
|
||||
*ints[i].second = sr.getValue(ints[i].first, 0);
|
||||
for (int i = 0; i < floats.size(); ++i)
|
||||
*floats[i].second = sr.getValue(floats[i].first, 0);
|
||||
emit loading(sr);
|
||||
}
|
||||
92
qad_utils/session_manager.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Peri4 Paint
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SESSION_MANAGER_H
|
||||
#define SESSION_MANAGER_H
|
||||
|
||||
#include <QPair>
|
||||
#include <QMainWindow>
|
||||
#include <QCheckBox>
|
||||
#include <QLineEdit>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QAction>
|
||||
#include <QComboBox>
|
||||
#include <QTabWidget>
|
||||
#include <QSplitter>
|
||||
#include "qpiconfig.h"
|
||||
|
||||
class SessionManager: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SessionManager(const QString & file = QString()) {setFile(file);}
|
||||
~SessionManager() {;}
|
||||
|
||||
inline void setFile(const QString & file) {file_ = file;}
|
||||
|
||||
inline void addEntry(QMainWindow * e) {mwindows.push_back(QPair<QString, QMainWindow * >(e->objectName(), e));}
|
||||
inline void addEntry(QCheckBox * e) {checks.push_back(QPair<QString, QCheckBox * >(e->objectName(), e));}
|
||||
inline void addEntry(QLineEdit * e) {lines.push_back(QPair<QString, QLineEdit * >(e->objectName(), e));}
|
||||
inline void addEntry(QComboBox * e) {combos.push_back(QPair<QString, QComboBox * >(e->objectName(), e));}
|
||||
inline void addEntry(QDoubleSpinBox * e) {dspins.push_back(QPair<QString, QDoubleSpinBox * >(e->objectName(), e));}
|
||||
inline void addEntry(QSpinBox * e) {spins.push_back(QPair<QString, QSpinBox * >(e->objectName(), e));}
|
||||
inline void addEntry(QTabWidget * e) {tabs.push_back(QPair<QString, QTabWidget * >(e->objectName(), e));}
|
||||
inline void addEntry(QAction * e) {actions.push_back(QPair<QString, QAction * >(e->objectName(), e));}
|
||||
|
||||
inline void addEntry(const QString & name, QMainWindow * e) {mwindows.push_back(QPair<QString, QMainWindow * >(name, e));}
|
||||
inline void addEntry(const QString & name, QCheckBox * e) {checks.push_back(QPair<QString, QCheckBox * >(name, e));}
|
||||
inline void addEntry(const QString & name, QLineEdit * e) {lines.push_back(QPair<QString, QLineEdit * >(name, e));}
|
||||
inline void addEntry(const QString & name, QComboBox * e) {combos.push_back(QPair<QString, QComboBox * >(name, e));}
|
||||
inline void addEntry(const QString & name, QDoubleSpinBox * e) {dspins.push_back(QPair<QString, QDoubleSpinBox * >(name, e));}
|
||||
inline void addEntry(const QString & name, QSpinBox * e) {spins.push_back(QPair<QString, QSpinBox * >(name, e));}
|
||||
inline void addEntry(const QString & name, QTabWidget * e) {tabs.push_back(QPair<QString, QTabWidget * >(name, e));}
|
||||
inline void addEntry(const QString & name, QAction * e) {actions.push_back(QPair<QString, QAction * >(name, e));}
|
||||
inline void addEntry(const QString & name, QStringList * e) {stringlists.push_back(QPair<QString, QStringList * >(name, e));}
|
||||
inline void addEntry(const QString & name, QString * e) {strings.push_back(QPair<QString, QString * >(name, e));}
|
||||
inline void addEntry(const QString & name, QColor * e) {colors.push_back(QPair<QString, QColor * >(name, e));}
|
||||
inline void addEntry(const QString & name, bool * e) {bools.push_back(QPair<QString, bool * >(name, e));}
|
||||
inline void addEntry(const QString & name, int * e) {ints.push_back(QPair<QString, int * >(name, e));}
|
||||
inline void addEntry(const QString & name, float * e) {floats.push_back(QPair<QString, float * >(name, e));}
|
||||
|
||||
void save();
|
||||
void load(bool onlyMainwindow = false);
|
||||
|
||||
private:
|
||||
QVector<QPair<QString, QMainWindow * > > mwindows;
|
||||
QVector<QPair<QString, QCheckBox * > > checks;
|
||||
QVector<QPair<QString, QLineEdit * > > lines;
|
||||
QVector<QPair<QString, QComboBox * > > combos;
|
||||
QVector<QPair<QString, QDoubleSpinBox * > > dspins;
|
||||
QVector<QPair<QString, QSpinBox * > > spins;
|
||||
QVector<QPair<QString, QTabWidget * > > tabs;
|
||||
QVector<QPair<QString, QAction * > > actions;
|
||||
QVector<QPair<QString, QStringList * > > stringlists;
|
||||
QVector<QPair<QString, QString * > > strings;
|
||||
QVector<QPair<QString, QColor * > > colors;
|
||||
QVector<QPair<QString, bool * > > bools;
|
||||
QVector<QPair<QString, int * > > ints;
|
||||
QVector<QPair<QString, float * > > floats;
|
||||
QString file_;
|
||||
|
||||
signals:
|
||||
void loading(QPIConfig & );
|
||||
void saving(QPIConfig & );
|
||||
|
||||
};
|
||||
|
||||
#endif // SESSION_MANAGER_H
|
||||
5
qad_utils/svn-commit.tmp
Normal file
@@ -0,0 +1,5 @@
|
||||
qad_utils
|
||||
|
||||
--This line, and those below, will be ignored--
|
||||
|
||||
A .
|
||||