完成属性组的追加功能
This commit is contained in:
parent
bd49be8d6f
commit
3d4fa337ca
|
|
@ -30,6 +30,7 @@ set(H_HEADER_FILES
|
||||||
include/messageBox.h
|
include/messageBox.h
|
||||||
include/settings.h
|
include/settings.h
|
||||||
include/tableWidgetHoverDelegate.h
|
include/tableWidgetHoverDelegate.h
|
||||||
|
include/textColorPreserveDelegate.h
|
||||||
include/customMenu.h
|
include/customMenu.h
|
||||||
include/multiLineHeaderView.h
|
include/multiLineHeaderView.h
|
||||||
include/modelInfoEditDialog.h
|
include/modelInfoEditDialog.h
|
||||||
|
|
@ -41,6 +42,7 @@ set(H_HEADER_FILES
|
||||||
include/attributeSelector.h
|
include/attributeSelector.h
|
||||||
include/maskManager.h
|
include/maskManager.h
|
||||||
include/customBorderContainer.h
|
include/customBorderContainer.h
|
||||||
|
include/groupSelectionDialog.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CPP_SOURCE_FILES
|
set(CPP_SOURCE_FILES
|
||||||
|
|
@ -58,6 +60,7 @@ set(CPP_SOURCE_FILES
|
||||||
source/messageBox.cpp
|
source/messageBox.cpp
|
||||||
source/settings.cpp
|
source/settings.cpp
|
||||||
source/tableWidgetHoverDelegate.cpp
|
source/tableWidgetHoverDelegate.cpp
|
||||||
|
source/textColorPreserveDelegate.cpp
|
||||||
source/customMenu.cpp
|
source/customMenu.cpp
|
||||||
source/multiLineHeaderView.cpp
|
source/multiLineHeaderView.cpp
|
||||||
source/modelInfoEditDialog.cpp
|
source/modelInfoEditDialog.cpp
|
||||||
|
|
@ -68,6 +71,7 @@ set(CPP_SOURCE_FILES
|
||||||
source/attributeSelector.cpp
|
source/attributeSelector.cpp
|
||||||
source/maskManager.cpp
|
source/maskManager.cpp
|
||||||
source/customBorderContainer.cpp
|
source/customBorderContainer.cpp
|
||||||
|
source/groupSelectionDialog.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(UI_FILES
|
set(UI_FILES
|
||||||
|
|
@ -78,6 +82,7 @@ set(UI_FILES
|
||||||
ui/modelInfoEditDialog.ui
|
ui/modelInfoEditDialog.ui
|
||||||
ui/textEditWidget.ui
|
ui/textEditWidget.ui
|
||||||
ui/attributeSelector.ui
|
ui/attributeSelector.ui
|
||||||
|
ui/groupSelectionDialog.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class MainWindow;
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -12,7 +11,9 @@ class ConnectionDialog;
|
||||||
}
|
}
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
class CustomBorderContainer;
|
class CustomBorderContainer;
|
||||||
|
|
||||||
class ConnectionDialog : public QDialog
|
class ConnectionDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ public:
|
||||||
QModelIndex getConnNodeIndex(const QString& name);
|
QModelIndex getConnNodeIndex(const QString& name);
|
||||||
void addDataModel(const QString& connection, Model& model);
|
void addDataModel(const QString& connection, Model& model);
|
||||||
void removeDataModel(DBStructureNode*);
|
void removeDataModel(DBStructureNode*);
|
||||||
|
void addDataGroup(const QString& connection, int modelID, QVector<int> groups);
|
||||||
void removeDataGroup(DBStructureNode*);
|
void removeDataGroup(DBStructureNode*);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
@ -42,6 +43,7 @@ public slots:
|
||||||
private:
|
private:
|
||||||
DBStructureNode* getNode(const QModelIndex& index) const;
|
DBStructureNode* getNode(const QModelIndex& index) const;
|
||||||
DBStructureNode* getConnectionNode(const QString& name) const;
|
DBStructureNode* getConnectionNode(const QString& name) const;
|
||||||
|
DBStructureNode* getModelNode(DBStructureNode* connNode, int modelID) const;
|
||||||
|
|
||||||
MainWindow* m_pMainWindow;
|
MainWindow* m_pMainWindow;
|
||||||
DBStructureNode* m_rootNode;
|
DBStructureNode* m_rootNode;
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,9 @@ public:
|
||||||
~DBStructureView();
|
~DBStructureView();
|
||||||
|
|
||||||
void setMainWindow(MainWindow*);
|
void setMainWindow(MainWindow*);
|
||||||
|
DBStructureNode* currentNode();
|
||||||
void disconnectCurConnection();
|
void disconnectCurConnection();
|
||||||
const QString curConnection();
|
const QString curConnection();
|
||||||
|
|
||||||
void onActionTrigger_removeModel();
|
void onActionTrigger_removeModel();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -40,6 +39,7 @@ private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void actionTrigger_addModel();
|
void actionTrigger_addModel();
|
||||||
|
void actionTrigger_addGroup(int);
|
||||||
void openAttributeInfo(const QString&, ModelAttributeGroup&);
|
void openAttributeInfo(const QString&, ModelAttributeGroup&);
|
||||||
void closeAttributeInfo(ModelAttributeGroup&);
|
void closeAttributeInfo(ModelAttributeGroup&);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
#ifndef GROUPSELECTIONDIALOG_H
|
||||||
|
#define GROUPSELECTIONDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace Ui {
|
||||||
|
class GroupSelectionDialog;
|
||||||
|
}
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
|
class QListWidgetItem;
|
||||||
|
class CustomBorderContainer;
|
||||||
|
|
||||||
|
class GroupSelectionDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GroupSelectionDialog(QWidget *parent = nullptr);
|
||||||
|
~GroupSelectionDialog();
|
||||||
|
|
||||||
|
void setMainWindow(MainWindow*);
|
||||||
|
void setModel(int);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initialize();
|
||||||
|
|
||||||
|
Ui::GroupSelectionDialog* ui;
|
||||||
|
MainWindow* m_pMainWindow;
|
||||||
|
int m_curModelID;
|
||||||
|
|
||||||
|
CustomBorderContainer* m_customBorderContainer;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void addGroups(int, QVector<int>);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onBtnClicked_save();
|
||||||
|
void onBtnClicked_cancle();
|
||||||
|
void onBtnClicked_removeSelected();
|
||||||
|
void onItemDblCliked_sourceList(QListWidgetItem*);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //GROUPSELECTIONDIALOG_H
|
||||||
|
|
@ -12,6 +12,7 @@ class ConnectionDialog;
|
||||||
class DBStructureView;
|
class DBStructureView;
|
||||||
class DBStructureModel;
|
class DBStructureModel;
|
||||||
class ModelInfoEditDialog;
|
class ModelInfoEditDialog;
|
||||||
|
class GroupSelectionDialog;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -47,18 +48,21 @@ private:
|
||||||
DBStructureView* m_pDBStrutureView;
|
DBStructureView* m_pDBStrutureView;
|
||||||
DBStructureModel* m_pDBStrutureModel;
|
DBStructureModel* m_pDBStrutureModel;
|
||||||
ModelInfoEditDialog* m_pModelInfoDialog;
|
ModelInfoEditDialog* m_pModelInfoDialog;
|
||||||
|
GroupSelectionDialog* m_pGroupSelectionDialog;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onActionTrigger_connect();
|
void onActionTrigger_connect();
|
||||||
void onActionTrigger_disconnect();
|
void onActionTrigger_disconnect();
|
||||||
void onActionTrigger_addModel();
|
void onActionTrigger_addModel();
|
||||||
void onActionTrigger_removeModel();
|
void onActionTrigger_removeModel();
|
||||||
|
void onActionTrigger_addGroup(int);
|
||||||
|
|
||||||
void onSIG_addConnection(DatabaseConfig&);
|
void onSIG_addConnection(DatabaseConfig&);
|
||||||
void onSIG_errorFromDBManger(const QString& strConnectionName, const QString& error);
|
void onSIG_errorFromDBManger(const QString& strConnectionName, const QString& error);
|
||||||
void onSIG_errorFormSQLExecutor(const QString& error);
|
void onSIG_errorFormSQLExecutor(const QString& error);
|
||||||
void onSIG_connectionStatusChanged(const QString& strConnectionName, bool bConnected);
|
void onSIG_connectionStatusChanged(const QString& strConnectionName, bool bConnected);
|
||||||
void onSIG_addModel(Model&);
|
void onSIG_addModel(Model&);
|
||||||
|
void onSIG_addGroups(int, QVector<int>);
|
||||||
void onSIG_openAttributeInfo(const QString&, ModelAttributeGroup&);
|
void onSIG_openAttributeInfo(const QString&, ModelAttributeGroup&);
|
||||||
void onSIG_closeAttributeInfo(ModelAttributeGroup&);
|
void onSIG_closeAttributeInfo(ModelAttributeGroup&);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,16 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
class MainWindow;
|
|
||||||
class QListWidgetItem;
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ModelInfoEditDialog;
|
class ModelInfoEditDialog;
|
||||||
}
|
}
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
|
class QListWidgetItem;
|
||||||
|
class CustomBorderContainer;
|
||||||
|
|
||||||
class ModelInfoEditDialog : public QDialog
|
class ModelInfoEditDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -23,7 +24,7 @@ public:
|
||||||
|
|
||||||
void setState(DialogState state) {m_state = state;}
|
void setState(DialogState state) {m_state = state;}
|
||||||
void setMainWindow(MainWindow*);
|
void setMainWindow(MainWindow*);
|
||||||
void setModel(int id) {m_curModelID = id;}
|
void setModel(int);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void showEvent(QShowEvent*);
|
virtual void showEvent(QShowEvent*);
|
||||||
|
|
@ -39,6 +40,8 @@ private:
|
||||||
MainWindow* m_pMainWindow;
|
MainWindow* m_pMainWindow;
|
||||||
int m_curModelID;
|
int m_curModelID;
|
||||||
|
|
||||||
|
CustomBorderContainer* m_customBorderContainer;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void addModel(Model&);
|
void addModel(Model&);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ public:
|
||||||
bool modelNameExistsInDB(const QString&, const QString&);
|
bool modelNameExistsInDB(const QString&, const QString&);
|
||||||
bool modelTypeExistsInDB(const QString&, const QString&);
|
bool modelTypeExistsInDB(const QString&, const QString&);
|
||||||
bool removeModel(const QString&, int);
|
bool removeModel(const QString&, int);
|
||||||
|
bool addModleGrpus(const QString&, int, QVector<int>);
|
||||||
|
QVector<int> getModelGroups(const QString&, int);
|
||||||
//属性相关
|
//属性相关
|
||||||
int getAttributeCount(const QString&, int, int);
|
int getAttributeCount(const QString&, int, int);
|
||||||
int getAllAttributeCount(const QString&);
|
int getAllAttributeCount(const QString&);
|
||||||
|
|
@ -53,8 +55,6 @@ private:
|
||||||
// 禁止拷贝
|
// 禁止拷贝
|
||||||
SqlQueryExecutor(const SqlQueryExecutor&) = delete; //delete关键字表示该函数不可用,包括编译器自动生成的函数
|
SqlQueryExecutor(const SqlQueryExecutor&) = delete; //delete关键字表示该函数不可用,包括编译器自动生成的函数
|
||||||
SqlQueryExecutor& operator=(const SqlQueryExecutor&) = delete;
|
SqlQueryExecutor& operator=(const SqlQueryExecutor&) = delete;
|
||||||
//基于具体业务的查询接口-内部调用
|
|
||||||
QVector<int> getModelGroups(const QString&, int);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //SQLQUERYEXECUTOR_H
|
#endif //SQLQUERYEXECUTOR_H
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
*\brief 用来实现item选中时保持前景色(文字颜色)不变
|
||||||
|
*
|
||||||
|
*\author dsc
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEXTCOLORPRESERVEDELEGATE_H
|
||||||
|
#define TEXTCOLORPRESERVEDELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
class TextColorPreserveDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TextColorPreserveDelegate(QObject* parent = nullptr);
|
||||||
|
~TextColorPreserveDelegate();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TEXTCOLORPRESERVEDELEGATE_H
|
||||||
|
|
@ -42,6 +42,20 @@ DBStructureNode* DBStructureModel::getConnectionNode(const QString& name) const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBStructureNode* DBStructureModel::getModelNode(DBStructureNode* connNode, int modelID) const
|
||||||
|
{
|
||||||
|
if(!connNode)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
for(int i = 0; i < connNode->childCount(); ++i)
|
||||||
|
{
|
||||||
|
DBStructureNode* node = connNode->child(i);
|
||||||
|
if(node->type() == TableNode && node->data(Qt::UserRole + NodeDataRole::ID).toInt() == modelID)
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex DBStructureModel::index(int row, int column, const QModelIndex& parent) const
|
QModelIndex DBStructureModel::index(int row, int column, const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
if(!hasIndex(row, column, parent))
|
if(!hasIndex(row, column, parent))
|
||||||
|
|
@ -212,6 +226,41 @@ void DBStructureModel::removeDataModel(DBStructureNode* modelNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DBStructureModel::addDataGroup(const QString& connection, int modelID, QVector<int> groups)
|
||||||
|
{
|
||||||
|
DBStructureNode* connNode = getConnectionNode(connection);
|
||||||
|
if(!connNode)
|
||||||
|
{
|
||||||
|
LOG_ERROR("DBStructureModel", QString::fromWCharArray(L"添加数组时获取ConnectionNode失败,节点名称:%1").arg(connection));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DBStructureNode* modelNode = getModelNode(connNode, modelID);
|
||||||
|
if(!connNode)
|
||||||
|
{
|
||||||
|
LOG_ERROR("DBStructureModel", QString::fromWCharArray(L"添加数组时获取ModelNode失败,节点ID:%1").arg(modelID));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex connIndex = index(connNode->row(), 0, QModelIndex());
|
||||||
|
QModelIndex modelIndex = index(modelNode->row(), 0, connIndex);
|
||||||
|
beginInsertRows(modelIndex, modelNode->childCount(), groups.count());
|
||||||
|
|
||||||
|
for(int groupID : groups)
|
||||||
|
{
|
||||||
|
//QString groupName = SqlQueryExecutor::instance().getAttributeGroupName(connection, groupID);
|
||||||
|
AttributeGroup group = SqlQueryExecutor::instance().getAttributeGroupData(connection, groupID);
|
||||||
|
if(group.name.isEmpty())
|
||||||
|
continue;
|
||||||
|
DBStructureNode* groupNode = new DBStructureNode(GroupNode, group.name, modelNode);
|
||||||
|
groupNode->setData(Qt::UserRole + NodeDataRole::ID, groupID);
|
||||||
|
groupNode->setData(Qt::UserRole + NodeDataRole::Type, group.isPublic);
|
||||||
|
modelNode->appendChild(groupNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
void DBStructureModel::removeDataGroup(DBStructureNode* groupNode)
|
void DBStructureModel::removeDataGroup(DBStructureNode* groupNode)
|
||||||
{
|
{
|
||||||
int groupID = groupNode->data(Qt::UserRole + NodeDataRole::ID).toInt();
|
int groupID = groupNode->data(Qt::UserRole + NodeDataRole::ID).toInt();
|
||||||
|
|
|
||||||
|
|
@ -164,10 +164,16 @@ const QString DBStructureView::curConnection()
|
||||||
return m_curConnection;
|
return m_curConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBStructureView::onActionTrigger_removeModel()
|
DBStructureNode* DBStructureView::currentNode()
|
||||||
{
|
{
|
||||||
QModelIndex currentInex = currentIndex();
|
QModelIndex currentInex = currentIndex();
|
||||||
DBStructureNode* node = static_cast<DBStructureNode*>(currentInex.internalPointer());
|
DBStructureNode* node = static_cast<DBStructureNode*>(currentInex.internalPointer());
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBStructureView::onActionTrigger_removeModel()
|
||||||
|
{
|
||||||
|
DBStructureNode* node = currentNode();
|
||||||
if(!node || (node->type() != TableNode && node->type() != GroupNode))
|
if(!node || (node->type() != TableNode && node->type() != GroupNode))
|
||||||
{
|
{
|
||||||
if(m_pMainWindow)
|
if(m_pMainWindow)
|
||||||
|
|
@ -280,8 +286,11 @@ void DBStructureView::showContextMenu(const QPoint& pos)
|
||||||
}
|
}
|
||||||
removeNode(node);
|
removeNode(node);
|
||||||
});
|
});
|
||||||
menu.addSeparator();
|
|
||||||
menu.addAction(QString::fromWCharArray(L"刷新"), []{});
|
menu.addAction(QString::fromWCharArray(L"刷新"), []{});
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(QString::fromWCharArray(L"添加属性组"), [this, node]{
|
||||||
|
emit actionTrigger_addGroup(node->data(Qt::UserRole + NodeDataRole::ID).toInt());
|
||||||
|
});
|
||||||
//menu.addAction(QString::fromWCharArray(L"打开"), []{});
|
//menu.addAction(QString::fromWCharArray(L"打开"), []{});
|
||||||
/*menu.addSeparator();
|
/*menu.addSeparator();
|
||||||
menu.addAction(QString::fromWCharArray(L"清空数据"), []{});
|
menu.addAction(QString::fromWCharArray(L"清空数据"), []{});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,156 @@
|
||||||
|
#include "groupSelectionDialog.h"
|
||||||
|
#include "./ui_groupSelectionDialog.h"
|
||||||
|
#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()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "sqlQueryExecutor.h"
|
#include "sqlQueryExecutor.h"
|
||||||
#include "modelInfoEditDialog.h"
|
#include "modelInfoEditDialog.h"
|
||||||
|
#include "groupSelectionDialog.h"
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
@ -21,6 +22,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
, m_pMessageDialog(nullptr)
|
, m_pMessageDialog(nullptr)
|
||||||
, m_pConnectionDialog(nullptr)
|
, m_pConnectionDialog(nullptr)
|
||||||
, m_pModelInfoDialog(nullptr)
|
, m_pModelInfoDialog(nullptr)
|
||||||
|
, m_pGroupSelectionDialog(nullptr)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
@ -78,6 +80,7 @@ void MainWindow::initialize()
|
||||||
m_pDBStrutureView = new DBStructureView(m_dbManager, this);
|
m_pDBStrutureView = new DBStructureView(m_dbManager, this);
|
||||||
m_pDBStrutureView->setMainWindow(this);
|
m_pDBStrutureView->setMainWindow(this);
|
||||||
connect(m_pDBStrutureView, &DBStructureView::actionTrigger_addModel, this, &MainWindow::onActionTrigger_addModel);
|
connect(m_pDBStrutureView, &DBStructureView::actionTrigger_addModel, this, &MainWindow::onActionTrigger_addModel);
|
||||||
|
connect(m_pDBStrutureView, &DBStructureView::actionTrigger_addGroup, this, &MainWindow::onActionTrigger_addGroup);
|
||||||
connect(m_pDBStrutureView, &DBStructureView::openAttributeInfo, this, &MainWindow::onSIG_openAttributeInfo);
|
connect(m_pDBStrutureView, &DBStructureView::openAttributeInfo, this, &MainWindow::onSIG_openAttributeInfo);
|
||||||
connect(m_pDBStrutureView, &DBStructureView::closeAttributeInfo, this, &MainWindow::onSIG_closeAttributeInfo);
|
connect(m_pDBStrutureView, &DBStructureView::closeAttributeInfo, this, &MainWindow::onSIG_closeAttributeInfo);
|
||||||
ui->layoutDBStructure->addWidget(m_pDBStrutureView);
|
ui->layoutDBStructure->addWidget(m_pDBStrutureView);
|
||||||
|
|
@ -181,6 +184,7 @@ void MainWindow::onActionTrigger_addModel()
|
||||||
m_pModelInfoDialog->setMainWindow(this);
|
m_pModelInfoDialog->setMainWindow(this);
|
||||||
m_pModelInfoDialog->installEventFilter(this);
|
m_pModelInfoDialog->installEventFilter(this);
|
||||||
connect(m_pModelInfoDialog, &ModelInfoEditDialog::addModel, this, &MainWindow::onSIG_addModel);
|
connect(m_pModelInfoDialog, &ModelInfoEditDialog::addModel, this, &MainWindow::onSIG_addModel);
|
||||||
|
connect(m_pModelInfoDialog, &ModelInfoEditDialog::finished, this, [=]{ MaskManager::instance()->hideMask(m_pModelInfoDialog);});
|
||||||
}
|
}
|
||||||
|
|
||||||
int nX = this->geometry().x() + (this->width() - m_pModelInfoDialog->width()) * 0.5;
|
int nX = this->geometry().x() + (this->width() - m_pModelInfoDialog->width()) * 0.5;
|
||||||
|
|
@ -189,8 +193,8 @@ void MainWindow::onActionTrigger_addModel()
|
||||||
m_pModelInfoDialog->setState(DS_New);
|
m_pModelInfoDialog->setState(DS_New);
|
||||||
|
|
||||||
MaskManager::instance()->showMask(m_pModelInfoDialog);
|
MaskManager::instance()->showMask(m_pModelInfoDialog);
|
||||||
m_pModelInfoDialog->exec();
|
m_pModelInfoDialog->show();
|
||||||
MaskManager::instance()->hideMask(m_pModelInfoDialog);
|
//MaskManager::instance()->hideMask(m_pModelInfoDialog);
|
||||||
}
|
}
|
||||||
void MainWindow::onActionTrigger_removeModel()
|
void MainWindow::onActionTrigger_removeModel()
|
||||||
{
|
{
|
||||||
|
|
@ -211,6 +215,29 @@ void MainWindow::onSIG_addConnection(DatabaseConfig& config)
|
||||||
m_pDBStrutureModel->addConnection(config.strConnectionName, config.strDBType);
|
m_pDBStrutureModel->addConnection(config.strConnectionName, config.strDBType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onActionTrigger_addGroup(int modelID)
|
||||||
|
{
|
||||||
|
if(m_pGroupSelectionDialog && m_pGroupSelectionDialog->isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(m_pGroupSelectionDialog == nullptr)
|
||||||
|
{
|
||||||
|
m_pGroupSelectionDialog = new GroupSelectionDialog(this);
|
||||||
|
m_pGroupSelectionDialog->setMainWindow(this);
|
||||||
|
m_pGroupSelectionDialog->installEventFilter(this);
|
||||||
|
connect(m_pGroupSelectionDialog, &GroupSelectionDialog::addGroups, this, &MainWindow::onSIG_addGroups);
|
||||||
|
connect(m_pGroupSelectionDialog, &GroupSelectionDialog::finished, this, [=]{ MaskManager::instance()->hideMask(m_pGroupSelectionDialog);});
|
||||||
|
}
|
||||||
|
|
||||||
|
int nX = this->geometry().x() + (this->width() - m_pGroupSelectionDialog->width()) * 0.5;
|
||||||
|
int nY = this->geometry().y() + (this->height() - m_pGroupSelectionDialog->height()) * 0.5;
|
||||||
|
m_pGroupSelectionDialog->move(nX, nY);
|
||||||
|
m_pGroupSelectionDialog->setModel(modelID);
|
||||||
|
|
||||||
|
MaskManager::instance()->showMask(m_pGroupSelectionDialog);
|
||||||
|
m_pGroupSelectionDialog->show();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onSIG_errorFromDBManger(const QString& strConnectionName, const QString& error)
|
void MainWindow::onSIG_errorFromDBManger(const QString& strConnectionName, const QString& error)
|
||||||
{
|
{
|
||||||
//m_lastSqlError = error;
|
//m_lastSqlError = error;
|
||||||
|
|
@ -238,6 +265,12 @@ void MainWindow::onSIG_addModel(Model& model)
|
||||||
m_pDBStrutureModel->addDataModel(connection, model);
|
m_pDBStrutureModel->addDataModel(connection, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSIG_addGroups(int modelID, QVector<int> groups)
|
||||||
|
{
|
||||||
|
QString connection = m_pDBStrutureView->curConnection();
|
||||||
|
m_pDBStrutureModel->addDataGroup(connection, modelID, groups);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onSIG_openAttributeInfo(const QString& connection, ModelAttributeGroup& attributeGroup)
|
void MainWindow::onSIG_openAttributeInfo(const QString& connection, ModelAttributeGroup& attributeGroup)
|
||||||
{
|
{
|
||||||
if(m_dbBrowser)
|
if(m_dbBrowser)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#include "./ui_modelInfoEditDialog.h"
|
#include "./ui_modelInfoEditDialog.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "sqlQueryExecutor.h"
|
#include "sqlQueryExecutor.h"
|
||||||
|
#include "textColorPreserveDelegate.h"
|
||||||
|
#include "customBorderContainer.h"
|
||||||
#include <QRegularExpressionValidator>
|
#include <QRegularExpressionValidator>
|
||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
|
|
@ -13,6 +15,7 @@ ModelInfoEditDialog::ModelInfoEditDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, ui(new Ui::ModelInfoEditDialog)
|
, ui(new Ui::ModelInfoEditDialog)
|
||||||
, m_pMainWindow(nullptr)
|
, m_pMainWindow(nullptr)
|
||||||
|
, m_curModelID(-1)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
if(QSysInfo::kernelType() == "linux")
|
if(QSysInfo::kernelType() == "linux")
|
||||||
|
|
@ -20,6 +23,9 @@ ModelInfoEditDialog::ModelInfoEditDialog(QWidget *parent)
|
||||||
//Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用
|
//Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用
|
||||||
setWindowFlags(windowFlags() & ~Qt::Dialog);
|
setWindowFlags(windowFlags() & ~Qt::Dialog);
|
||||||
setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;background-color:rgb(250,250,250);}");
|
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();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
@ -52,6 +58,10 @@ void ModelInfoEditDialog::initialize()
|
||||||
QRegularExpressionValidator* validator = new QRegularExpressionValidator(regExp, this);
|
QRegularExpressionValidator* validator = new QRegularExpressionValidator(regExp, this);
|
||||||
ui->lineEdit_modelType->setValidator(validator);
|
ui->lineEdit_modelType->setValidator(validator);
|
||||||
|
|
||||||
|
TextColorPreserveDelegate* delegate = new TextColorPreserveDelegate(this);
|
||||||
|
ui->sourceList->setItemDelegate(delegate);
|
||||||
|
ui->selectedList->setItemDelegate(delegate);
|
||||||
|
|
||||||
connect(ui->btnSave, &QPushButton::clicked, this, &ModelInfoEditDialog::onBtnClicked_save);
|
connect(ui->btnSave, &QPushButton::clicked, this, &ModelInfoEditDialog::onBtnClicked_save);
|
||||||
connect(ui->btnCancle, &QPushButton::clicked, this, &ModelInfoEditDialog::onBtnClicked_cancle);
|
connect(ui->btnCancle, &QPushButton::clicked, this, &ModelInfoEditDialog::onBtnClicked_cancle);
|
||||||
connect(ui->btnAddGroup, &QPushButton::clicked, this, &ModelInfoEditDialog::onBtnClicked_addGroup);
|
connect(ui->btnAddGroup, &QPushButton::clicked, this, &ModelInfoEditDialog::onBtnClicked_addGroup);
|
||||||
|
|
@ -76,10 +86,8 @@ void ModelInfoEditDialog::refreshGroupList()
|
||||||
{
|
{
|
||||||
ui->sourceList->clear();
|
ui->sourceList->clear();
|
||||||
ui->selectedList->clear();
|
ui->selectedList->clear();
|
||||||
if(!m_pMainWindow)
|
|
||||||
return;
|
|
||||||
QString connection = m_pMainWindow->getCurConnection();
|
QString connection = m_pMainWindow->getCurConnection();
|
||||||
//考虑写一个专门用来返回相关数据的类,可以减少多处调用同样SQL语句的状况,也可以避免SQL语句变更时需要更改同步多处
|
|
||||||
const QVector<AttributeGroup> groups = SqlQueryExecutor::instance().getAttributeGroup(connection);
|
const QVector<AttributeGroup> groups = SqlQueryExecutor::instance().getAttributeGroup(connection);
|
||||||
for(const AttributeGroup& group : groups)
|
for(const AttributeGroup& group : groups)
|
||||||
{
|
{
|
||||||
|
|
@ -112,6 +120,11 @@ void ModelInfoEditDialog::setMainWindow(MainWindow* window)
|
||||||
m_pMainWindow = window;
|
m_pMainWindow = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelInfoEditDialog::setModel(int id)
|
||||||
|
{
|
||||||
|
m_curModelID = id;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelInfoEditDialog::onItemDblCliked_sourceList(QListWidgetItem* item)
|
void ModelInfoEditDialog::onItemDblCliked_sourceList(QListWidgetItem* item)
|
||||||
{
|
{
|
||||||
if(item->data(Qt::UserRole + itemRole_isPublic).toBool())
|
if(item->data(Qt::UserRole + itemRole_isPublic).toBool())
|
||||||
|
|
@ -169,7 +182,8 @@ void ModelInfoEditDialog::onBtnClicked_save()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//插入数据
|
|
||||||
|
//向数据库中插入数据(因为提供了连续添加的功能,所以向数据库中插入数据放在这里执行)
|
||||||
Model modle(-1, modelName, modeType, remark, groups);
|
Model modle(-1, modelName, modeType, remark, groups);
|
||||||
bool result = SqlQueryExecutor::instance().addModel(connection, modle);
|
bool result = SqlQueryExecutor::instance().addModel(connection, modle);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ bool SqlQueryExecutor::addModel(const QString& connectionName, Model& model)
|
||||||
}
|
}
|
||||||
|
|
||||||
//然后向model_group中插入记录,采用批量接口
|
//然后向model_group中插入记录,采用批量接口
|
||||||
QStringList sqlStatements;
|
/*QStringList sqlStatements;
|
||||||
QList<QVariantHash> paramsList;
|
QList<QVariantHash> paramsList;
|
||||||
for(int groupID : model.groups)
|
for(int groupID : model.groups)
|
||||||
{
|
{
|
||||||
|
|
@ -290,6 +290,35 @@ bool SqlQueryExecutor::addModel(const QString& connectionName, Model& model)
|
||||||
executeBatchSQL(connectionName, sqlStatements, paramsList);
|
executeBatchSQL(connectionName, sqlStatements, paramsList);
|
||||||
}
|
}
|
||||||
catch (const DatabaseException& e)
|
catch (const DatabaseException& e)
|
||||||
|
{
|
||||||
|
LOG_INFO("DB", QString("DB Rollback"));
|
||||||
|
if(!db.rollback()) // 回滚失败时记录警告
|
||||||
|
{
|
||||||
|
LOG_ERROR("DB", QString("Rollback failed. connectionName: %1. error: %2").arg(connectionName, db.lastError().databaseText()));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
QSqlQuery query(db);
|
||||||
|
strSQL = "INSERT INTO basic.model_group (model_type_id, attribute_group_id) VALUES (?, ?)";
|
||||||
|
if(!query.prepare(strSQL))
|
||||||
|
{
|
||||||
|
LOG_ERROR("SQL", QString("SQL '%1' prepare fialed. error: %2").arg(strSQL, query.lastError().databaseText()));
|
||||||
|
if(!db.rollback()) // 回滚
|
||||||
|
{
|
||||||
|
LOG_ERROR("DB", QString("Rollback failed. connectionName: %1. error: %2").arg(connectionName, db.lastError().databaseText()));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QVariantList modelIds, groupIds;
|
||||||
|
for(int groupID : model.groups)
|
||||||
|
{
|
||||||
|
modelIds << modelID;
|
||||||
|
groupIds << groupID;
|
||||||
|
}
|
||||||
|
query.addBindValue(modelIds);
|
||||||
|
query.addBindValue(groupIds);
|
||||||
|
if( !query.execBatch() )
|
||||||
{
|
{
|
||||||
LOG_INFO("DB", QString("DB Rollback"));
|
LOG_INFO("DB", QString("DB Rollback"));
|
||||||
if(!db.rollback()) // 回滚失败时记录警告
|
if(!db.rollback()) // 回滚失败时记录警告
|
||||||
|
|
@ -359,6 +388,61 @@ bool SqlQueryExecutor::removeModel(const QString& connectionName, int modelID)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SqlQueryExecutor::addModleGrpus(const QString& connectionName, int modelID, QVector<int> groups)
|
||||||
|
{
|
||||||
|
//属于批量操作,需要开启事务
|
||||||
|
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
||||||
|
if(!db.isOpen())
|
||||||
|
{
|
||||||
|
LOG_ERROR("DB", QString("Database not open. connectionName: %1").arg(connectionName));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!db.transaction())
|
||||||
|
{
|
||||||
|
LOG_ERROR("DB", QString("Start transaction failed. connectionName: %1. error: %2").arg(connectionName, db.lastError().databaseText()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery query(db);
|
||||||
|
QString strSQL = "INSERT INTO basic.model_group (model_type_id, attribute_group_id) VALUES (?, ?)";
|
||||||
|
if(!query.prepare(strSQL))
|
||||||
|
{
|
||||||
|
LOG_ERROR("SQL", QString("SQL '%1' prepare fialed. error: %2").arg(strSQL, query.lastError().databaseText()));
|
||||||
|
if(!db.rollback()) // 回滚
|
||||||
|
{
|
||||||
|
LOG_ERROR("DB", QString("Rollback failed. connectionName: %1. error: %2").arg(connectionName, db.lastError().databaseText()));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QVariantList modelIds, groupIds;
|
||||||
|
for(int groupID : groups)
|
||||||
|
{
|
||||||
|
modelIds << modelID;
|
||||||
|
groupIds << groupID;
|
||||||
|
}
|
||||||
|
query.addBindValue(modelIds);
|
||||||
|
query.addBindValue(groupIds);
|
||||||
|
if( !query.execBatch() )
|
||||||
|
{
|
||||||
|
LOG_ERROR("SQL", QString("SQL '%1' execBatch error: %2").arg(strSQL, query.lastError().databaseText()));
|
||||||
|
LOG_INFO("DB", QString("DB Rollback"));
|
||||||
|
if(!db.rollback()) // 回滚
|
||||||
|
{
|
||||||
|
LOG_ERROR("DB", QString("Rollback failed. connectionName: %1. error: %2").arg(connectionName, db.lastError().databaseText()));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!db.commit()) // 提交
|
||||||
|
{
|
||||||
|
LOG_ERROR("DB", QString("Commit transaction failed. connectionName: %1. error: %2").arg(connectionName, db.lastError().databaseText()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const QVector<AttributeGroup> SqlQueryExecutor::getAttributeGroup(const QString& connectionName)
|
const QVector<AttributeGroup> SqlQueryExecutor::getAttributeGroup(const QString& connectionName)
|
||||||
{
|
{
|
||||||
QVector<AttributeGroup> groupList;
|
QVector<AttributeGroup> groupList;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include "textColorPreserveDelegate.h"
|
||||||
|
|
||||||
|
TextColorPreserveDelegate::TextColorPreserveDelegate(QObject *parent)
|
||||||
|
: QStyledItemDelegate{parent}
|
||||||
|
{}
|
||||||
|
|
||||||
|
TextColorPreserveDelegate::~TextColorPreserveDelegate()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void TextColorPreserveDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
QColor textColor = index.data(Qt::ForegroundRole).value<QColor>();
|
||||||
|
|
||||||
|
QStyleOptionViewItem opt = option;
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
|
||||||
|
opt.palette.setColor(QPalette::Text, textColor);
|
||||||
|
opt.palette.setColor(QPalette::HighlightedText, textColor); // 关键:覆盖高亮文本色
|
||||||
|
|
||||||
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,252 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>GroupSelectionDialog</class>
|
||||||
|
<widget class="QDialog" name="GroupSelectionDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>372</width>
|
||||||
|
<height>305</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>属性组编辑</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="../resource/PowerModeler.qrc">
|
||||||
|
<normaloff>:/img/images/icon_hierarchy.png</normaloff>:/img/images/icon_hierarchy.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">QListView
|
||||||
|
{
|
||||||
|
outline:0px;
|
||||||
|
border-left:1px solid rgb(235,235,235);
|
||||||
|
border-right:1px solid rgb(235,235,235);
|
||||||
|
border-top:1px solid rgb(0,0,0);
|
||||||
|
border-bottom:1px solid rgb(0,0,0);
|
||||||
|
}
|
||||||
|
QListView::item
|
||||||
|
{
|
||||||
|
border:0px;
|
||||||
|
padding-left:5px;
|
||||||
|
padding-top:1px;
|
||||||
|
padding-bottom:1px;
|
||||||
|
}
|
||||||
|
QListView::item:hover
|
||||||
|
{
|
||||||
|
background-color: rgb(240, 248, 255);
|
||||||
|
}
|
||||||
|
QListView::item:selected
|
||||||
|
{
|
||||||
|
background-color:rgb(211, 241, 250);
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>12</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_source">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>61</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>61</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>所有组别</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="sourceList"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_selected">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>61</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>61</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>所选组别</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnRemoveSelected">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>21</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>21</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">QPushButton
|
||||||
|
{
|
||||||
|
border:0px;
|
||||||
|
image: url(:/img/images/icon_remove2.png);
|
||||||
|
}
|
||||||
|
QPushButton:hover
|
||||||
|
{
|
||||||
|
image: url(:/img/images/icon_remove2_hover.png);
|
||||||
|
}
|
||||||
|
QPushButton:pressed
|
||||||
|
{
|
||||||
|
image: url(:/img/images/icon_remove2.png);
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="selectedList"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnSave">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>86</width>
|
||||||
|
<height>31</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>86</width>
|
||||||
|
<height>31</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>完成</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnCancle">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>86</width>
|
||||||
|
<height>31</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>86</width>
|
||||||
|
<height>31</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>取消</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../resource/PowerModeler.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
|
|
@ -39,7 +39,6 @@ background-color: rgb(240, 248, 255);
|
||||||
}
|
}
|
||||||
QListView::item:selected
|
QListView::item:selected
|
||||||
{
|
{
|
||||||
color:rgb(0,0,0);
|
|
||||||
background-color:rgb(211, 241, 250);
|
background-color:rgb(211, 241, 250);
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -261,7 +260,7 @@ background-color:rgb(211, 241, 250);
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>所有类别</string>
|
<string>所有组别</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -347,7 +346,7 @@ QPushButton:pressed
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>所选类别</string>
|
<string>所选组别</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue