1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
74
qad_sql_table/sql_record_widget.h
Normal file
74
qad_sql_table/sql_record_widget.h
Normal 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
|
||||
Reference in New Issue
Block a user