Explorar o código

V0.3.3
1、完成了大部分的检测时段功能

apple hai 2 semanas
pai
achega
24888869df

+ 2 - 0
SettingLibrary/CMakeLists.txt

@@ -33,6 +33,7 @@ file(GLOB LOCAL_SRC
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/AICompare/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Basic/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod/*.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod/CPushButtonTime/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Database/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Noise/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/warning/*.cpp
@@ -92,6 +93,7 @@ target_include_directories(${libName} PRIVATE
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/AICompare
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Basic
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod
+    ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod/CPushButtonTime
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Database
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Noise
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/warning

+ 58 - 0
SettingLibrary/Modules/CheckPeriod/CPushButtonTime/cpushbuttontime.cpp

@@ -0,0 +1,58 @@
+#include "cpushbuttontime.h"
+#include "ui_cpushbuttontime.h"
+
+
+
+CPushButtonTime::CPushButtonTime(QWidget *parent) :
+    QWidget(parent),
+    ui(new Ui::CPushButtonTime)
+{
+    ui->setupUi(this);
+
+    /* 注册事件过滤器 */
+    ui->label_icon->installEventFilter(this);
+    ui->label_text->installEventFilter(this);
+}
+
+CPushButtonTime::~CPushButtonTime()
+{
+    delete ui;
+}
+
+
+/* 设置文本 */
+void CPushButtonTime::setText(const QString &text)
+{
+    ui->label_text->setText(text);
+}
+
+/* 获取文本 */
+QString CPushButtonTime::getText() const
+{
+    return ui->label_text->text();
+}
+
+/* 设置图标 */
+void CPushButtonTime::setIcon(const QImage &icon)
+{
+    if(icon.isNull())
+    {
+        ui->label_icon->clear();
+        return;
+    }
+    QPixmap pixmap = QPixmap::fromImage(icon);
+    ui->label_icon->setPixmap(pixmap);
+}
+
+/* 事件过滤器 */
+bool CPushButtonTime::eventFilter(QObject *watched, QEvent *event)
+{
+    if(event->type() == QEvent::MouseButtonPress)
+    {
+        /* 按钮被点击 */
+        emit signal_buttonClicked();
+        return true; // 事件已处理
+    }
+    return QWidget::eventFilter(watched, event); // 继续传递事件
+}
+

+ 42 - 0
SettingLibrary/Modules/CheckPeriod/CPushButtonTime/cpushbuttontime.h

@@ -0,0 +1,42 @@
+#ifndef CPUSHBUTTONTIME_H
+#define CPUSHBUTTONTIME_H
+
+#include <QWidget>
+#include <QImage>
+#include <qobjectdefs.h>
+
+namespace Ui {
+class CPushButtonTime;
+}
+
+class CPushButtonTime : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit CPushButtonTime(QWidget *parent = nullptr);
+    ~CPushButtonTime();
+
+    /* 设置文本 */
+    void setText(const QString &text);
+    /* 获取文本 */
+    QString getText() const;
+    /* 设置图标 */
+    void setIcon(const QImage &icon);
+
+signals:
+    /* 按钮被点击 */
+    void signal_buttonClicked();
+
+private slots:
+
+
+protected:
+    /* 事件过滤器 */
+    bool eventFilter(QObject *watched, QEvent *event) override;
+
+private:
+    Ui::CPushButtonTime *ui;
+};
+
+#endif // CPUSHBUTTONTIME_H

+ 80 - 0
SettingLibrary/Modules/CheckPeriod/CPushButtonTime/cpushbuttontime.ui

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CPushButtonTime</class>
+ <widget class="QWidget" name="CPushButtonTime">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>242</width>
+    <height>32</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>0</width>
+    <height>32</height>
+   </size>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>1666666</width>
+    <height>32</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <property name="spacing">
+    <number>3</number>
+   </property>
+   <property name="leftMargin">
+    <number>12</number>
+   </property>
+   <property name="topMargin">
+    <number>8</number>
+   </property>
+   <property name="rightMargin">
+    <number>8</number>
+   </property>
+   <property name="bottomMargin">
+    <number>8</number>
+   </property>
+   <item>
+    <widget class="QLabel" name="label_text">
+     <property name="minimumSize">
+      <size>
+       <width>55</width>
+       <height>0</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label_icon">
+     <property name="minimumSize">
+      <size>
+       <width>16</width>
+       <height>16</height>
+      </size>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>16</width>
+       <height>16</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 0 - 588
SettingLibrary/Modules/CheckPeriod/addperioddialog.ui

