Browse Source

V1.2.5
1、修复了一些设置动态库的bug

Apple 3 weeks ago
parent
commit
3f400f1383

+ 2 - 0
SettingLibrary/CMakeLists.txt

@@ -38,6 +38,7 @@ file(GLOB LOCAL_SRC
     ${CMAKE_CURRENT_SOURCE_DIR}/Resources/*.qrc
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/AICompare/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Basic/*.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Basic/TableHeader/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod/CPushButtonTime/*.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Database/*.cpp
@@ -103,6 +104,7 @@ target_include_directories(${libName} PRIVATE
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/AICompare
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Basic
+    ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Basic/TableHeader
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CheckPeriod/CPushButtonTime
     ${CMAKE_CURRENT_SOURCE_DIR}/Modules/Database

+ 146 - 0
SettingLibrary/Modules/Basic/TableHeader/baseheader.cpp

@@ -0,0 +1,146 @@
+#include "baseheader.h"
+#include "PaintHelper/painthelper.h"
+#include <QDebug>
+#include <QApplication>
+
+BaseHeader::BaseHeader(QWidget *parent, Qt::Orientation orientation, Qt::Alignment flags)
+    : QHeaderView(orientation, parent)
+    , m_alignmentText(flags)
+    , m_nCurSortedIndex(-1)
+    , m_bSortable(false)
+    , m_stateCurSorted(Disable)
+    , m_bCheckable(false)
+    , m_checkState(Qt::Unchecked)
+{
+    connect(this, &QHeaderView::sectionClicked, this, &BaseHeader::OnSectionClicked);
+}
+
+void BaseHeader::SetTextAlignment(Qt::Alignment flags)
+{
+    m_alignmentText = flags;
+}
+
+void BaseHeader::SetSortable(bool value, const QList<int> &notSortList)
+{
+    m_bSortable = value;
+    setSectionsClickable(value);
+    m_listSortDisable = notSortList;
+}
+
+void BaseHeader::SetCheckable(bool value)
+{
+    m_bCheckable = value;
+    setSectionsClickable(value);
+}
+
+void BaseHeader::SetChecked(Qt::CheckState state)
+{
+    m_checkState = state;
+    updateSection(0);
+}
+
+QString BaseHeader::GetText(int logicalIndex)
+{
+    return model()->headerData(logicalIndex, orientation()).toString();
+}
+
+void BaseHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
+{
+    //颜色
+    // QColor colorBG = QColor(70, 70, 73);
+    QColor colorBG = QColor(255, 255, 255);
+    QColor colorBorder = QColor(255, 255, 255, 38);
+    // QColor colorText = QColor(210, 210, 210);
+    QColor colorText = QColor("#3A3F63");
+
+    //背景
+    PainterEx *painterEx = static_cast<PainterEx*>(painter);
+    painterEx->SetBrushOnly(colorBG);
+    painterEx->drawRect(rect);
+    
+    //顶部横线
+    painterEx->DrawBorder(rect, colorBorder, PainterEx::RectBorderTop);
+
+    //文本
+    FontEx font(qApp->font().family(), 14, false);
+    QFontMetrics fontMetrics(font);
+    QString headerText = model()->headerData(logicalIndex, orientation()).toString();
+    QString text = fontMetrics.elidedText(headerText, Qt::ElideRight, rect.width()-16);
+    painterEx->setFont(font);
+    bool isCheckableCol = (m_bCheckable && logicalIndex == 0);
+    QRect textRect = rect.adjusted((isCheckableCol?44:0),0,0,0);
+    if(!isCheckableCol && logicalIndex == 0)
+    {
+        textRect = rect.adjusted(12,0,0,0);
+    }
+    painterEx->DrawText(textRect, text, colorText, m_alignmentText);
+    
+    //底部横线
+    painterEx->DrawBorder(rect, colorBorder, PainterEx::RectBorderBottom);
+    
+    //排序图标
+    if(m_bSortable && !m_listSortDisable.contains(logicalIndex))
+    {
+        QColor upColor = (m_nCurSortedIndex == logicalIndex && m_stateCurSorted == Asc)?QColor(133,142,189,200):QColor(133,142,189,80);
+        QColor downColor = (m_nCurSortedIndex == logicalIndex && m_stateCurSorted == Desc)?QColor(133,142,189,200):QColor(133,142,189,80);
+        QSize textSize = fontMetrics.size(Qt::TextSingleLine, text);
+        int xPos = textRect.left() + textSize.width() + 6;
+        int yPos = rect.top() + (rect.height() - fontMetrics.capHeight())/2 + 1;
+        
+        painterEx->DrawTriangle(QRect(xPos, yPos, 10, 5), true, upColor);
+        painterEx->DrawTriangle(QRect(xPos, yPos+7, 10, 5), false, downColor);
+    }
+
+    //checkbox图标
+    if(m_bCheckable && logicalIndex == 0)
+    {
+        painterEx->save();
+        QRect target(rect.left()+12, rect.top()+(rect.height()-16)/2, 20, 20);
+        painterEx->DrawPixmap(target, GetCheckboxImage(m_checkState));
+        painterEx->restore();
+    }
+}
+
+void BaseHeader::OnSectionClicked(int logicalIndex)
+{
+    if(m_bSortable && !m_listSortDisable.contains(logicalIndex))
+    {
+        if(m_nCurSortedIndex == logicalIndex)
+        {
+            int state = m_stateCurSorted;
+            state = (state + 1)%3;
+            m_stateCurSorted = SortState(state);
+            emit sig_Sorted(logicalIndex, m_stateCurSorted);
+        }
+        else
+        {
+            m_nCurSortedIndex = logicalIndex;
+            m_stateCurSorted = Asc;
+            emit sig_Sorted(logicalIndex, Asc);
+        }
+    }
+    
+    if(m_bCheckable && logicalIndex == 0)
+    {
+        m_checkState = (m_checkState != Qt::Checked)?(Qt::Checked):(Qt::Unchecked);
+        emit sig_Checked(m_checkState == Qt::Checked);
+    }
+    updateSection(logicalIndex);
+}
+
+QString BaseHeader::GetCheckboxImage(Qt::CheckState state) const
+{
+    if(state == Qt::Unchecked)
+    {
+        return ":/icon/unchecked.png";
+    }
+    else if(state == Qt::PartiallyChecked)
+    {
+        return ":/icon/partially_checked.png";
+    }
+    else if(state == Qt::Checked)
+    {
+        return ":/icon/checked.png";
+    }
+    return "";
+}

+ 47 - 0
SettingLibrary/Modules/Basic/TableHeader/baseheader.h

@@ -0,0 +1,47 @@
+#ifndef GGBASEHEADER_H
+#define GGBASEHEADER_H
+
+#include <QWidget>
+#include <QHeaderView>
+
+class BaseHeader : public QHeaderView
+{
+    Q_OBJECT
+public:
+    enum SortState
+    {
+        Disable = -1,
+        NotSort = 0,
+        Asc     = 1,
+        Desc    = 2
+    };
+
+public:
+    explicit BaseHeader(QWidget *parent = nullptr, Qt::Orientation orientation = Qt::Horizontal, Qt::Alignment flags = Qt::AlignLeft|Qt::AlignVCenter);
+    void SetTextAlignment(Qt::Alignment flags);
+    void SetSortable(bool value, const QList<int> &notSortList = QList<int>());
+    void SetCheckable(bool value);
+    void SetChecked(Qt::CheckState state);
+    QString GetText(int logicalIndex);//获取表头名称 add by wl 2023-06-26
+protected:
+    void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override;
+
+signals:
+    void sig_Sorted(int logicalIndex, SortState state);
+    void sig_Checked(bool checked);
+private slots:
+    void OnSectionClicked(int logicalIndex);
+private:
+    Qt::Alignment m_alignmentText;
+    int m_nCurSortedIndex;
+    bool m_bSortable;
+    SortState m_stateCurSorted;
+    QList<int> m_listSortDisable;
+    bool m_bCheckable;
+    Qt::CheckState m_checkState;
+    //QList<SortState> m_listStates;
+private:
+    QString GetCheckboxImage(Qt::CheckState state) const;
+};
+
+#endif // GGBASEHEADER_H

+ 58 - 2
SettingLibrary/Modules/Basic/compareitemdialog.cpp

@@ -25,6 +25,9 @@ CompareItemDialog::CompareItemDialog(QWidget *parent)
     /* 对输入做一些限制 */
     setDetectParamInputOnlyNumber();
 
+    /* 限制对比项名称长度 */
+    ui->lineEdit_compareItmName->setMaxLength(15);
+
     /* 设置默认开启 */
     ui->checkBoxMute->setChecked(true);
     ui->checkBoxOverload->setChecked(true);
@@ -39,7 +42,10 @@ CompareItemDialog::CompareItemDialog(QWidget *parent)
     connect(ui->checkBoxMute, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
     connect(ui->checkBoxOverload, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
     connect(ui->checkBoxPhase, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
-
+    
+    /* 连接通道的选择信号 */
+    connect(ui->widget_mainRoad, &SingleCompareRoadWidget::signal_selectRecordRoad, this, &CompareItemDialog::do_selectOneRecordRoad);
+    connect(ui->widget_secondRoad, &SingleCompareRoadWidget::signal_selectRecordRoad, this, &CompareItemDialog::do_selectOneRecordRoad);
 
     /* 设置样式 */
     setQSS();
@@ -93,12 +99,17 @@ void CompareItemDialog::setDefaultParams(const CompareItemInfo_t& item)
     {
         if(road.nCompareRoadNum == 1) // 主通道
         {
+            /* 阻塞这个comBoBox发送信号 */
+            ui->widget_mainRoad->blockSignals(true);
             ui->widget_mainRoad->setSoundCardRoadList(m_soundCardInfo);
+            ui->widget_mainRoad->blockSignals(false);
             ui->widget_mainRoad->setDefaultParams(road);
         }
         else if(road.nCompareRoadNum == 2) // 第二通道
         {
+            ui->widget_secondRoad->blockSignals(true);
             ui->widget_secondRoad->setSoundCardRoadList(m_soundCardInfo);
+            ui->widget_secondRoad->blockSignals(false);
             ui->widget_secondRoad->setDefaultParams(road);
         }
     }
@@ -169,6 +180,49 @@ void CompareItemDialog::do_checkBox_MOP_clicked(bool checked)
     }
 }
 
+
+/* 选择了一个录音通道,判断有没有重复的,有则去掉重复的 */
+void CompareItemDialog::do_selectOneRecordRoad(QString strPCMName)
+{
+    auto sender = qobject_cast<SingleCompareRoadWidget*>(QObject::sender());
+    /* 只在release模式下生效,debug可以设置重复的,方便测试 */
+#if C_RELEASE
+    /* 判断是否重复 */
+    if(sender != ui->widget_mainRoad)
+    {
+        if(ui->widget_mainRoad->getCurrentPCMName() == strPCMName)
+        {
+            // 如果重复,则去掉重复的
+            ui->widget_mainRoad->clearCurrentSelectRecordName();
+        }
+    }
+    
+    if(sender != ui->widget_secondRoad)
+    {
+        if(ui->widget_secondRoad->getCurrentPCMName() == strPCMName)
+        {
+            // 如果重复,则去掉重复的
+            ui->widget_secondRoad->clearCurrentSelectRecordName();
+        }
+    }
+    
+
+    for(auto& it : m_listOtherRoadWgt)
+    {
+        if(it == sender)
+        {
+            continue;
+        }
+        if(it->getCurrentPCMName() == strPCMName)
+        {
+            it->clearCurrentSelectRecordName();
+        }
+    }
+
+#endif
+
+}
+
 /* 设置样式表 */
 void CompareItemDialog::setQSS()
 {
@@ -279,13 +333,15 @@ SingleCompareRoadWidget* CompareItemDialog::addOneRoadWidget(int nIndex, bool bD
         return nullptr;
     }
     SingleCompareRoadWidget *pWgt = new SingleCompareRoadWidget(this);
-    connect(pWgt, &SingleCompareRoadWidget::deleted, this, &CompareItemDialog::do_CompareRoadWgtDeleted);
     pWgt->setIndex(nIndex);
     pWgt->setDelBtnVisible(bDelBtnVisible);
     /* 设置可选通道列表 */
     pWgt->setSoundCardRoadList(m_soundCardInfo);
     pWgt->setQSS(m_qssRecordRoad);
     pLayout->insertWidget(m_listOtherRoadWgt.size(), pWgt);
+
+    connect(pWgt, &SingleCompareRoadWidget::deleted, this, &CompareItemDialog::do_CompareRoadWgtDeleted);
+    connect(pWgt, &SingleCompareRoadWidget::signal_selectRecordRoad, this, &CompareItemDialog::do_selectOneRecordRoad);
     m_listOtherRoadWgt.append(pWgt);
     
     return pWgt;

+ 2 - 1
SettingLibrary/Modules/Basic/compareitemdialog.h

@@ -54,7 +54,8 @@ private slots:
 
     /* 静音、过载、反相检测条件开关 */
     void do_checkBox_MOP_clicked(bool checked);
-    
+    /* 选择了一个录音通道,判断有没有重复的,有则去掉重复的 */
+    void do_selectOneRecordRoad(QString strPCMName);
 
 private:
     /* 设置静音过载反相可编辑 */

+ 5 - 0
SettingLibrary/Modules/Basic/compareitemlistdialog.cpp

@@ -12,6 +12,7 @@
 #include "tipwidget.h"
 #include "warning.h"
 #include "compareitemdetailwidget.h"
+#include "baseheader.h"
 
 
 /* 重载比较函数 */
@@ -335,6 +336,7 @@ void CompareItemListDialog::initTable()
     /* 初始化视图模型 */
     m_model = new QStandardItemModel(this);
     m_model->setColumnCount(5);
+
     /* 设置每一列的标题 */
     m_model->setHeaderData(0, Qt::Horizontal, "序号");
     m_model->setHeaderData(1, Qt::Horizontal, "状态");
@@ -350,6 +352,9 @@ void CompareItemListDialog::initTable()
     ui->tableView->setModel(m_model);
 
     // 设置选择模式为整行选择
+    auto oneHeader = new BaseHeader(ui->tableView);
+    oneHeader->SetCheckable(true);
+    ui->tableView->setHorizontalHeader(oneHeader);
     ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
     ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
 

+ 25 - 0
SettingLibrary/Modules/Basic/singlecompareroadwidget.cpp

@@ -17,7 +17,11 @@ SingleCompareRoadWidget::SingleCompareRoadWidget(QWidget *parent)
     /* 设置comboBox阴影 */
     // ui->comboBox_soundCardNum->setViewShadowEffect();
 
+    /* 通道名称限制10个字 */
+    ui->lineEditRoadName->setMaxLength(10);
+
     connect(ui->btnDel, &QPushButton::clicked, this, [this]{emit deleted(m_nIndex);});
+    connect(ui->comboBox_soundCardNum, QOverload<int>::of(&CustomComboBox::currentIndexChanged), this, &SingleCompareRoadWidget::do_comboBox_soundCardNum_currentIndexChanged);
 }
 
 SingleCompareRoadWidget::~SingleCompareRoadWidget()
@@ -121,6 +125,13 @@ OneSoundCardPCMInfo_t SingleCompareRoadWidget::getSoundCardRoadInfo()
     return pcmInfo;
 }
 
+/* 获取当前PCM通道名称 */
+QString SingleCompareRoadWidget::getCurrentPCMName() const
+{
+    return  ui->comboBox_soundCardNum->currentData().toString();
+}
+
+
 /* 是否开启录音 */
 bool SingleCompareRoadWidget::isRecordEnabled() const
 {
@@ -136,6 +147,12 @@ void SingleCompareRoadWidget::setRoadNameWarn(bool isWarn)
     ui->lineEditRoadName->update();
 }
 
+/* 设置当前录音通道名称 */
+void SingleCompareRoadWidget::clearCurrentSelectRecordName()
+{
+    ui->comboBox_soundCardNum->setCurrentIndex(-1);
+}
+
 /* 设置样式表 */
 void SingleCompareRoadWidget::setQSS(QString strStyle)
 {
@@ -148,4 +165,12 @@ void SingleCompareRoadWidget::setQSS(QString strStyle)
 }
 
 
+/* 选择了一个录音通道 */
+void SingleCompareRoadWidget::do_comboBox_soundCardNum_currentIndexChanged(int nIndex)
+{
+    QString strPCMName = ui->comboBox_soundCardNum->currentData().toString();
+    // SPDLOG_INFO("选择了一个录音通道: {}", strPCMName.toStdString());
+    emit signal_selectRecordRoad(strPCMName);
+}
+
 

+ 11 - 0
SettingLibrary/Modules/Basic/singlecompareroadwidget.h

@@ -37,17 +37,28 @@ public:
     QString getRoadName() const;
     /* 获取声卡录音通道编号 */
     OneSoundCardPCMInfo_t getSoundCardRoadInfo();
+    /* 获取当前PCM通道名称 */
+    QString getCurrentPCMName() const;
     /* 是否开启录音 */
     bool isRecordEnabled() const;
 
     /* 设置通道名称报警 */
     void setRoadNameWarn(bool isWarn);
 
+    /* 设置当前录音通道名称 */
+    void clearCurrentSelectRecordName();
+
     /* 设置样式表 */
     void setQSS(QString strStyle);
 
 signals:
     void deleted(int nIndex);
+    /* 选择了一个录音通道 */
+    void signal_selectRecordRoad(QString strPCMName);
+
+private slots:
+    /* 选择了一个录音通道 */
+    void do_comboBox_soundCardNum_currentIndexChanged(int nIndex);
 
 private:
     Ui::SingleCompareRoadWidget *ui;

+ 1 - 0
SettingLibrary/Resources/Resources.qrc

@@ -2,6 +2,7 @@
     <qresource prefix="/">
         <file>icon/checked.png</file>
         <file>icon/unchecked.png</file>
+        <file>icon/partially_checked.png</file>
         <file>icon/close.png</file>
         <file>icon/close_hover.png</file>
         <file>icon/add.png</file>

BIN
SettingLibrary/Resources/icon/partially_checked.png


+ 3 - 2
SettingLibrary/Resources/qss/white/compareitemlistwidget.qss

@@ -155,8 +155,9 @@ QTableView::item
 
 QTableView::item:selected
 {
-    color: #FFFFFF;
-    background: #bdbbf5;
+    color: #3A3F63;
+    /* background: #bdbbf5; */
+    background: #EEF2FF;
     border-radius: 0px 0px 0px 0px;
     outline: none;
 }