git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
2015-02-28 21:28:53 +00:00
commit ba8bc27298
2358 changed files with 336795 additions and 0 deletions

View 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\x1a\x00q\x00a\x00d\x00_\x00s\x00q\x00l\x00_\x00t\x00a\x00b\x00l\x00e)
[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_sql_table/
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

View File

@@ -0,0 +1,36 @@
project(qad_sql_table)
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 "sql_table_widget.h" "sql_record_widget.h")
set(CPPS "sql_table_widget.cpp" "sql_record_widget.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_sql_table SHARED ${CPPS} ${CUIS} ${CMOCS} ${CRES})
set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSQL_LIBRARY} qad_widgets qad_utils)
target_link_libraries(qad_sql_table ${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_sql_table DESTINATION ${MINGW_LIB})
get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH)
install(TARGETS qad_sql_table DESTINATION ${QTDIR})
else ()
set(CMAKE_INSTALL_PREFIX /usr)
install(FILES ${MOCS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(TARGETS qad_sql_table DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif ()
else ()
install(TARGETS qad_sql_table DESTINATION bin)
endif ()

View File

4
qad_sql_table/clean Normal file
View 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 ./*cxx ./moc_* ./*~ ./*.o ./ui_*.h

4
qad_sql_table/clean.bat Normal file
View 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

View File

@@ -0,0 +1,14 @@
#ifndef ETABWIDGET_H
#define ETABWIDGET_H
#include <QTabWidget>
#include <QTabBar>
class ETabWidget: public QTabWidget {
Q_OBJECT
public:
ETabWidget(QWidget * parent = 0): QTabWidget(parent) {}
void setTabTextColor(int index, const QColor & color) {const_cast<QTabBar * >(tabBar())->setTabTextColor(index, color);}
};
#endif // ETABWIDGET_H

0
qad_sql_table/gpio.conf Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 641 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
qad_sql_table/icons/dd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 992 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 918 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="ru_RU">
<context>
<name>SQLFilterEdit</name>
<message utf8="true">
<source></source>
<translation type="unfinished"></translation>
</message>
<message utf8="true">
<source></source>
<translation type="unfinished"></translation>
</message>
<message utf8="true">
<source></source>
<translation type="unfinished"></translation>
</message>
<message utf8="true">
<source></source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SQLTableWidget</name>
<message>
<source>Table doesn`t exists!</source>
<translation>Таблица не существует!</translation>
</message>
<message>
<source>Add record</source>
<translation>Добавить запись</translation>
</message>
<message>
<source>Configure filters</source>
<translation>Настроить фильтры</translation>
</message>
<message>
<source>Clear</source>
<translation>Очистить</translation>
</message>
<message>
<source>Operator AND</source>
<translation>Операция И</translation>
</message>
<message>
<source>Operator OR</source>
<translation>Операция ИЛИ</translation>
</message>
<message>
<source>Remove selected</source>
<translation>Удалить выделенные</translation>
</message>
<message>
<source>Table &quot;%1&quot; doesn`t exists!</source>
<translation>Таблица &quot;%1&quot; не существует!</translation>
</message>
</context>
</TS>

Binary file not shown.

View File

@@ -0,0 +1 @@
cmake_mgw -DLIB= && make install && qmake && make install

View File

@@ -0,0 +1,17 @@
#include "qad_sql_table.h"
#include "sql_table_plugin.h"
#include "sql_record_plugin.h"
QADSQLTable::QADSQLTable(QObject * parent): QObject(parent) {
m_widgets.append(new SQLTablePlugin(this));
m_widgets.append(new SQLRecordPlugin(this));
}
QList<QDesignerCustomWidgetInterface * > QADSQLTable::customWidgets() const {
return m_widgets;
}
Q_EXPORT_PLUGIN2(qad_sql_table_plugin, QADSQLTable)

View File

@@ -0,0 +1,21 @@
#ifndef QAD_SQL_TABLE_H
#define QAD_SQL_TABLE_H
#include <QtDesigner/QtDesigner>
#include <QtCore/qplugin.h>
class QADSQLTable: public QObject, public QDesignerCustomWidgetCollectionInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
public:
explicit QADSQLTable(QObject * parent = 0);
virtual QList<QDesignerCustomWidgetInterface * > customWidgets() const;
private:
QList<QDesignerCustomWidgetInterface * > m_widgets;
};
#endif // QAD_SQL_TABLE_H

View File

@@ -0,0 +1,3 @@
[Project]
Manager=KDevCMakeManager
Name=qad_sql_table

View File

@@ -0,0 +1,19 @@
### eqmake4 was here ###
QT += sql
CONFIG += designer plugin release
TARGET = $$qtLibraryTarget(qad_sql_table_plugin)
TEMPLATE = lib
HEADERS = qad_sql_table.h sql_table_plugin.h sql_record_plugin.h
SOURCES = qad_sql_table.cpp sql_table_plugin.cpp sql_record_plugin.cpp
RESOURCES = qad_sql_table.qrc
TRANSLATIONS = lang/qad_sql_table_ru.ts
LIBS += -L. -lqad_widgets -lqad_sql_table
QMAKE_CXXFLAGS += -g3
QMAKE_CFLAGS += -g3
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
CONFIG -= debug_and_release debug
CONFIG += release

View File

@@ -0,0 +1,25 @@
<RCC>
<qresource prefix="/">
<file>icons/dialog-close.png</file>
<file>icons/edit-clear.png</file>
<file>icons/edit-guides.png</file>
<file>icons/view-grid.png</file>
<file>icons/zoom-fit-best.png</file>
<file>icons/configure.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.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/expand_s_x.png</file>
<file>icons/expand_s_y.png</file>
<file>icons/expand_x.png</file>
<file>icons/expand_y.png</file>
<file>icons/sql_table.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,25 @@
<RCC>
<qresource prefix="/">
<file>icons/dialog-close.png</file>
<file>icons/edit-clear.png</file>
<file>icons/edit-guides.png</file>
<file>icons/view-grid.png</file>
<file>icons/zoom-fit-best.png</file>
<file>icons/configure.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.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/expand_s_x.png</file>
<file>icons/expand_s_y.png</file>
<file>icons/expand_x.png</file>
<file>icons/expand_y.png</file>
<file>icons/sql_table.png</file>
</qresource>
</RCC>

Binary file not shown.

View File

@@ -0,0 +1,69 @@
#include "sql_record_widget.h"
#include "sql_record_plugin.h"
#include <QtCore/QtPlugin>
SQLRecordPlugin::SQLRecordPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void SQLRecordPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool SQLRecordPlugin::isInitialized() const {
return m_initialized;
}
QWidget * SQLRecordPlugin::createWidget(QWidget * parent) {
return new SQLRecordWidget(parent);
}
QString SQLRecordPlugin::name() const {
return QLatin1String("SQLRecordWidget");
}
QString SQLRecordPlugin::group() const {
return QLatin1String("Editor Widgets");
}
QIcon SQLRecordPlugin::icon() const {
return QIcon(":/icons/sql_table.png");
}
QString SQLRecordPlugin::toolTip() const {
return QLatin1String("");
}
QString SQLRecordPlugin::whatsThis() const {
return QLatin1String("");
}
bool SQLRecordPlugin::isContainer() const {
return false;
}
QString SQLRecordPlugin::domXml() const {
return QLatin1String("<widget class=\"SQLRecordWidget\" name=\"recordSQL\">\n</widget>\n");
}
QString SQLRecordPlugin::includeFile() const {
return QLatin1String("sql_record_widget.h");
}

View File

@@ -0,0 +1,31 @@
#ifndef SQLRECORDPLUGIN_H
#define SQLRECORDPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class SQLRecordPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
SQLRecordPlugin(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 // SQLRECORDPLUGIN_H

View File

@@ -0,0 +1,329 @@
#include "sql_record_widget.h"
#include <qpiconfig.h>
#include <QSqlRecord>
#include <QSqlField>
#include <QSqlError>
#include <QFormLayout>
#include <QLabel>
#include <QDoubleSpinBox>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
#include <colorbutton.h>
#include <qpiconfigvaluewidget.h>
SQLRecordWidget::SQLRecordWidget(QWidget * parent): QWidget(parent) {
setLayout(new QFormLayout());
ro = false;
}
SQLRecordWidget::~SQLRecordWidget() {
}
void SQLRecordWidget::setRecord(const QSqlRecord & q, bool full_update) {
//qDebug() << (q.count() - hidden.size()) << (layout()->count() / 2);
if (full_update || (q.count() - hidden.size()) != (layout()->count() / 2)) createWidgets(q);
for (int i = 0; i < q.count(); ++i) {
QSqlField f = q.field(i);
QWidget * val = 0;
for (int w = 0; w < cws.size(); ++w)
if (cws[w]->objectName() == f.name()) {
val = cws[w];
break;
}
if (val == 0) continue;
if (qobject_cast<QLineEdit * >(val)) qobject_cast<QLineEdit * >(val)->setText(f.value().toString());
if (qobject_cast<QCheckBox * >(val)) qobject_cast<QCheckBox * >(val)->setChecked(f.value().toBool());
if (qobject_cast<QDoubleSpinBox * >(val)) qobject_cast<QDoubleSpinBox * >(val)->setValue(f.value().toDouble());
if (qobject_cast<ColorButton * >(val)) qobject_cast<ColorButton * >(val)->setColor(QColor::fromRgba(f.value().toUInt()));
if (qobject_cast<StringListEdit * >(val)) {
QString s = f.value().toString();
qobject_cast<StringListEdit * >(val)->setValue(s.isEmpty() ? QStringList() : s.split(";"));
}
if (qobject_cast<QComboBox * >(val)) {
QList<QPair<int, QString> > & rv(relations[f.name()]);
bool ok = false;
int sv(f.value().toInt(&ok));
if (!ok)
((QComboBox*)val)->setCurrentIndex(-1);
else {
for (int j = 0; j < rv.size(); ++j) {
if (sv == rv[j].first) {
((QComboBox*)val)->setCurrentIndex(j);
break;
}
}
}
}
}
}
void SQLRecordWidget::setFixedValue(const QString & name, const QVariant & value) {
foreach (QWidget * w, cws) {
if (w->objectName() != name) continue;
if (qobject_cast<QLineEdit * >(w)) {qobject_cast<QLineEdit * >(w)->setText(value.toString()); qobject_cast<QLineEdit * >(w)->setReadOnly(true);}
if (qobject_cast<QCheckBox * >(w)) {qobject_cast<QCheckBox * >(w)->setChecked(value.toBool()); w->setEnabled(false);}
if (qobject_cast<QDoubleSpinBox * >(w)) {qobject_cast<QDoubleSpinBox * >(w)->setValue(value.toDouble()); qobject_cast<QDoubleSpinBox * >(w)->setReadOnly(true);}
if (qobject_cast<ColorButton * >(w)) {qobject_cast<ColorButton * >(w)->setColor(QColor::fromRgba(value.toUInt())); qobject_cast<ColorButton * >(w)->setEnabled(false);}
if (qobject_cast<StringListEdit * >(w)) {qobject_cast<StringListEdit * >(w)->setValue(QStringList()); qobject_cast<StringListEdit * >(w)->setEnabled(false);}
}
}
void SQLRecordWidget::clearValues() {
foreach (QWidget * w, cws) {
if (qobject_cast<QLineEdit * >(w)) qobject_cast<QLineEdit * >(w)->setText(QString());
if (qobject_cast<QCheckBox * >(w)) qobject_cast<QCheckBox * >(w)->setChecked(false);
if (qobject_cast<QDoubleSpinBox * >(w)) qobject_cast<QDoubleSpinBox * >(w)->setValue(0.);
if (qobject_cast<ColorButton * >(w)) qobject_cast<ColorButton * >(w)->setColor(Qt::black);
if (qobject_cast<StringListEdit * >(w)) qobject_cast<StringListEdit * >(w)->setValue(QStringList());
}
}
void SQLRecordWidget::createWidgets(const QSqlRecord & q) {
qDeleteAll(cws);
cws.clear();
delete layout();
QFormLayout * lay = new QFormLayout();
lay->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
lay->setLabelAlignment(Qt::AlignRight);
lay->setContentsMargins(0, 0, 0, 0);
setLayout(lay);
//qDebug() << "createWidgets" << q.count();
for (int i = 0; i < q.count(); ++i) {
QSqlField f = q.field(i);
if (hidden.contains(f.name())) continue;
QPair<QString, QString> ctr = trColumn(f.name());
QWidget * val = 0;
if (relations.contains(f.name())) {
val = new QComboBox();
QList<QPair<int, QString> > & rv(relations[f.name()]);
bool ok = false;
int sv(f.value().toInt(&ok));
for (int j = 0; j < rv.size(); ++j) {
((QComboBox*)val)->addItem(rv[j].second, rv[j].first);
if (ok)
if (sv == rv[j].first)
((QComboBox*)val)->setCurrentIndex(j);
}
if (!ok)
((QComboBox*)val)->setCurrentIndex(-1);
} else {
switch (fieldType(f)) {
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
case QVariant::ULongLong:
case QVariant::Double:
val = new QDoubleSpinBox();
((QDoubleSpinBox*)val)->setRange(-1E+99, 1E+99);
((QDoubleSpinBox*)val)->setDecimals(3); break;
case QVariant::String:
val = new QLineEdit(); break;
case QVariant::Bool:
val = new QCheckBox(); break;
case QVariant::Color:
val = new ColorButton();
((ColorButton*)val)->setUseAlphaChannel(true);
((ColorButton*)val)->setUseNativeDialog(true);
break;
case QVariant::StringList:
val = new StringListEdit();
break;
default: break;
}
if (f.type() == QVariant::String || f.type() == QVariant::StringList) val->setProperty("_string", true);
}
if (val != 0) {
QString lt = ctr.first.left(1).toUpper() + ctr.first.right(ctr.first.length() - 1);
while (lt.endsWith("_")) lt.chop(1);
QLabel * lbl = new QLabel(lt + ":");
lbl->setToolTip(ctr.second);
cws << lbl;
val->setObjectName(f.name());
cws << val;
lay->addRow(lbl, val);
} else {
if (!hidden.contains(ctr.first))
hidden << ctr.first;
}
}
updateWidgets();
emit widgetsCreated();
}
void SQLRecordWidget::updateWidgets() {
foreach (QWidget * w, cws) {
if (qobject_cast<QLineEdit * >(w)) qobject_cast<QLineEdit * >(w)->setReadOnly(ro);
if (qobject_cast<QCheckBox * >(w)) qobject_cast<QCheckBox * >(w)->setEnabled(!ro);
if (qobject_cast<QDoubleSpinBox * >(w)) qobject_cast<QDoubleSpinBox * >(w)->setReadOnly(ro);
if (qobject_cast<ColorButton * >(w)) qobject_cast<ColorButton * >(w)->setEnabled(!ro);
if (qobject_cast<StringListEdit * >(w)) qobject_cast<StringListEdit * >(w)->setEnabled(!ro);
}
}
QVariant::Type SQLRecordWidget::fieldType(const QSqlField & f) {
QString ft = ftypes.value(f.name());
if (ft.isEmpty()) return f.type();
if (ft == "l") return QVariant::StringList;
if (ft == "b") return QVariant::Bool;
if (ft == "n") return QVariant::Int;
if (ft == "f") return QVariant::Double;
if (ft == "c") return QVariant::Color;
if (ft == "r") return QVariant::Rect;
if (ft == "a") return QVariant::RectF;
if (ft == "p") return QVariant::Point;
if (ft == "v") return QVariant::PointF;
return QVariant::String;
}
void SQLRecordWidget::addTranslation(const QString & file) {
QPIConfig conf(file, QIODevice::ReadOnly, QPIConfig::Config);
QPIConfig::Branch ae = conf.allLeaves();
foreach (QPIConfig::Entry * e, ae)
translates[e->name()] = QPair<QString, QString>(e->value(), e->comment());
}
QString SQLRecordWidget::getValuesQuery() const {
QString ret("(");
bool first = true;
foreach (QWidget * w, cws) {
QWidget * vw(0);
if (qobject_cast<QLineEdit * >(w)) {if (!qobject_cast<QLineEdit * >(w)->text().isEmpty()) vw = w;}
if (qobject_cast<QCheckBox * >(w)) vw = w;
if (qobject_cast<QDoubleSpinBox * >(w)) vw = w;
if (qobject_cast<ColorButton * >(w)) vw = w;
if (qobject_cast<StringListEdit * >(w)) vw = w;
if (qobject_cast<QComboBox * >(w)) vw = w;
if (vw == 0) continue;
if (!first) ret += ",";
first = false;
ret += vw->objectName();
}
ret += ") VALUES (";
foreach (QWidget * w, cws) {
QWidget * vw(0);
if (qobject_cast<QLineEdit * >(w)) {
if (!qobject_cast<QLineEdit * >(w)->text().isEmpty()) {
vw = w;
bool q = w->property("_string").toBool();
if (q) ret += "'";
ret += qobject_cast<QLineEdit * >(w)->text();
if (q) ret += "'";
}
}
if (qobject_cast<QCheckBox * >(w)) {
vw = w;
ret += qobject_cast<QCheckBox * >(w)->isChecked() ? "1" : "0";
}
if (qobject_cast<QDoubleSpinBox * >(w)) {
vw = w;
ret += QString::number(qobject_cast<QDoubleSpinBox * >(w)->value());
}
if (qobject_cast<ColorButton * >(w)) {
vw = w;
ret += QString::number(qobject_cast<ColorButton * >(w)->color().rgba());
}
if (qobject_cast<StringListEdit * >(w)) {
vw = w;
ret += "'" + qobject_cast<StringListEdit * >(w)->value().join(";") + "'";
}
if (qobject_cast<QComboBox * >(w)) {
vw = w;
ret += ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex(), Qt::UserRole).toString();
}
if (vw == 0) continue;
ret += ",";
}
if (ret.endsWith(",")) ret.chop(1);
ret += ")";
return ret;
}
QString SQLRecordWidget::getUpdateQuery() const {
QString ret;
bool first = true;
foreach (QWidget * w, cws) {
QWidget * vw(0);
if (qobject_cast<QLineEdit * >(w)) vw = w;
if (qobject_cast<QCheckBox * >(w)) vw = w;
if (qobject_cast<QDoubleSpinBox * >(w)) vw = w;
if (qobject_cast<ColorButton * >(w)) vw = w;
if (qobject_cast<StringListEdit * >(w)) vw = w;
if (qobject_cast<QComboBox * >(w)) vw = w;
if (vw == 0) continue;
if (!first) ret += ",";
first = false;
ret += vw->objectName() + "=";
if (qobject_cast<QLineEdit * >(w)) {
if (qobject_cast<QLineEdit * >(w)->text().isEmpty())
ret += "null";
else {
bool q = w->property("_string").toBool();
if (q) ret += "'";
ret += qobject_cast<QLineEdit * >(w)->text();
if (q) ret += "'";
}
}
if (qobject_cast<QCheckBox * >(w))
ret += qobject_cast<QCheckBox * >(w)->isChecked() ? "1" : "0";
if (qobject_cast<QDoubleSpinBox * >(w))
ret += QString::number(qobject_cast<QDoubleSpinBox * >(w)->value());
if (qobject_cast<ColorButton * >(w))
ret += QString::number(qobject_cast<ColorButton * >(w)->color().rgba());
if (qobject_cast<StringListEdit * >(w))
ret += "'" + qobject_cast<StringListEdit * >(w)->value().join(";") + "'";
if (qobject_cast<QComboBox * >(w)) {
ret += ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex(), Qt::UserRole).toString();
}
}
return ret;
}
bool SQLRecordWidget::isEmpty() const {
return layout()->count() < 2;
}
void SQLRecordWidget::updateRelations() {
relations.clear();
for (int i = 0; i < relations_src.size(); ++i) {
QSqlQuery q(QString("SELECT %1,%2 FROM %3").arg(relations_src[i].key, relations_src[i].ocol, relations_src[i].table), QSqlDatabase::database(connection_name));
QList<QPair<int, QString> > cr;
while (q.next())
cr << QPair<int, QString>(q.value(0).toInt(), q.value(1).toString());
relations[relations_src[i].tcol] = cr;
}
QFormLayout * lay = (QFormLayout*)layout();
if (!lay) return;
for (int i = 0; i < lay->rowCount(); ++i) {
QString name = lay->itemAt(i, QFormLayout::FieldRole)->widget()->objectName();
if (hidden.contains(name)) continue;
QComboBox * val = qobject_cast<QComboBox*>(lay->itemAt(i, QFormLayout::FieldRole)->widget());
if (!val) continue;
if (!relations.contains(name)) continue;
QList<QPair<int, QString> > & rv(relations[name]);
bool ok = false;
int sv(val->itemData(val->currentIndex()).toInt());
val->clear();
for (int j = 0; j < rv.size(); ++j) {
val->addItem(rv[j].second, rv[j].first);
if (sv == rv[j].first)
val->setCurrentIndex(j);
}
if (!ok)
val->setCurrentIndex(-1);
}
}

View File

@@ -0,0 +1,74 @@
#ifndef SQL_RECORD_WIDGET_H
#define SQL_RECORD_WIDGET_H
#include <QWidget>
#include <QSqlQuery>
#include <QSqlField>
#include <QVariant>
#include <QMap>
#include <QSet>
class SQLRecordWidget: public QWidget {
Q_OBJECT
public:
SQLRecordWidget(QWidget * parent = 0);
~SQLRecordWidget();
void setRecord(const QSqlRecord & q, bool full_update = false);
void setReadOnly(bool yes) {ro = yes; updateWidgets();}
void setFixedValue(const QString & name, const QVariant & value);
void setTypeForName(const QString & name, const QString & type) {ftypes[name] = type;}
void clearValues();
void removeWidgets() {qDeleteAll(cws); cws.clear();}
void hideColumn(const QString & col) {hidden << col;}
void showColumn(const QString & col) {hidden.remove(col);}
void showColumns() {hidden.clear();}
void addRelation(const QString & this_column, const QString & other_table, const QString & other_key, const QString & other_column) {relations_src << RelationSrc(this_column, other_table, other_key, other_column); updateRelations();}
void removeRelations() {relations_src.clear(); updateRelations();}
void addTranslation(const QString & file);
void setConnectionName(const QString &conn_name) {connection_name = conn_name;}
QString connectionName() const {return connection_name;}
QString getValuesQuery() const;
QString getUpdateQuery() const;
bool isEmpty() const;
QWidget * valueWidget(const QString & name) const {foreach (QWidget * w, cws) if (w->objectName() == name) return w; return 0;}
void updateRelations();
protected:
QPair<QString, QString> trColumn(const QString & n) {QPair<QString, QString> trn = translates.value(n); if (trn.first.isEmpty()) return QPair<QString, QString>(n, ""); return trn;}
void createWidgets(const QSqlRecord & q);
void updateWidgets();
QVariant::Type fieldType(const QSqlField & f);
struct RelationSrc {
RelationSrc(const QString & v0 = QString(), const QString & v1 = QString(), const QString & v2 = QString(), const QString & v3 = QString()):
tcol(v0),
table(v1),
key(v2),
ocol(v3)
{}
QString tcol;
QString table;
QString key;
QString ocol;
};
QMap<QString, QPair<QString, QString> > translates;
QVector<RelationSrc> relations_src;
QMap<QString, QList<QPair<int, QString> > > relations;
QMap<QString, QString> ftypes;
QSet<QString> hidden;
QWidgetList cws;
bool ro;
QString connection_name;
signals:
void updateRequest();
void widgetsCreated();
};
#endif // SQL_RECORD_WIDGET_H

View File

@@ -0,0 +1,69 @@
#include "sql_table_widget.h"
#include "sql_table_plugin.h"
#include <QtCore/QtPlugin>
SQLTablePlugin::SQLTablePlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void SQLTablePlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool SQLTablePlugin::isInitialized() const {
return m_initialized;
}
QWidget * SQLTablePlugin::createWidget(QWidget * parent) {
return new SQLTableWidget(parent);
}
QString SQLTablePlugin::name() const {
return QLatin1String("SQLTableWidget");
}
QString SQLTablePlugin::group() const {
return QLatin1String("Editor Widgets");
}
QIcon SQLTablePlugin::icon() const {
return QIcon(":/icons/sql_table.png");
}
QString SQLTablePlugin::toolTip() const {
return QLatin1String("");
}
QString SQLTablePlugin::whatsThis() const {
return QLatin1String("");
}
bool SQLTablePlugin::isContainer() const {
return false;
}
QString SQLTablePlugin::domXml() const {
return QLatin1String("<widget class=\"SQLTableWidget\" name=\"tableSQL\">\n</widget>\n");
}
QString SQLTablePlugin::includeFile() const {
return QLatin1String("sql_table_widget.h");
}

Some files were not shown because too many files have changed in this diff Show More