@@ -1,588 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>AddPeriodDialog</class>
- <widget class="QDialog" name="AddPeriodDialog">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>416</width>
-    <height>273</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Dialog</string>
-  </property>
-  <property name="styleSheet">
-   <string notr="true">QWidget#widgetBackground
-{
-	background: #FFFFFF;
-	border-radius: 8px;
-}
-QWidget#widgetTop
-{
-	border-bottom: 1px solid #E6E9F4;
-}
-
-QLabel
-{
-	font-weight: 400;
-	font-size: 14px;
-	color: #3A3F63;
-}
-QLabel#labelTitle
-{
-	font-weight: 500;
-	font-size: 18px;
-}
-
-QPushButton#btnClose
-{
-	border-image: url(:/close.png);
-}
-QPushButton#btnClose:hover
-{
-	border-image: url(:/close_hover.png);
-}
-QPushButton#btnCancel
-{
-	background: #FFFFFF;
-	border-radius: 16px;
-	border: 1px solid #E6E9F4;
-	font-weight: 500;
-	font-size: 14px;
-	color: #3A3F63;
-}
-QPushButton#btnCancel:hover
-{
-	border: 1px solid #4458FE;
-	color: #4458FE;
-}
-QPushButton#btnOK
-{
-	background: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 #4F8AFF, stop:1 #4B5EFF);
-	border-radius: 16px;
-	font-weight: 500;
-	font-size: 14px;
-	color: #FFFFFF;
-}
-QPushButton#btnOK:hover
-{
-	background: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 #4F8AFF, stop:1 #7182ff);
-}
-
-
-QComboBox
-{
-	padding-left: 12px;
-	font-weight: 400;
-	font-size: 14px;
-	color: #3A3F63;
-	background: #FFFFFF;
-	border-radius: 4px;
-	border: 1px solid #E6E9F4;
-}
-QComboBox:hover,QComboBox:on
-{
-	border: 1px solid #4458FE;
-}
-QComboBox QAbstractItemView
-{
-	margin-left: 4px;
-	margin-right: 20px;
-	margin-bottom: 4px;
-	font-size: 14px;
-	background-color: #FFFFFF;
-	outline:0px;
-	border-radius: 4px;
-}
-QComboBox QAbstractItemView::item 
-{
-    border-radius: 4px;
-	color: #3A3F63;
-    height: 40px;
-	background-color: #FFFFFF;
-	font-size: 14px;
-	padding-left: 12px;
-}
-QComboBox QAbstractItemView::item:hover 
-{
-	font-weight: 500;
-    color: #3A3F63;
-	background-color: #EEF2FF;
-}
-QComboBox QAbstractItemView::item:selected
-{
-	font-weight: 500;
-    color: #3A3F63;
-	background-color: #EEF2FF;
-}
-QComboBox::down-arrow
-{
-	width: 16px;
-	image: url(:/down_arrow.png);
-	padding-right: 8px;
-}
-QComboBox::drop-down
-{	
-	width: 16px;
-	background-color: transparent;
-}</string>
-  </property>
-  <layout class="QGridLayout" name="gridLayout">
-   <property name="leftMargin">
-    <number>0</number>
-   </property>
-   <property name="topMargin">
-    <number>0</number>
-   </property>
-   <property name="rightMargin">
-    <number>0</number>
-   </property>
-   <property name="bottomMargin">
-    <number>0</number>
-   </property>
-   <property name="spacing">
-    <number>0</number>
-   </property>
-   <item row="0" column="0">
-    <widget class="QWidget" name="widgetBackground" native="true">
-     <layout class="QVBoxLayout" name="verticalLayout">
-      <property name="spacing">
-       <number>0</number>
-      </property>
-      <property name="leftMargin">
-       <number>0</number>
-      </property>
-      <property name="topMargin">
-       <number>0</number>
-      </property>
-      <property name="rightMargin">
-       <number>0</number>
-      </property>
-      <property name="bottomMargin">
-       <number>0</number>
-      </property>
-      <item>
-       <widget class="QWidget" name="widgetTop" native="true">
-        <property name="minimumSize">
-         <size>
-          <width>0</width>
-          <height>57</height>
-         </size>
-        </property>
-        <property name="maximumSize">
-         <size>
-          <width>16777215</width>
-          <height>57</height>
-         </size>
-        </property>
-        <layout class="QHBoxLayout" name="horizontalLayout_4">
-         <property name="spacing">
-          <number>0</number>
-         </property>
-         <property name="leftMargin">
-          <number>32</number>
-         </property>
-         <property name="topMargin">
-          <number>0</number>
-         </property>
-         <property name="rightMargin">
-          <number>16</number>
-         </property>
-         <property name="bottomMargin">
-          <number>0</number>
-         </property>
-         <item>
-          <widget class="QLabel" name="labelTitle">
-           <property name="text">
-            <string>添加时段</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QPushButton" name="btnClose">
-           <property name="minimumSize">
-            <size>
-             <width>32</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>32</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="text">
-            <string/>
-           </property>
-          </widget>
-         </item>
-        </layout>
-       </widget>
-      </item>
-      <item>
-       <widget class="QWidget" name="widgetContent" native="true">
-        <layout class="QVBoxLayout" name="verticalLayout_2">
-         <property name="spacing">
-          <number>24</number>
-         </property>
-         <property name="leftMargin">
-          <number>32</number>
-         </property>
-         <property name="topMargin">
-          <number>32</number>
-         </property>
-         <property name="rightMargin">
-          <number>32</number>
-         </property>
-         <property name="bottomMargin">
-          <number>32</number>
-         </property>
-         <item>
-          <widget class="QWidget" name="widgetDate" native="true">
-           <property name="minimumSize">
-            <size>
-             <width>0</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>16777215</width>
-             <height>32</height>
-            </size>
-           </property>
-           <layout class="QHBoxLayout" name="horizontalLayout_5">
-            <property name="spacing">
-             <number>0</number>
-            </property>
-            <property name="leftMargin">
-             <number>0</number>
-            </property>
-            <property name="topMargin">
-             <number>0</number>
-            </property>
-            <property name="rightMargin">
-             <number>0</number>
-            </property>
-            <property name="bottomMargin">
-             <number>0</number>
-            </property>
-            <item>
-             <widget class="QLabel" name="label_2">
-              <property name="minimumSize">
-               <size>
-                <width>78</width>
-                <height>0</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>78</width>
-                <height>16777215</height>
-               </size>
-              </property>
-              <property name="text">
-               <string>&lt;font color = #D21F21 &gt;*&lt;/font&gt;日期选择:</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QDateTimeEdit" name="dateTimeEdit">
-              <property name="minimumSize">
-               <size>
-                <width>274</width>
-                <height>32</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>274</width>
-                <height>32</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </widget>
-         </item>
-         <item>
-          <widget class="QWidget" name="widgetWeek" native="true">
-           <property name="minimumSize">
-            <size>
-             <width>0</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>16777215</width>
-             <height>32</height>
-            </size>
-           </property>
-           <layout class="QHBoxLayout" name="horizontalLayout_7">
-            <property name="spacing">
-             <number>0</number>
-            </property>
-            <property name="leftMargin">
-             <number>0</number>
-            </property>
-            <property name="topMargin">
-             <number>0</number>
-            </property>
-            <property name="rightMargin">
-             <number>0</number>
-            </property>
-            <property name="bottomMargin">
-             <number>0</number>
-            </property>
-            <item>
-             <widget class="QLabel" name="label_4">
-              <property name="minimumSize">
-               <size>
-                <width>78</width>
-                <height>0</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>78</width>
-                <height>16777215</height>
-               </size>
-              </property>
-              <property name="text">
-               <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; color:#d21f21;&quot;&gt;*&lt;/span&gt;星期选择:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QComboBox" name="comboBox">
-              <property name="minimumSize">
-               <size>
-                <width>274</width>
-                <height>32</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>274</width>
-                <height>32</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </widget>
-         </item>
-         <item>
-          <widget class="QWidget" name="widgetTime" native="true">
-           <property name="minimumSize">
-            <size>
-             <width>0</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>16777215</width>
-             <height>32</height>
-            </size>
-           </property>
-           <layout class="QHBoxLayout" name="horizontalLayout_6">
-            <property name="spacing">
-             <number>0</number>
-            </property>
-            <property name="leftMargin">
-             <number>0</number>
-            </property>
-            <property name="topMargin">
-             <number>0</number>
-            </property>
-            <property name="rightMargin">
-             <number>0</number>
-            </property>
-            <property name="bottomMargin">
-             <number>0</number>
-            </property>
-            <item>
-             <widget class="QLabel" name="label_3">
-              <property name="minimumSize">
-               <size>
-                <width>78</width>
-                <height>0</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>78</width>
-                <height>16777215</height>
-               </size>
-              </property>
-              <property name="text">
-               <string>&lt;font color = #D21F21 &gt;*&lt;/font&gt;时段选择:</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QWidget" name="widget_2" native="true">
-              <property name="minimumSize">
-               <size>
-                <width>125</width>
-                <height>32</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>125</width>
-                <height>32</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QLabel" name="label">
-              <property name="minimumSize">
-               <size>
-                <width>24</width>
-                <height>0</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>24</width>
-                <height>16777215</height>
-               </size>
-              </property>
-              <property name="text">
-               <string>-</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QWidget" name="widget" native="true">
-              <property name="minimumSize">
-               <size>
-                <width>125</width>
-                <height>32</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>125</width>
-                <height>32</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </widget>
-         </item>
-        </layout>
-       </widget>
-      </item>
-      <item>
-       <widget class="QWidget" name="widgetBottom" native="true">
-        <property name="minimumSize">
-         <size>
-          <width>0</width>
-          <height>64</height>
-         </size>
-        </property>
-        <property name="maximumSize">
-         <size>
-          <width>16777215</width>
-          <height>64</height>
-         </size>
-        </property>
-        <layout class="QHBoxLayout" name="horizontalLayout_3">
-         <property name="spacing">
-          <number>16</number>
-         </property>
-         <property name="leftMargin">
-          <number>0</number>
-         </property>
-         <property name="topMargin">
-          <number>0</number>
-         </property>
-         <property name="rightMargin">
-          <number>32</number>
-         </property>
-         <property name="bottomMargin">
-          <number>32</number>
-         </property>
-         <item>
-          <spacer name="horizontalSpacer">
-           <property name="orientation">
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-         <item>
-          <widget class="QPushButton" name="btnCancel">
-           <property name="minimumSize">
-            <size>
-             <width>60</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>60</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>取消</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QPushButton" name="btnOK">
-           <property name="minimumSize">
-            <size>
-             <width>60</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>60</width>
-             <height>32</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>确定</string>
-           </property>
-          </widget>
-         </item>
-        </layout>
-       </widget>
-      </item>
-     </layout>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>

+ 47 - 35
SettingLibrary/Modules/CheckPeriod/checkperiodfunc.cpp

@@ -1,7 +1,7 @@
 #include "checkperiodfunc.h"
 
 
-
+#include "spdlog/spdlog.h"
 
 
 
@@ -14,25 +14,10 @@
  * @return true 
  * @return false 
  */
-bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, bool isExcludeSelf)
+bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan)
 {
-    QList<OnePlan_t> list = planList;
-    if(isExcludeSelf)
-    {
-        /* 排除自身 */
-        for(int i = 0; i < list.size(); ++i)
-        {
-            if(list[i].weekType == plan.weekType &&
-               list[i].timeStart == plan.timeStart && list[i].timeEnd == plan.timeEnd)
-            {
-                list.removeAt(i);
-                break;
-            }
-        }
-    }
-
     bool isConflict = false;
-    for(const auto& it : list)
+    for(const auto& it : planList)
     {
         /* info结束时间小于开始时间,或者info开始时间大于结束时间,就不冲突 */
         bool isLess = weekTimeIsGerater(it.weekType, it.timeStart, plan.weekType, plan.timeEnd);
@@ -50,6 +35,27 @@ bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan
     return isConflict;
 }
 
+/* 查重函数重载,排除一个计划 */
+bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, const OnePlan_t& excludePlan)
+{
+    QList<OnePlan_t> list = planList;
+    /* 排除自身 */
+    for(int i = 0; i < list.size(); ++i)
+    {
+        // SPDLOG_DEBUG("{}, {}-{} 与 {}, {}-{}", 
+        //     static_cast<int>(list[i].weekType), list[i].timeStart.toString("hh:mm:ss").toStdString(), list[i].timeEnd.toString("hh:mm:ss").toStdString(), 
+        //     static_cast<int>(excludePlan.weekType), excludePlan.timeStart.toString("hh:mm:ss").toStdString(), excludePlan.timeEnd.toString("hh:mm:ss").toStdString());
+        if(list[i].weekType == excludePlan.weekType &&
+           list[i].timeStart == excludePlan.timeStart && list[i].timeEnd == excludePlan.timeEnd)
+        {
+            list.removeAt(i);
+            break;
+        }
+    }
+
+    return isWeekPlanDuplicate(list, plan);
+}
+
 
 /**
  * @brief 日期查重函数
@@ -60,25 +66,10 @@ bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan
  * @return true 
  * @return false 
  */
-bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, bool isExcludeSelf)
+bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan)
 {
-    QList<OnePlan_t> list = planList;
-    if(isExcludeSelf)
-    {
-        /* 排除自身 */
-        for(int i = 0; i < list.size(); ++i)
-        {
-            if(list[i].date == plan.date &&
-               list[i].timeStart == plan.timeStart && list[i].timeEnd == plan.timeEnd)
-            {
-                list.removeAt(i);
-                break;
-            }
-        }
-    }
-
     bool isConflict = false;
-    for(const auto& it : list)
+    for(const auto& it : planList)
     {
         /* info结束时间小于开始时间,或者info开始时间大于结束时间,就不冲突 */
         bool isLess = dateTimeIsGerater(it.date, it.timeStart, plan.date, plan.timeEnd);
@@ -96,6 +87,27 @@ bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan
     return isConflict;
 }
 
+/* 日期查重,重载版,排除一个日期计划 */
+bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, const OnePlan_t& excludePlan)
+{
+    QList<OnePlan_t> list = planList;
+
+    /* 排除自身 */
+    for(int i = 0; i < list.size(); ++i)
+    {
+        if(list[i].date == excludePlan.date &&
+           list[i].timeStart == excludePlan.timeStart && list[i].timeEnd == excludePlan.timeEnd)
+        {
+            list.removeAt(i);
+            break;
+        }
+    }
+    
+    return isDatePlanDuplicate(list, plan);
+}
+
+
+
 /* 周时间1大于周时间2 */
 bool weekTimeIsGerater(const eWeekType& week1, const QTime& time1,
                                  const eWeekType& week2, const QTime& time2)

+ 7 - 2
SettingLibrary/Modules/CheckPeriod/checkperiodfunc.h

@@ -22,7 +22,9 @@
  * @return true 
  * @return false 
  */
-bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, bool isExcludeSelf = false);
+bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan);
+/* 查重函数重载,排除一个计划 */
+bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, const OnePlan_t& excludePlan);
 
 /**
  * @brief 日期查重函数
@@ -33,7 +35,10 @@ bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan
  * @return true 
  * @return false 
  */
-bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, bool isExcludeSelf = false);
+bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan);
+/* 日期查重,重载版,排除一个日期计划 */
+bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, const OnePlan_t& excludePlan);
+
 
 /* 周时间1大于周时间2 */
 bool weekTimeIsGerater(const eWeekType& week1, const QTime& time1,

+ 300 - 32
SettingLibrary/Modules/CheckPeriod/checkperiodwidget.cpp

@@ -1,4 +1,7 @@
 #include "checkperiodwidget.h"
+#include "GlobalVariable.h"
+#include "checkperiodfunc.h"
+#include "onedetectplan.h"
 #include "ui_checkperiodwidget.h"
 #include "addperioddialog.h"
 
@@ -7,6 +10,15 @@
 
 #include <QFile>
 #include <QListWIdgetItem>
+#include <algorithm>
+#include <cmath>
+#include <qboxlayout.h>
+#include "checkperiodfunc.h"
+#include "tipwidget.h"
+#include "GlobalInfo.h"
+#include "timewidget.h"
+
+
 
 CheckPeriodWidget::CheckPeriodWidget(QWidget *parent) :
     QWidget(parent),
@@ -21,12 +33,18 @@ CheckPeriodWidget::CheckPeriodWidget(QWidget *parent) :
         return;
     }
 
+    
+
 
     /* 下拉框设置阴影 */
     ui->comboBox_selectCompareItem->setViewShadowEffect();
+    
+    /* 初始化检测计划容器 */
+    m_layoutDetectPlans = qobject_cast<QVBoxLayout*>(ui->scrollArea_detectPlans->layout());
 
     connect(ui->pBtn_addDetectPlan, &QPushButton::clicked, this, &CheckPeriodWidget::do_pBtn_addDetectPlan_clicked);
     connect(ui->pBtn_addNoDetectPlan, &QPushButton::clicked, this, &CheckPeriodWidget::do_pBtn_addNoDetectPlan_clicked);
+    connect(ui->comboBox_selectCompareItem, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CheckPeriodWidget::do_comboBox_selectCompareItem_currentIndexChanged);
 
     /* 设置UI */
     UIStyle.registerWidget(this);
@@ -43,6 +61,7 @@ CheckPeriodWidget::CheckPeriodWidget(QWidget *parent) :
 
     /* 初始化列表 */
     initListWidget();
+
 }
 
 CheckPeriodWidget::~CheckPeriodWidget()
@@ -51,44 +70,105 @@ CheckPeriodWidget::~CheckPeriodWidget()
     delete ui;
 }
 
-/* 获取计划列表 */
-QList<OnePlan_t> CheckPeriodWidget::getDetectPlanList()
+
+/* 更新可选的对比项列表 */
+void CheckPeriodWidget::updateCompareItemList(const QList<CompareItemInfo_t>& compareItemList)
 {
-    m_planList.clear();
-    for(int i = 0; i < ui->listWidget_detectPlan->count(); ++i)
+    /* 先获取当前选择的列表项 */
+    int id = ui->comboBox_selectCompareItem->currentData().value<int>();
+    ui->comboBox_selectCompareItem->clear();
+    m_pListcurrDetect = nullptr;
+    /* 屏蔽comboBox信号 */
+    ui->comboBox_selectCompareItem->blockSignals(true);
+    for(const auto& item : compareItemList)
     {
-        QListWidgetItem *item = ui->listWidget_detectPlan->item(i);
-        OneDetectPlan *detectPlan = qobject_cast<OneDetectPlan*>(ui->listWidget_detectPlan->itemWidget(item));
-        if(detectPlan)
+        /* 添加到下拉框 */
+        ui->comboBox_selectCompareItem->addItem(item.strName, QVariant::fromValue(item.nID));
+    }
+
+    /* 设置当前选择的对比项 */
+    if(id != 0)
+    {
+        /* 屏蔽comboBox信号 */
+        ui->comboBox_selectCompareItem->blockSignals(true);
+        for(int i = 0; i < ui->comboBox_selectCompareItem->count(); ++i)
         {
-            m_planList.append(detectPlan->getPlan());
+            if(ui->comboBox_selectCompareItem->itemData(i).value<int>() == id)
+            {
+                ui->comboBox_selectCompareItem->setCurrentIndex(i);
+                break;
+            }
         }
+        
+    } else
+    {
+        ui->comboBox_selectCompareItem->setCurrentIndex(0);
     }
-
-    return m_planList;
+    /* 恢复comboBox信号 */
+    ui->comboBox_selectCompareItem->blockSignals(false);
+    /* 手动切换当前的列表 */
+    do_comboBox_selectCompareItem_currentIndexChanged(ui->comboBox_selectCompareItem->currentIndex());
 }
 
+
 /* 设置计划列表 */
 void CheckPeriodWidget::setDetectPlanList(const QList<OnePlan_t>& planList)
 {
-    m_planList = planList;
-    ui->listWidget_detectPlan->clear();
+    m_currentPlanList = planList;
+    removeAllDetectPlanWidgets();
 
-    for(const auto& plan : m_planList)
+    for(const auto& plan : m_currentPlanList)
     {
         addDetectPlan(plan);
     }
 }
 
+/* 选择了一个对比项 */
+void CheckPeriodWidget::do_comboBox_selectCompareItem_currentIndexChanged(int index)
+{
+    /* 获取当前选择的对比项id */
+    int id = ui->comboBox_selectCompareItem->currentData().value<int>();
+    if(id == 0)
+    {
+        m_pListcurrDetect = nullptr;
+        SPDLOG_LOGGER_WARN(m_logger, "对比项ID为0,无法获取检测计划列表");
+        return;
+    }
+
+    /* 如果已经有了,就不需要重新创建 */
+    if(m_mapDetectPlanList.contains(id))
+    {
+        m_pListcurrDetect = m_mapDetectPlanList.value(id);
+    }else 
+    {
+        /* 创建一个新的列表 */
+        m_pListcurrDetect = new QList<OneDetectPlan*>();
+        m_mapDetectPlanList.insert(id, m_pListcurrDetect);
+    }
+
+    /* 清空当前的布局 */
+    removeAllDetectPlanWidgets();
+    
+    addDetectPlanToLayout();
+}
+
 
 /* 添加一个检测计划 */
 void CheckPeriodWidget::do_pBtn_addDetectPlan_clicked()
 {
+    /* 检查当前有没有对比项选择 */
+    int id = ui->comboBox_selectCompareItem->currentData().value<int>();
+    if(id <= 0)
+    {
+        TipWidget::display(TipWidget::OPERATOR_WARN, "请先选择一个对比项", GInfo.getTopWindow());
+        SPDLOG_LOGGER_WARN(m_logger, "没有选择对比项,无法添加检测计划");
+        return;
+    }
     AddPeriodDialog dlg(PERIOD_WEEK);
     /* 更新计划列表 */
-    getDetectPlanList();
+    updateDetectPlanList(1);
     /* 设置计划列表 */
-    dlg.setPlanList(m_planList);
+    dlg.setPlanList(m_currentPlanList);
     dlg.exec();
 
     if(!dlg.isOK())
@@ -102,6 +182,15 @@ void CheckPeriodWidget::do_pBtn_addDetectPlan_clicked()
 /* 添加一个不检测计划 */
 void CheckPeriodWidget::do_pBtn_addNoDetectPlan_clicked()
 {
+    /* 检查当前有没有对比项选择 */
+    int id = ui->comboBox_selectCompareItem->currentData().value<int>();
+    // if(id <= 0)
+    // {
+    //     TipWidget::display(TipWidget::OPERATOR_WARN, "请先选择一个对比项", GInfo.getTopWindow());
+    //     SPDLOG_LOGGER_WARN(m_logger, "没有选择对比项,无法添加检测计划");
+    //     return;
+    // }
+
     AddPeriodDialog dlg(PERIOD_DATE);
     dlg.exec();
 }
@@ -109,7 +198,18 @@ void CheckPeriodWidget::do_pBtn_addNoDetectPlan_clicked()
 /* 删除一个检测计划 */
 void CheckPeriodWidget::do_pBtn_deleteDetectPlan_clicked()
 {
+    /* 获取信号发送者 */
+    OneDetectPlan *pDetect = qobject_cast<OneDetectPlan*>(sender());
+    if(pDetect == nullptr)
+    {
+        return;
+    }
+    m_layoutDetectPlans->removeWidget(pDetect);
+    m_pListcurrDetect->removeAll(pDetect);
 
+    delete pDetect;
+    /* 重新排序 */
+    // sortDetectPlanList();
 }
 
 /* 删除一个不检测计划 */
@@ -119,40 +219,208 @@ void CheckPeriodWidget::do_pBtn_deleteNoDetectPlan_clicked()
 }
 
 
