소스 검색

修改输入框,加入输入限制

lichanglin 3 년 전
부모
커밋
397807fbb9

+ 17 - 4
DataManage/entity/Airport.cpp

@@ -5,6 +5,7 @@
 #include "CheckComboBoxWidget.h"
 
 #include "charcode.h"
+#include "DebugUtil.h"
 
 QX_REGISTER_CPP_USER(Airport)
 
@@ -53,10 +54,10 @@ namespace qx {
         pData->setDescription("是否删除");
         pData->setPropertyBag("notShow",true);
         pData->setPropertyBag("notInput",true);
-        qx::QxSoftDelete SoftDelete;
-        SoftDelete.setColumnName("ISDELETE");
-        SoftDelete.setMode(qx::QxSoftDelete::mode_flag);
-        t.setSoftDelete(SoftDelete);
+//        qx::QxSoftDelete SoftDelete;
+//        SoftDelete.setColumnName("ISDELETE");
+//        SoftDelete.setMode(qx::QxSoftDelete::mode_flag);
+//        t.setSoftDelete(SoftDelete);
 
         pData = t.data(& Airport::m_IMPORTTIME, "IMPORTTIME", 0, true, true);
         pData->setDescription("更新时间");
@@ -113,3 +114,15 @@ void Airport::setIMPORTTIME(const QDateTime & val) { m_IMPORTTIME = val; }
 
 void Airport::setNOTE(const QString & val) { m_NOTE = val; }
 
+void Airport::onBeforeFetch(qx::dao::detail::IxDao_Helper *dao)
+{
+    qDebug() << "onBeforeFetch     **********************";
+    Debug(dao->query().executedQuery());
+}
+
+void Airport::onAfterFetch(qx::dao::detail::IxDao_Helper *dao)
+{
+    qDebug() << "onAfterFetch     **********************";
+    Debug(dao->query().executedQuery());
+}
+

+ 39 - 1
DataManage/entity/Airport.h

@@ -3,10 +3,22 @@
 
 #include "QxOrm.h"
 #include "precompiled.h"
+class Airport;
+
+namespace qx {
+namespace dao {
+namespace detail {
+
+template <>
+struct QxDao_Trigger<Airport>;
+
+} // namespace detail
+} // namespace dao
+} // namespace qx
 
 class Airport
 {
-
+    friend struct qx::dao::detail::QxDao_Trigger<Airport>;
    QX_REGISTER_FRIEND_CLASS(Airport)
 
 protected:
@@ -61,7 +73,11 @@ public:
 public:
 
    static QString table_name(bool key = false) { return (key ? QString("Airport") : QString("T_CM_AIRPORT")); }
+protected:
 
+   // The following triggers methods must be implemented in a custom code
+   virtual void onBeforeFetch(qx::dao::detail::IxDao_Helper * dao);
+   virtual void onAfterFetch(qx::dao::detail::IxDao_Helper * dao);
 };
 
 typedef std::shared_ptr<Airport> Airport_ptr;
@@ -71,4 +87,26 @@ typedef std::shared_ptr<list_of_Airport> list_of_Airport_ptr;
 QX_REGISTER_PRIMARY_KEY(Airport, double)
 QX_REGISTER_HPP_USER(Airport, qx::trait::no_base_class_defined, 0)
 
+namespace qx {
+namespace dao {
+namespace detail {
+
+template <>
+struct QxDao_Trigger<Airport>
+{
+
+   static inline void onBeforeFetch(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { if (t) { t->onBeforeFetch(dao); } }
+   static inline void onAfterFetch(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { if (t) { t->onAfterFetch(dao); } }
+   static inline void onBeforeInsert(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { Q_UNUSED(t); Q_UNUSED(dao); }
+   static inline void onAfterInsert(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { Q_UNUSED(t); Q_UNUSED(dao); }
+   static inline void onBeforeUpdate(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { Q_UNUSED(t); Q_UNUSED(dao); }
+   static inline void onAfterUpdate(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { Q_UNUSED(t); Q_UNUSED(dao); }
+   static inline void onBeforeDelete(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { Q_UNUSED(t); Q_UNUSED(dao); }
+   static inline void onAfterDelete(Airport * t, qx::dao::detail::IxDao_Helper * dao)  { Q_UNUSED(t); Q_UNUSED(dao); }
+};
+
+} // namespace detail
+} // namespace dao
+} // namespace qx
+
 #endif // AIRPORT_H

+ 34 - 0
DataManage/forms/AirportWidget.cpp

@@ -3,6 +3,7 @@
 #include "Airport.h"
 #include "Application.h"
 #include "CustomDelegate.h"
+#include "DebugUtil.h"
 
 #include <QMessageBox>
 
@@ -186,3 +187,36 @@ void AirportWidget::onDataChange(const QModelIndex &topLeft, const QModelIndex &
 }
 
 
+void AirportWidget::on_pushButton_clicked()
+{
+    QList<Airport_ptr> airports;
+    qx::QxSqlQuery query("where 1 = 1 ");
+//    query.where("1").isEqualTo(1);
+//    query.and_(Airport::column_LATITUDE()).isGreaterThan(1);
+//    query.where(Airport::column_LATITUDE()).isGreaterThan(1);
+    QStringList columns;
+    columns << Airport::column_HEIGHT();
+    QSqlError error = qx::dao::fetch_by_query(query,airports,0,columns);
+    if(error.isValid())
+        qDebug() << "------" << error.text();
+
+    QSqlQuery query1(qx::QxSqlDatabase::getSingleton()->getDatabase());
+//    query1.prepare("select ID FROM T_CM_AIRPORT WHERE 1 = :1_1_0 AND LATITUDE > :LATITUDE_3_0");
+//    query1.bindValue(":1_1_0",1);
+//    query1.bindValue(":LATITUDE_3_0",1);
+
+    query1.prepare("select ID FROM T_CM_AIRPORT WHERE 123 = :lcl_1");
+    query1.bindValue(":lcl_1",-1);
+//    query1.bindValue(":LATITUDE_3_0",1);
+    bool result = query1.exec();
+    if(!query1.next())
+    {
+
+        Debug(query1.lastError().text());
+    }
+    else
+    {
+        Debug(query1.value(0));
+        Debug(result);
+    }
+}

+ 2 - 0
DataManage/forms/AirportWidget.h

@@ -36,6 +36,8 @@ private slots:
 	void onRemove();
     void onDataChange(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
 
+    void on_pushButton_clicked();
+
 private:
 	Ui::AirportWidget *ui;
 	AirportModel *m_Model;

+ 7 - 0
DataManage/forms/AirportWidget.ui

@@ -75,6 +75,13 @@
         </property>
        </widget>
       </item>
+      <item>
+       <widget class="QPushButton" name="pushButton">
+        <property name="text">
+         <string>test</string>
+        </property>
+       </widget>
+      </item>
       <item>
        <spacer name="horizontalSpacer_2">
         <property name="orientation">

+ 0 - 7
DataManage/mainwindow.cpp

@@ -6,11 +6,6 @@
 #include <QDebug>
 #include <QHBoxLayout>
 
-static void getBytes(char *src, int srcLength, int length)
-{
-
-}
-
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
@@ -20,8 +15,6 @@ MainWindow::MainWindow(QWidget *parent)
     QHBoxLayout *hLayout = new QHBoxLayout(this);
     hLayout->addWidget(widget);
     ui->centralwidget->setLayout(hLayout);
-    double lon;
-    getBytes((char*)&lon,sizeof(lon),3);
 }
 
 MainWindow::~MainWindow()

+ 19 - 0
DataManage/widgets/IxWidgets/LineEditWidget.cpp

@@ -1,5 +1,6 @@
 #include "LineEditWidget.h"
 #include <QRegExpValidator>
+#include "DoubleValidator.h"
 
 const QString LineEditWidget::type = "LineEdit";
 
@@ -8,6 +9,24 @@ LineEditWidget::LineEditWidget(QWidget *parent)
 {
 }
 
+void LineEditWidget::setIntValidator(int min, int max)
+{
+	QValidator* validator = new QIntValidator(min, max, this);
+	setValidator(validator);
+}
+
+void LineEditWidget::setDoubleValidator(double min, double max, int precision)
+{
+	QValidator* validator = new DoubleValidator(min, max, precision, this);
+	setValidator(validator);
+}
+
+void LineEditWidget::setRegExpValidator(const QString& regExp)
+{
+	QRegExp re(regExp);
+	setValidator(new QRegExpValidator(re, this));
+}
+
 QVariant LineEditWidget::getValue() const
 {
     return text().trimmed();

+ 6 - 1
DataManage/widgets/IxWidgets/LineEditWidget.h

@@ -13,8 +13,13 @@ public:
 public:
     LineEditWidget(QWidget *parent);
 
-    IXWIDGET_OBJECT_NAME
+	IXWIDGET_OBJECT_NAME
 
+	void setIntValidator(int min, int max);
+
+	void setDoubleValidator(double min, double max, int Precision);
+
+	void setRegExpValidator(const QString& regExp);
 public:
 	QVariant getValue() const override;
 

+ 3 - 3
DataManage/widgets/TagEdit.h

@@ -1,5 +1,5 @@
-#ifndef TAGEDIT_H
-#define TAGEDIT_H
+#ifndef TAGEDITWIDGET_H
+#define TAGEDITWIDGET_H
 
 #include <QLineEdit>
 #include <QLabel>
@@ -37,4 +37,4 @@ protected:
     QVector<Tag *> tags;
 };
 
-#endif // TAGEDIT_H
+#endif // TAGEDITWIDGET_H