comac_desk_app/PostProcessing/SelectDatatDialog.cpp

135 lines
4.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "SelectDatatDialog.h"
#include <QIcon>
#include <ElaText.h>
#include <QVBoxLayout>
#include <ElaComboBox.h>
#include <ElaScrollArea.h>
#include "Curve2DKeySelcetBar.h"
namespace pst
{
SelectDatatDialog::SelectDatatDialog(QWidget* parent)
: ElaWidget(parent)
, m_variableAxisValue{ nullptr }
, m_keySelectBarList{}
{
setWindowTitle("数据选择");
setWindowIcon(QIcon(":/include/Image/Moon.jpg"));
this->setIsFixedSize(true);
setContentsMargins(0, 0, 0, 0);
this->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
setWindowModality(Qt::ApplicationModal);
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
}
void SelectDatatDialog::setDialogTitle(const QString& title)
{
setWindowTitle(title);
}
QString SelectDatatDialog::getDialogTitle() const
{
return windowTitle();
}
void SelectDatatDialog::setDataList(
const QList<QPair<QString, QList<double>>>& dataList)
{
m_dataList = dataList;
}
QList<QPair<QString, QList<double>>>
SelectDatatDialog::getDataList() const
{
return m_dataList;
}
void SelectDatatDialog::updateUI()
{
auto _page1Layout = new QVBoxLayout(this);
// 变量区域
auto variableArea = new ElaScrollArea(this);
auto variableAreaLayout = new QHBoxLayout(variableArea);
ElaText* listText = new ElaText("变量", this);
//listText->setTe xtPixelSize(12);
m_variableAxisValue = new ElaComboBox(this);
variableAreaLayout->addWidget(listText);
variableAreaLayout->addWidget(m_variableAxisValue);
_page1Layout->addWidget(variableArea);
QWidget* _otherKeyWidget = new QWidget(this);
//otherKey->setMaximumWidth(_contentWidth);
_otherKeyWidget->setStyleSheet("background:transparent;");
ElaScrollArea* otherKeyArea = new ElaScrollArea(this);
otherKeyArea->setWidget(_otherKeyWidget);
otherKeyArea->setWidgetResizable(true);
//otherKeyArea->setFixedHeight(100);
otherKeyArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
otherKeyArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
auto otherKeyAreaAreaLayout = new QVBoxLayout(_otherKeyWidget);
for (const auto& i : m_dataList)
{
// 变量区
m_variableAxisValue->addItem(i.first);
// 其他值区域
auto cur = new Curve2DKeySelcetBar(this);
cur->setData(i.first, i.second);
otherKeyAreaAreaLayout->addWidget(cur);
m_keySelectBarList.push_back(cur);
}
otherKeyAreaAreaLayout->addStretch();
_page1Layout->addWidget(otherKeyArea);
/// 步骤很重要先设置m_variableAxisValue的值再连信号再设置currentIndex
connect(m_variableAxisValue, QOverload<int>::of(&ElaComboBox::currentIndexChanged),
this, &SelectDatatDialog::slot_variableIndexChanged);
if (!m_dataList.empty())
{
m_variableAxisValue->setCurrentIndex(0);
m_keySelectBarList.at(0)->hide();
}
_page1Layout->addStretch();
auto _cancelOKLayout = new QHBoxLayout();
ElaPushButton* cancelButton = new ElaPushButton(this);
ElaPushButton* okButton = new ElaPushButton(this);
cancelButton->setText("取消");
okButton->setText("确定");
_cancelOKLayout->addStretch();
_cancelOKLayout->addWidget(cancelButton);
_cancelOKLayout->addWidget(okButton);
_page1Layout->addLayout(_cancelOKLayout);
connect(cancelButton, &ElaPushButton::clicked, this, [this]() {this->close(); });
connect(okButton, &ElaPushButton::clicked, this, &SelectDatatDialog::slot_sendChosenInfo);
}
void SelectDatatDialog::slot_variableIndexChanged(int index)
{
for (int i = 0; i < m_keySelectBarList.size(); ++i)
{
i == index ? m_keySelectBarList.at(i)->hide() : m_keySelectBarList.at(i)->show();
}
}
void pst::SelectDatatDialog::slot_sendChosenInfo()
{
auto variableIndex = m_variableAxisValue->currentIndex();
QList<QPair<int, QList<int>>> chosenkeyList;
for (int i = 0; i < m_keySelectBarList.size(); ++i)
{
if (i == variableIndex) continue;
auto indexs = m_keySelectBarList.at(i)->getSelectedIndex();
chosenkeyList.append(qMakePair(i, indexs));
}
emit signal_sendSelectedInfo(variableIndex, chosenkeyList);
this->close();
}
}