+/* 修改了日期或周几,检测是否冲突 */
+void CheckPeriodWidget::do_detectPlanModifiedWeek(OnePlan_t formerPlan, OnePlan_t newPlan)
+{
+    OneDetectPlan *pDetect = qobject_cast<OneDetectPlan*>(sender());
+    /* 更新计划 */
+    updateDetectPlanList(1);
+    /* 检测是否冲突 */
+    if(isWeekPlanDuplicate(m_currentPlanList, newPlan, newPlan))
+    {
+        /* 弹出提示 */
+        TipWidget::display(TipWidget::OPERATOR_WARN, "与已有计划冲突,请重新修改", GInfo.getTopWindow());
+        SPDLOG_LOGGER_WARN(m_logger, "检测计划冲突");
+        /* 恢复原计划 */
+        pDetect->setPlan(formerPlan);
+        return;
+    }
+
+    
+
+    /* 重新排序 */
+    sortDetectPlanList();
+}
+
+
+/* 点击了检测计划的时间按钮,在这里修改时间 */
+void CheckPeriodWidget::do_detectPlanModifiedTime(QPoint pBtnSize, bool isStartTime)
+{
+   /* 获取信号发送者 */
+    auto one = qobject_cast<OneDetectPlan*>(sender());
+    OnePlan_t plan = one->getPlan();
+    /* 创建时间选择控件 */
+    std::shared_ptr<TimeWidget> tw = std::make_shared<TimeWidget>(this, TimeWidget::ShowType::Dialog);
+    /* 设置样式表 */
+    tw->setStyleSheet(m_qssPlan);
+    /* 设置图标 */
+    tw->setIcon(":/icon/time.png");
+    tw->setIconShow(true);
+    tw->setIconSize(16, 16);
+    /* 重新设置大小 */
+    tw->setEditLine(112, 32);
+    /* 设置选择框大小 */
+    tw->setTimeAreaWidth(140);
+    /* 移动位置,覆盖显示时间的按钮,获取的坐标是相对于Dialog的位置 */
+    auto pos = this->mapFromGlobal(pBtnSize);
+    // pos.setX(pos.x() - 1);     /* 去掉阴影的宽度 */
+    // pos.setY(pos.y());     /* 去掉阴影的高度 */
+    tw->move(pos);
+
+    // SPDLOG_LOGGER_DEBUG(m_logger, "移动前位置: {}, {}", pBtnSize.x(), pBtnSize.y());
+    // SPDLOG_LOGGER_DEBUG(m_logger, "移动后位置: {}, {}", pos.x(), pos.y());
+    /* 设置默认的时间 */
+    if(isStartTime)
+    {
+        tw->setTime(plan.timeStart);
+    } else
+    {
+        tw->setTime(plan.timeEnd);
+    }
+
+    tw->execShow();
+    auto time = tw->getTime();
+    /* 判断时间有没有修改 */
+    if(isStartTime)
+    {
+        if(time == plan.timeStart)
+        {
+            return; // 没有修改
+        }
+    } else
+    {
+        if(time == plan.timeEnd)
+        {
+            return; // 没有修改
+        }
+    }
+    SPDLOG_LOGGER_DEBUG(m_logger, "修改时间: {}, {}", time.toString("hh:mm:ss").toStdString(), isStartTime ? "开始时间" : "结束时间");
+    OnePlan_t newPlan = plan;
+    if(isStartTime)
+    {
+        newPlan.timeStart = time;
+    } else
+    {
+        newPlan.timeEnd = time;
+    }
+
+    /* 判断时间是否重复 */
+    updateDetectPlanList(1);
+    if(isWeekPlanDuplicate(m_currentPlanList, newPlan, plan))
+    {
+        /* 设置时间报警 */
+        TipWidget::display(TipWidget::OPERATOR_WARN, "与已有计划冲突,请重新修改", GInfo.getTopWindow());
+        SPDLOG_LOGGER_WARN(m_logger, "检测计划冲突");
+        return;
+    }
+    /* 设置时间 */
+    one->setPlan(newPlan);
+    /* 重新排序 */
+    sortDetectPlanList();
+    
+}
+
+
 /* 初始化QListWidget */
 void CheckPeriodWidget::initListWidget()
 {
-    ui->listWidget_detectPlan->clear();
+
     ui->listWidget_noDetectPlan->clear();
 
     /* 禁用横向滚动条 */
-    ui->listWidget_detectPlan->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    ui->listWidget_noDetectPlan->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    
 
     /* 设置行间距为16 */
-    ui->listWidget_detectPlan->setSpacing(8);
-    ui->listWidget_noDetectPlan->setSpacing(8);
 
-    /* 添加检测计划 */
-    // for (int i = 0; i < 8; ++i) {
-    //     OnePlan_t plan;
-    //     addDetectPlan(plan);
-    // }
 
 }
 
 /* 添加一个检测计划 */
 void CheckPeriodWidget::addDetectPlan(const OnePlan_t& plan)
 {
-    OneDetectPlan *detectPlan = new OneDetectPlan(ui->listWidget_detectPlan);
+    OneDetectPlan *detectPlan = new OneDetectPlan(eWeekType::Week_Monday, this);
+    /* 删除日期选择框 */
+    
     detectPlan->setQSS(m_qssPlan);
     detectPlan->setPlan(plan);
 
-    connect(detectPlan, &OneDetectPlan::signal_oneDetectPlanCloseClicked,
-            this, &CheckPeriodWidget::do_pBtn_deleteDetectPlan_clicked);
+    connect(detectPlan, &OneDetectPlan::signal_oneDetectPlanCloseClicked, this, &CheckPeriodWidget::do_pBtn_deleteDetectPlan_clicked);
+    connect(detectPlan, &OneDetectPlan::signal_planModifiedWeek, this, &CheckPeriodWidget::do_detectPlanModifiedWeek);
+    connect(detectPlan, &OneDetectPlan::signal_timeButtonClicked, this, &CheckPeriodWidget::do_detectPlanModifiedTime);
+
+    /* 将数据插入到列表中,在排序的时候会将新增加的插入到里面 */
+    m_pListcurrDetect->append(detectPlan);
+
+    /* 排序 */
+    sortDetectPlanList();
+}
+
+
+/* 重新排序检测计划 */
+void CheckPeriodWidget::sortDetectPlanList()
+{
+    /* 清空列表 */
+    removeAllDetectPlanWidgets();
+    
+    /* 排序 */
+    std::sort(m_pListcurrDetect->begin(), m_pListcurrDetect->end(), [](OneDetectPlan *a, OneDetectPlan *b) 
+    {
+        const OnePlan_t &planA = a->getPlan();
+        const OnePlan_t &planB = b->getPlan();
+        /* 按时间从小到大升序 */
+        return weekTimeIsGerater(planB.weekType, planB.timeStart, planA.weekType, planA.timeStart);
+    });
+
 
-    /* 将数据插入到列表中 */
-    QListWidgetItem *item = new QListWidgetItem(ui->listWidget_detectPlan);
-    item->setSizeHint(detectPlan->sizeHint());
-    ui->listWidget_detectPlan->setItemWidget(item, detectPlan);
+    /* 重新插入 */
+    addDetectPlanToLayout();
 }
+
+
+/* 获取计划列表 */
+QList<OnePlan_t> CheckPeriodWidget::updateDetectPlanList(int id)
+{
+    m_currentPlanList.clear();
+    
+    for(auto& pDetect : *m_pListcurrDetect)
+    {
+        OnePlan_t plan = pDetect->getPlan();
+        m_currentPlanList.append(plan);
+    }
+
+    return m_currentPlanList;
+}
+
+/* 清空当前检测计划布局中的控件 */
+void CheckPeriodWidget::removeAllDetectPlanWidgets()
+{
+    /* 清空布局中的所有控件,只剩一个弹簧 */
+    // for(auto& pDetect : *m_pListcurrDetect)
+    // {
+    //     m_layoutDetectPlans->removeWidget(pDetect);
+    // }
+    while (m_layoutDetectPlans->count() > 1)
+    {
+        QWidget *widget = m_layoutDetectPlans->itemAt(0)->widget();
+        if(widget)
+        {
+            m_layoutDetectPlans->removeWidget(widget);
+            widget->hide();
+        }
+    
+    }
+    update();
+}
+
+/* 从当前列表中添加控件到布局 */
+void CheckPeriodWidget::addDetectPlanToLayout()
+{
+    for(auto& pDetect : *m_pListcurrDetect)
+    {
+        pDetect->show();
+        /* 添加到布局中 */
+        m_layoutDetectPlans->insertWidget(m_layoutDetectPlans->count() - 1, pDetect);
+    }
+}
+
+

+ 30 - 5
SettingLibrary/Modules/CheckPeriod/checkperiodwidget.h

@@ -2,10 +2,14 @@
 #define CHECKPERIODWIDGET_H
 
 #include <QWidget>
+#include <QVBoxLayout>
+#include <qboxlayout.h>
+#include <QMap>
+
 #include "spdlog/spdlog.h"
 #include "GlobalVariable.h"
 #include "onedetectplan.h"
-
+#include "CompareItemData.h"
 
 
 
@@ -28,12 +32,14 @@ public:
     explicit CheckPeriodWidget(QWidget *parent = nullptr);
     ~CheckPeriodWidget();
 
-    /* 获取计划列表 */
-    QList<OnePlan_t> getDetectPlanList();
+    /* 更新可选的对比项列表 */
+    void updateCompareItemList(const QList<CompareItemInfo_t>& compareItemList);
     /* 设置计划列表 */
     void setDetectPlanList(const QList<OnePlan_t>& planList);
 
 private slots:
+    /* 选择了一个对比项 */
+    void do_comboBox_selectCompareItem_currentIndexChanged(int index);
     /* 添加一个检测计划 */
     void do_pBtn_addDetectPlan_clicked();
     /* 添加一个不检测计划 */
@@ -44,19 +50,38 @@ private slots:
     /* 删除一个不检测计划 */
     void do_pBtn_deleteNoDetectPlan_clicked();
 
+    /* 修改了日期或周几,检测是否冲突 */
+    void do_detectPlanModifiedWeek(OnePlan_t formerPlan, OnePlan_t newPlan);
+    /* 点击了检测计划的时间按钮,在这里修改时间 */
+    void do_detectPlanModifiedTime(QPoint pBtnSize, bool isStartTime);
+
+
 private:
     /* 初始化QListWidget */
     void initListWidget();
     /* 添加一个检测计划 */
     void addDetectPlan(const OnePlan_t& plan);
+    /* 重新排序检测计划 */
+    void sortDetectPlanList();
+    /* 更新当前的检测计划列表 */
+    QList<OnePlan_t> updateDetectPlanList(int id);
+    /* 清空当前检测计划布局中的控件 */
+    void removeAllDetectPlanWidgets();
+    /* 从当前列表中添加控件到布局 */
+    void addDetectPlanToLayout();
+
 
 private:
     Ui::CheckPeriodWidget *ui;
     std::shared_ptr<spdlog::logger> m_logger = nullptr;
+    QVBoxLayout* m_layoutDetectPlans;                   /* 检测计划的布局,计划控件都在这里面 */
+    QString m_qssPlan;                                  /* 一条计划的样式表 */
 
