2025-04-18 18:44:26 +08:00
|
|
|
|
#include "groupSelectionDialog.h"
|
|
|
|
|
|
#include "./ui_groupSelectionDialog.h"
|
2025-04-21 14:29:20 +08:00
|
|
|
|
#include "maskLayer.h"
|
2025-04-18 18:44:26 +08:00
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
#include "sqlQueryExecutor.h"
|
|
|
|
|
|
#include "textColorPreserveDelegate.h"
|
|
|
|
|
|
#include "customBorderContainer.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define itemRole_groupID 1
|
|
|
|
|
|
#define itemRole_isPublic 2
|
|
|
|
|
|
#define itemRole_isNewlyAdded 3
|
|
|
|
|
|
|
|
|
|
|
|
GroupSelectionDialog::GroupSelectionDialog(QWidget *parent)
|
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
|
, ui(new Ui::GroupSelectionDialog)
|
|
|
|
|
|
, m_pMainWindow(nullptr)
|
|
|
|
|
|
, m_curModelID(-1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
if(QSysInfo::kernelType() == "linux")
|
|
|
|
|
|
{
|
|
|
|
|
|
//Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用
|
|
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::Dialog);
|
|
|
|
|
|
setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;background-color:rgb(250,250,250);}");
|
|
|
|
|
|
|
|
|
|
|
|
m_customBorderContainer = new CustomBorderContainer(this);
|
|
|
|
|
|
m_customBorderContainer->setOperationOptions(CustomBorderContainer::Movable | CustomBorderContainer::Resizable);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GroupSelectionDialog::~GroupSelectionDialog()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupSelectionDialog::initialize()
|
|
|
|
|
|
{
|
2025-04-21 14:29:20 +08:00
|
|
|
|
m_pMaskLayer = new MaskLayer(this);
|
|
|
|
|
|
|
2025-04-18 18:44:26 +08:00
|
|
|
|
TextColorPreserveDelegate* delegate = new TextColorPreserveDelegate(this);
|
|
|
|
|
|
ui->sourceList->setItemDelegate(delegate);
|
|
|
|
|
|
ui->selectedList->setItemDelegate(delegate);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui->btnSave, &QPushButton::clicked, this, &GroupSelectionDialog::onBtnClicked_save);
|
|
|
|
|
|
connect(ui->btnCancle, &QPushButton::clicked, this, &GroupSelectionDialog::onBtnClicked_cancle);
|
|
|
|
|
|
connect(ui->btnRemoveSelected, &QPushButton::clicked, this, &GroupSelectionDialog::onBtnClicked_removeSelected);
|
|
|
|
|
|
connect(ui->sourceList, &QListWidget::itemDoubleClicked, this, &GroupSelectionDialog::onItemDblCliked_sourceList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupSelectionDialog::setMainWindow(MainWindow* window)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pMainWindow = window;
|
|
|
|
|
|
|
|
|
|
|
|
ui->sourceList->clear();
|
|
|
|
|
|
ui->selectedList->clear();
|
|
|
|
|
|
if(m_pMainWindow)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString connection = m_pMainWindow->getCurConnection();
|
|
|
|
|
|
const QVector<AttributeGroup> groups = SqlQueryExecutor::instance().getAttributeGroup(connection);
|
|
|
|
|
|
for(const AttributeGroup& group : groups)
|
|
|
|
|
|
{
|
|
|
|
|
|
QListWidgetItem* sourceItem = new QListWidgetItem(group.name);
|
|
|
|
|
|
sourceItem->setFlags(sourceItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
|
sourceItem->setData(Qt::UserRole + itemRole_groupID, group.id);
|
|
|
|
|
|
sourceItem->setData(Qt::UserRole + itemRole_isPublic, group.isPublic);
|
|
|
|
|
|
ui->sourceList->addItem(sourceItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupSelectionDialog::setModel(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->selectedList->clear();
|
|
|
|
|
|
if(!m_pMainWindow || id <= 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
m_curModelID = id;
|
|
|
|
|
|
QString connection = m_pMainWindow->getCurConnection();
|
|
|
|
|
|
QVector<int> groups = SqlQueryExecutor::instance().getModelGroups(connection, id);
|
|
|
|
|
|
for(int groupID : groups)
|
|
|
|
|
|
{
|
|
|
|
|
|
AttributeGroup group = SqlQueryExecutor::instance().getAttributeGroupData(connection, groupID);
|
|
|
|
|
|
if(group.name.isEmpty())
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(group.name);
|
|
|
|
|
|
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
|
item->setData(Qt::UserRole + itemRole_groupID, group.id);
|
|
|
|
|
|
item->setData(Qt::UserRole + itemRole_isPublic, group.isPublic);
|
|
|
|
|
|
item->setData(Qt::UserRole + itemRole_isNewlyAdded, false);
|
|
|
|
|
|
item->setForeground(QBrush(QColor(128,128,128)));
|
|
|
|
|
|
ui->selectedList->addItem(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-21 14:29:20 +08:00
|
|
|
|
void GroupSelectionDialog::showMask()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pMaskLayer->setGeometry(0, 0, this->width(), this->height());
|
|
|
|
|
|
m_pMaskLayer->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
void GroupSelectionDialog::hideMask()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pMaskLayer->close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-18 18:44:26 +08:00
|
|
|
|
void GroupSelectionDialog::onBtnClicked_save()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!m_pMainWindow)
|
|
|
|
|
|
{
|
|
|
|
|
|
close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVector<int> groups;
|
|
|
|
|
|
for(int i = 0; i < ui->selectedList->count(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
QListWidgetItem* item = ui->selectedList->item(i);
|
|
|
|
|
|
bool isNewlyAdded = item->data(Qt::UserRole + itemRole_isNewlyAdded).toBool();
|
|
|
|
|
|
if(isNewlyAdded)
|
|
|
|
|
|
groups.append(item->data(Qt::UserRole + itemRole_groupID).toInt());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString connection = m_pMainWindow->getCurConnection();
|
|
|
|
|
|
bool result = SqlQueryExecutor::instance().addModleGrpus(connection, m_curModelID, groups);
|
|
|
|
|
|
if(!result)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pMainWindow->showMessageDialog(type_warning, QString::fromWCharArray(L"错误"),QString::fromWCharArray(L"信息存储失败,详情可见日志文件"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
emit addGroups(m_curModelID, groups);
|
|
|
|
|
|
close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupSelectionDialog::onBtnClicked_cancle()
|
|
|
|
|
|
{
|
|
|
|
|
|
close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupSelectionDialog::onBtnClicked_removeSelected()
|
|
|
|
|
|
{
|
|
|
|
|
|
QListWidgetItem* item = ui->selectedList->currentItem();
|
|
|
|
|
|
if(item && !item->data(Qt::UserRole + itemRole_isNewlyAdded).toBool())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pMainWindow->showMessageDialog(type_warning, QString::fromWCharArray(L"错误"),QString::fromWCharArray(L"该组别不是最新添加,不可移除"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int row = ui->selectedList->currentRow();
|
|
|
|
|
|
item = ui->selectedList->takeItem(row);
|
|
|
|
|
|
if(item)
|
|
|
|
|
|
delete item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupSelectionDialog::onItemDblCliked_sourceList(QListWidgetItem* item)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(item->data(Qt::UserRole + itemRole_isPublic).toBool())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QList<QListWidgetItem*> foundItems = ui->selectedList->findItems(item->text(), Qt::MatchFixedString);
|
|
|
|
|
|
if(foundItems.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QListWidgetItem* selectedItem = new QListWidgetItem(*item);
|
|
|
|
|
|
selectedItem->setData(Qt::UserRole + itemRole_isNewlyAdded, true);
|
|
|
|
|
|
ui->selectedList->addItem(selectedItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|