-    QString m_qssPlan;          /* 一条计划的样式表 */
-    QList<OnePlan_t> m_planList; /* 检测计划列表 */
+    QList<OnePlan_t> m_currentPlanList;                 /* 当前的计划列表 */
+    QList<OneDetectPlan*>* m_pListcurrDetect = nullptr; /* 当前的检测计划列表 */
+    QMap<int, QList<OneDetectPlan*>*> m_mapDetectPlanList;   /* 检测计划列表,key为对比项id,value为计划列表 */
 
+    
 
 };
 

+ 45 - 1
SettingLibrary/Modules/CheckPeriod/checkperiodwidget.ui

@@ -168,7 +168,51 @@
        </layout>
       </item>
       <item>
-       <widget class="QListWidget" name="listWidget_detectPlan"/>
+       <widget class="QScrollArea" name="scrollArea">
+        <property name="widgetResizable">
+         <bool>true</bool>
+        </property>
+        <widget class="QWidget" name="scrollArea_detectPlans">
+         <property name="geometry">
+          <rect>
+           <x>0</x>
+           <y>0</y>
+           <width>358</width>
+           <height>220</height>
+          </rect>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout_5">
+          <property name="spacing">
+           <number>16</number>
+          </property>
+          <property name="leftMargin">
+           <number>0</number>
+          </property>
+          <property name="topMargin">
+           <number>0</number>
+          </property>
+          <property name="rightMargin">
+           <number>0</number>
+          </property>
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item>
+           <spacer name="verticalSpacer">
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>20</width>
+              <height>217</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </widget>
+       </widget>
       </item>
      </layout>
     </widget>

+ 64 - 36
SettingLibrary/Modules/CheckPeriod/onedetectplan.cpp

@@ -4,36 +4,43 @@
 #include "timewidget.h"
 #include "customcombobox.h"
 #include "GlobalVariable.h"
+#include <qpoint.h>
+#include <qpushbutton.h>
+#include <qsize.h>
 
 
-OneDetectPlan::OneDetectPlan(QWidget *parent) :
+OneDetectPlan::OneDetectPlan(eWeekType type, QWidget *parent) :
     QWidget(parent),
-    ui(new Ui::OneDetectPlan)
+    ui(new Ui::OneDetectPlan), m_type(type)
 {
     ui->setupUi(this);
 
+    if(m_type == eWeekType::Week_Special)
+    {
+        ui->dateEdit->setVisible(true);
+        /* 特殊日不显示下拉框 */
+        ui->comboBox->hide();
+        /* 将下拉框从布局中移除 */
+        // this->layout()->removeWidget(ui->comboBox);
+    } else
+    {
+        ui->comboBox->setVisible(true);
+        ui->dateEdit->hide();
+        /* 将日期选择框从布局中移除 */
+        // this->layout()->removeWidget(ui->dateEdit);
+    }
 
     /* 设置下拉框阴影 */
     ui->comboBox->setViewShadowEffect();
     /* 设置时间框默认时间 */
-    // ui->timeEdit_start->setDefaultStyle();
-    // ui->timeEdit_end->setDefaultStyle();
-    ui->timeEdit_start->setTime(QTime(0, 0, 0));
-    ui->timeEdit_end->setTime(QTime(23, 59, 59));
+    m_timeStart = QTime(0, 0, 0);
+    m_timeEnd = QTime(23, 59, 59);
+    ui->pBtn_timeStart->setText(m_timeStart.toString("hh:mm:ss"));
+    ui->pBtn_timeEnd->setText(m_timeEnd.toString("hh:mm:ss"));
 
     /* 禁用comboBox滚动修改 */
     ui->comboBox->setWheelDisabled(true);
 
-    /* 禁用QTimeEdit滚轮编辑 */
-    ui->timeEdit_start->setWheelDisabled(true);
-    ui->timeEdit_end->setWheelDisabled(true);
-
-    ui->timeEdit_start->SetMainWindow(parent->window());
-    ui->timeEdit_end->SetMainWindow(parent->window());
-
-    /* 禁止使用时间图标清空时间 */
-    ui->timeEdit_start->setDisableClear(true);
-    ui->timeEdit_end->setDisableClear(true);
 
     /* 给下拉框设置可选项 */
     for(auto it = MapWeekTypeToString.begin(); it != MapWeekTypeToString.end(); ++it)
@@ -46,10 +53,14 @@ OneDetectPlan::OneDetectPlan(QWidget *parent) :
     }
 
     /* 连接信号和槽 */
-    connect(ui->timeEdit_start, &TimeWidget::signal_formerTimer, this, &OneDetectPlan::do_formerTime);
-    connect(ui->timeEdit_start, &TimeWidget::signal_nowTime, this, &OneDetectPlan::do_afterTime);
     connect(ui->pBtn_close, &QPushButton::clicked, this, &OneDetectPlan::signal_oneDetectPlanCloseClicked);
 
+    connect(ui->pBtn_timeStart, &QPushButton::clicked, this, &OneDetectPlan::do_timeButtonClicked);
+    connect(ui->pBtn_timeStartIcon, &QPushButton::clicked, this, &OneDetectPlan::do_timeButtonClicked);
+    connect(ui->pBtn_timeEnd, &QPushButton::clicked, this, &OneDetectPlan::do_timeButtonClicked);
+    connect(ui->pBtn_timeEndIcon, &QPushButton::clicked, this, &OneDetectPlan::do_timeButtonClicked);
+    connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &OneDetectPlan::do_comboBox_currentIndexChanged);
+
 }
 
 OneDetectPlan::~OneDetectPlan()
@@ -79,39 +90,56 @@ void OneDetectPlan::setPlan(const OnePlan_t &plan)
     /* 设置周几 */
     ui->comboBox->setCurrentText(MapWeekTypeToString.value(plan.weekType));
     /* 设置日期 */
-    ui->timeEdit_start->setTime(plan.timeStart);
-    ui->timeEdit_end->setTime(plan.timeEnd);
+    m_timeStart = plan.timeStart;
+    m_timeEnd = plan.timeEnd;
+    ui->pBtn_timeStart->setText(m_timeStart.toString("hh:mm:ss"));
+    ui->pBtn_timeEnd->setText(m_timeEnd.toString("hh:mm:ss"));
 }
 
 /* 获取计划 */
-OnePlan_t OneDetectPlan::getPlan()
+const OnePlan_t& OneDetectPlan::getPlan()
 {
     /* 更新计划 */
     m_plan.weekType = ui->comboBox->currentData().value<eWeekType>();
-    m_plan.timeStart = ui->timeEdit_start->getTime();
-    m_plan.timeEnd = ui->timeEdit_end->getTime();
+    m_plan.timeStart = m_timeStart;
+    m_plan.timeEnd = m_timeEnd;
 
     return m_plan;
 }
 
-/* 修改前的时间 */
-void OneDetectPlan::do_formerTime(const QTime &time)
+
+/* 修改了周几 */
+void OneDetectPlan::do_comboBox_currentIndexChanged(int index)
 {
-    if(sender() == ui->timeEdit_start)
+    /* 获取当前的计划 */
+    OnePlan_t formerPlan = m_plan;
+    getPlan(); // 更新计划
+    emit signal_planModifiedWeek(formerPlan, m_plan);
+}
+
+/* 点击了时间按钮 */
+void OneDetectPlan::do_timeButtonClicked()
+{
+    /* 获取按钮 */
+    QPushButton *pBtn = qobject_cast<QPushButton*>(sender());
+    if(!pBtn)
     {
-        m_startFormerTime = time;
+        return;
     }
-    else if(sender() == ui->timeEdit_end)
+    /* 获取按钮位置和开始结束时间标志 */
+    QPoint pBtnSize;
+    bool isStartTime = false;
+    if(pBtn == ui->pBtn_timeStart || pBtn == ui->pBtn_timeStartIcon)
     {
-        m_endFormerTime = time;
+        pBtnSize = ui->widget_timeStart->mapToGlobal(QPoint(0, 0));
+        isStartTime = true;
+    }
+    else if(pBtn == ui->pBtn_timeEnd || pBtn == ui->pBtn_timeEndIcon)
+    {
+        pBtnSize = ui->widget_timeEnd->mapToGlobal(QPoint(0, 0));
+        isStartTime = false;
     }
-}
 
-/* 修改后的计划时间 */
-void OneDetectPlan::do_afterTime(const QTime &time)
-{
-    OnePlan_t formerPlan = m_plan;
-    getPlan(); // 更新计划
-    emit signal_planModified(formerPlan, m_plan);
+    emit signal_timeButtonClicked(pBtnSize, isStartTime);
 }
 

+ 14 - 12
SettingLibrary/Modules/CheckPeriod/onedetectplan.h

@@ -22,7 +22,7 @@ class OneDetectPlan : public QWidget
     Q_OBJECT
 
 public:
-    explicit OneDetectPlan(QWidget *parent = nullptr);
+    explicit OneDetectPlan(eWeekType type, QWidget *parent = nullptr);
     ~OneDetectPlan();
 
     /* 设置QSS */
@@ -30,28 +30,30 @@ public:
     /* 设置计划 */
     void setPlan(const OnePlan_t &plan);
     /* 获取计划 */
-    OnePlan_t getPlan();
+    const OnePlan_t& getPlan();
 
 signals:
-    /* 计划被修改,重新排序 */
-    void signal_planModified();
     /* 点击了关闭按钮 */
     void signal_oneDetectPlanCloseClicked();
-    /* 修改了时间 */
-    void signal_planModified(OnePlan_t formerPlan, OnePlan_t newPlan);
+    /* 修改了周几,在外面判断是否冲突,并排序 */
+    void signal_planModifiedWeek(OnePlan_t formerPlan, OnePlan_t newPlan);
+    /* 点击了时间按钮,在外面修改时间,附带点击的按钮位置 */
+    void signal_timeButtonClicked(QPoint pBtnSize, bool isStartTime);
 
 private slots:
-    /* 修改前的时间 */
-    void do_formerTime(const QTime &time);
-    /* 修改后的时间 */
-    void do_afterTime(const QTime &time);
+    /* 修改了周几 */
+    void do_comboBox_currentIndexChanged(int index);
+    /* 点击了时间按钮 */
+    void do_timeButtonClicked();
 
 private:
     Ui::OneDetectPlan *ui;
 
+    eWeekType m_type;           /* 周几 */
+
     OnePlan_t m_plan;           /* 一条计划 */
-    QTime m_startFormerTime;    /* 修改前的开始时间 */
-    QTime m_endFormerTime;      /* 修改前的结束时间 */
+    QTime m_timeStart;          /* 开始时间 */
+    QTime m_timeEnd;            /* 结束时间 */
 
 };
 

+ 108 - 17
SettingLibrary/Modules/CheckPeriod/onedetectplan.ui

@@ -12,13 +12,13 @@
   </property>
   <property name="minimumSize">
    <size>
-    <width>352</width>
+    <width>344</width>
     <height>32</height>
    </size>
   </property>
   <property name="maximumSize">
    <size>
-    <width>352</width>
+    <width>16777215</width>
     <height>16777215</height>
    </size>
   </property>
@@ -27,7 +27,7 @@
   </property>
   <layout class="QHBoxLayout" name="horizontalLayout">
    <property name="spacing">
-    <number>6</number>
+    <number>4</number>
    </property>
    <property name="leftMargin">
     <number>0</number>
@@ -42,36 +42,106 @@
     <number>0</number>
    </property>
    <item>
-    <widget class="CustomComboBox" name="comboBox">
+    <widget class="QWidget" name="widget" native="true">
      <property name="minimumSize">
       <size>
-       <width>82</width>
+       <width>104</width>
        <height>32</height>
       </size>
      </property>
+     <widget class="CustomComboBox" name="comboBox">
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>112</width>
+        <height>32</height>
+       </rect>
+      </property>
+      <property name="minimumSize">
+       <size>
+        <width>104</width>
+        <height>32</height>
+       </size>
+      </property>
+      <property name="maximumSize">
+       <size>
+        <width>112</width>
+        <height>32</height>
+       </size>
+      </property>
+     </widget>
+     <widget class="QDateEdit" name="dateEdit">
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>112</width>
+        <height>32</height>
+       </rect>
+      </property>
+      <property name="minimumSize">
+       <size>
+        <width>104</width>
+        <height>32</height>
+       </size>
+      </property>
+      <property name="maximumSize">
+       <size>
+        <width>112</width>
+        <height>32</height>
+       </size>
+      </property>
+     </widget>
     </widget>
    </item>
    <item>
-    <widget class="TimeWidget" name="timeEdit_start">
+    <widget class="QWidget" name="widget_timeStart" native="true">
      <property name="minimumSize">
       <size>
-       <width>106</width>
+       <width>94</width>
        <height>32</height>
       </size>
      </property>
      <property name="maximumSize">
       <size>
        <width>94</width>
-       <height>16777215</height>
+       <height>32</height>
       </size>
      </property>
+     <widget class="QPushButton" name="pBtn_timeStart">
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>94</width>
+        <height>32</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="pBtn_timeStartIcon">
+      <property name="geometry">
+       <rect>
+        <x>70</x>
+        <y>8</y>
+        <width>16</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+     </widget>
     </widget>
    </item>
    <item>
     <widget class="QLabel" name="label">
      <property name="minimumSize">
       <size>
-       <width>8</width>
+       <width>4</width>
        <height>32</height>
       </size>
      </property>
@@ -87,19 +157,45 @@
     </widget>
    </item>
    <item>
-    <widget class="TimeWidget" name="timeEdit_end">
+    <widget class="QWidget" name="widget_timeEnd" native="true">
      <property name="minimumSize">
       <size>
-       <width>106</width>
+       <width>94</width>
        <height>32</height>
       </size>
      </property>
      <property name="maximumSize">
       <size>
        <width>94</width>
-       <height>16777215</height>
+       <height>32</height>
       </size>
      </property>
+     <widget class="QPushButton" name="pBtn_timeEnd">
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>94</width>
+        <height>32</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="pBtn_timeEndIcon">
+      <property name="geometry">
+       <rect>
+        <x>70</x>
+        <y>8</y>
+        <width>16</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+     </widget>
     </widget>
    </item>
    <item>
@@ -129,11 +225,6 @@
    <extends>QComboBox</extends>
    <header location="global">customcombobox.h</header>
   </customwidget>
-  <customwidget>
-   <class>TimeWidget</class>
-   <extends>QTimeEdit</extends>
-   <header location="global">timewidget.h</header>
-  </customwidget>
  </customwidgets>
  <resources/>
  <connections/>

+ 2 - 0
SettingLibrary/Resources/Resources.qrc

@@ -12,6 +12,8 @@
         <file>icon/onswitch.png</file>
         <file>icon/down_arrow.png</file>
         <file>icon/tip.png</file>
+        <file>icon/time.png</file>
+        <file>icon/Date.png</file>
         <file>Tip/Wait2x.png</file>
         <file>Tip/Tips2x.png</file>
         <file>Tip/Failed2x.png</file>

BIN=BIN
SettingLibrary/Resources/icon/Date.png


BIN=BIN
SettingLibrary/Resources/icon/date_dark.png


BIN=BIN
SettingLibrary/Resources/icon/date_light.png


BIN=BIN
SettingLibrary/Resources/icon/time.png


+ 32 - 8
SettingLibrary/Resources/qss/white/addperiodwidget.qss

@@ -19,23 +19,47 @@ TimeWidget:hover
 	border: 1px solid #4458FE;
 }
 
+
+
 /* ==========================================================
- *  DateWidget
+ *  日期选择器
  * ========================================================== */
+
 CalendarDTEdit
 {
 	background: #FFFFFF;
-	border-radius: 4px;
-	border: 1px solid #E6E9F4;
-	padding-left: 12px;
-	font-weight: 400;
-	font-size: 14px;
-	color: #3A3F63;
+    border-radius: 4px;
+    padding-left:12px;
+    border: 1px solid #E6E9F4;
 }
 
 CalendarDTEdit:hover
 {
-	border: 1px solid #4458FE;
+	background: #FFFFFF;
+    border-radius: 4px;
+    padding-left:12px;
+    border: 1px solid #4458FE;
+}
+
+CalendarDTEdit[Warn=true]
+{
+	background: #FFFFFF;
+    border-radius: 4px;
+    padding-left:12px;
+    border: 1px solid #D21F21;
+}
+
+CalendarDTEdit:!enabled/* 或者disable */
+{
+    background: rgba(0,0,0,0.04);
+    border: 1px solid #E6E9F4;
+}
+
+CalendarDTEdit::drop-down
+{
+ 	padding-right:8px;
+	width: 16px;
+    image: url(:/icon/Date.png);
 }
 
 

+ 47 - 0
SettingLibrary/Resources/qss/white/checkperiodwidget.qss

@@ -327,4 +327,51 @@ QListWidget QScrollBar::sub-line::vertical
 }
 
 
+/* ==========================================================
+ *  QScrollArea
+ * ========================================================== */
+QScrollArea, QWidget#scrollArea_detectPlans 
+{
+    background: #FFFFFF !important;
+    border: none;
+}
+
+QScrollBar:vertical
+{
+    width: 6px;
+	border:none;
+    background: transparent;
+    margin-right: 0px;
+}
+QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical
+{
+	background: transparent;
+	border: none;
+}
+QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical
+{
+	background: transparent;
+}
+QScrollBar::handle:vertical
+{
+    background: #E2E2E2;
+    border-radius: 1px;
+	margin-right: 1px;
+	margin-left: 1px;
+}
+QScrollBar::handle:vertical:hover
+{
+	background: rgb(234, 234, 234);
+	margin-right: 0px;
+	margin-left: 0px;
+	border-radius: 2px;
+}
+QScrollBar::handle:vertical:pressed
+{
+	background: rgb(234, 234, 234);
+	margin-right: 0px;
+	margin-left: 0px;
+	border-radius: 2px;
+}
+
 

+ 34 - 0
SettingLibrary/Resources/qss/white/onedetectplan.qss

@@ -1,5 +1,8 @@
 
 
+/* ==========================================================
+ *  QPushButton
+ * ========================================================== */
 QPushButton#pBtn_close
 {
 	border-image: url(:/icon/del.png);
@@ -10,6 +13,35 @@ QPushButton#pBtn_close:hover
 }
 
 
+QPushButton#pBtn_timeStart, #pBtn_timeEnd
+{
+    text-align: left; 
+	background: #FFFFFF;
+	border-radius: 4px;
+	border: 1px solid #E6E9F4;
+	padding-left: 12px;
+	font-weight: 400;
+	font-size: 14px;
+	color: #3A3F63;
+}
+
+QPushButton#pBtn_timeStart:hover, #pBtn_timeEnd:hover
+{
+	border: 1px solid #4458FE;
+}
+
+QPushButton#pBtn_timeStartIcon, #pBtn_timeEndIcon
+{
+	border-image: url(:/icon/time.png);
+}
+/* QPushButton#pBtn_timeStartIcon:hover, #pBtn_timeEndIcon:hover
+{
+	border-image: url(:/icon/time.png);
+} */
+
+
+
+
 /* ==========================================================
  *  TimeWidget
  * ========================================================== */
@@ -140,3 +172,5 @@ QComboBox QScrollBar::sub-line::vertical
 }
 
 
+
+

+ 39 - 0
SettingLibrary/setinfowidget.cpp

@@ -1,4 +1,5 @@
 #include "setinfowidget.h"
+#include "CompareItemData.h"
 #include "ui_setinfowidget.h"
 
 
@@ -16,6 +17,7 @@ SetInfoWidget::SetInfoWidget(QWidget *parent) :
     /* 连接信号和槽 */
     connect(ui->pBtn_save, &QPushButton::clicked, this, &SetInfoWidget::do_pBtn_save_clicked);
     connect(ui->pBtn_cancel, &QPushButton::clicked, this, &SetInfoWidget::do_pBtn_cancel_clicked);
+    connect(ui->tabWidget, &QTabWidget::currentChanged, this, &SetInfoWidget::do_tabWidget_currentChanged);
 
     /* 设置样式表 */
     UIStyle.registerWidget(this);
@@ -72,6 +74,43 @@ void SetInfoWidget::do_pBtn_cancel_clicked()
 
 }
 
+/* 切换了页面 */
+void SetInfoWidget::do_tabWidget_currentChanged(int index)
+{
+    /* 获取当前页的编号 */
+    QWidget* currentWidget = ui->tabWidget->currentWidget();
+    if(currentWidget == nullptr)
+    {
+        return;
+    }
+
+    /* 根据当前页的编号执行不同的操作 */
+    switch(index)
+    {
+        case 0: // 基础信息
+            break;
+        case 1: // 对比项
+            break;
+        case 2: // 噪音检测
+            break;
+        case 3: // 数据库
+            break;
+        case 4: // 检测时段
+            {
+                /* 设置对比项到可选列表中 */
+                CheckPeriodWidget* checkPeriodWidget = qobject_cast<CheckPeriodWidget*>(currentWidget);
+                if(checkPeriodWidget)
+                {
+                    checkPeriodWidget->updateCompareItemList(CIData.getCompareItemList());
+                }
+
+            }
+            break;
+        default:
+            break;
+    }
+}
+
 /* 保存数据 */
 void SetInfoWidget::saveData()
 {

+ 4 - 0
SettingLibrary/setinfowidget.h

@@ -28,11 +28,15 @@ private slots:
     /* 取消按钮 */
     void do_pBtn_cancel_clicked();
 
+    /* 切换了页面 */
+    void do_tabWidget_currentChanged(int index);
+
 private:
     /* 保存数据 */
     void saveData();
 
 
+
 private:
     Ui::SetInfoWidget *ui;
 

+ 7 - 7
show1/main.cpp

@@ -37,9 +37,9 @@ void addFont()
 {
     QString fontPath = QApplication::applicationDirPath() + "/font/SiYuanBlack_ttf";
     /* 加载字体 */
-    int id1 = QFontDatabase::addApplicationFont(fontPath + "/SiYuanBlack_Bold.ttf)");
-    int id2 = QFontDatabase::addApplicationFont(fontPath + "/SiYuanBlack_M.ttf)");
-    int id3 = QFontDatabase::addApplicationFont(fontPath + "/SiYuanBlack_R.ttf)");
+    int id1 = QFontDatabase::addApplicationFont(fontPath + "/SiYuanBlack_Bold.ttf");
+    int id2 = QFontDatabase::addApplicationFont(fontPath + "/SiYuanBlack_M.ttf");
+    int id3 = QFontDatabase::addApplicationFont(fontPath + "/SiYuanBlack_R.ttf");
     /***************************************************
      * 字体使用方式
      * id1 ("思源黑体-粗")
@@ -47,11 +47,11 @@ void addFont()
      * id3 ("思源黑体R")
     ****************************************************/
        SPDLOG_INFO("{}", fontPath.toStdString());
-       qDebug() << "id1" << QFontDatabase::applicationFontFamilies(id1);
-       qDebug() << "id2" << QFontDatabase::applicationFontFamilies(id2);
-       qDebug() << "id3" << QFontDatabase::applicationFontFamilies(id3);
+       qDebug() << "id1" << id1 << ", " << QFontDatabase::applicationFontFamilies(id1);
+       qDebug() << "id2" << id2 << ", " << QFontDatabase::applicationFontFamilies(id2);
+       qDebug() << "id3" << id3 << ", " << QFontDatabase::applicationFontFamilies(id3);
     QFont font_main;
-    font_main.setFamily("思源黑体R");
+    font_main.setFamily(QFontDatabase::applicationFontFamilies(id3).at(0));
     font_main.setPixelSize(14);
     QApplication::setFont(font_main);
 }