实现属性组浏览tab的关闭
This commit is contained in:
parent
f9ff317b46
commit
1f42960e74
|
|
@ -22,9 +22,11 @@ public:
|
|||
void addTab_attribute(const QString&, ModelAttributeGroup&);
|
||||
|
||||
private slots:
|
||||
void closeTab(QWidget*);
|
||||
void onBtnClick_tabCloseBtn(int);
|
||||
|
||||
private:
|
||||
int tabIndex(const QString&);
|
||||
|
||||
Ui::DatabaseBrowser *ui;
|
||||
QList<AttributeView> m_attributeViewList;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ private:
|
|||
void connectToDB(const QString&);
|
||||
void disconnectToDB(const QString&);
|
||||
void removeNode(DBStructureNode*);
|
||||
void openAttributeGroup(DBStructureNode*);
|
||||
|
||||
signals:
|
||||
void actionTrigger_addModel();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ DatabaseBrowser::DatabaseBrowser(QWidget *parent)
|
|||
, ui(new Ui::DatabaseBrowser)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->tabWidget, &QTabWidget::tabCloseRequested, this, &DatabaseBrowser::onBtnClick_tabCloseBtn);
|
||||
}
|
||||
|
||||
DatabaseBrowser::~DatabaseBrowser()
|
||||
|
|
@ -15,12 +17,34 @@ DatabaseBrowser::~DatabaseBrowser()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
int DatabaseBrowser::tabIndex(const QString& tabText)
|
||||
{
|
||||
for(int i = 0; i < ui->tabWidget->count(); i++)
|
||||
{
|
||||
QString strText = ui->tabWidget->tabText(i);
|
||||
if(ui->tabWidget->tabText(i) == tabText)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void DatabaseBrowser::addTab_attribute(const QString& connection, ModelAttributeGroup& attributeGroup)
|
||||
{
|
||||
QString tabText = attributeGroup.strModelName + "/" + attributeGroup.strGroupName;
|
||||
int index = tabIndex(tabText);
|
||||
if(index != -1)
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(index);
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeView* view = new AttributeView(ui->tabWidget, connection, QString::number(attributeGroup.modelID), QString::number(attributeGroup.groupID));
|
||||
int index = ui->tabWidget->addTab(view, QIcon(":/img/images/icon_hierarchy.png"), attributeGroup.strGroupName);
|
||||
index = ui->tabWidget->addTab(view, QIcon(":/img/images/icon_hierarchy.png"), tabText);
|
||||
//添加自定义按钮
|
||||
QPushButton* closeBtn = new QPushButton("");
|
||||
/*QPushButton* closeBtn = new QPushButton("");
|
||||
closeBtn->setProperty("index", index);
|
||||
connect(closeBtn, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClick_tabCloseBtn);
|
||||
closeBtn->setFixedSize(12, 12);
|
||||
closeBtn->setStyleSheet("QPushButton\n"
|
||||
"{\n"
|
||||
|
|
@ -35,11 +59,20 @@ void DatabaseBrowser::addTab_attribute(const QString& connection, ModelAttribute
|
|||
" border-image: url(:/img/images/btn_close_pressed.png);\n"
|
||||
"}");
|
||||
QTabBar* tabBar = ui->tabWidget->tabBar();
|
||||
tabBar->setTabButton(index, QTabBar::RightSide, closeBtn);
|
||||
tabBar->setTabButton(index, QTabBar::RightSide, closeBtn);*/
|
||||
|
||||
ui->tabWidget->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void DatabaseBrowser::closeTab(QWidget* tab)
|
||||
void DatabaseBrowser::onBtnClick_tabCloseBtn(int index)
|
||||
{
|
||||
/*QObject* sender = QObject::sender();
|
||||
QPushButton* button = qobject_cast<QPushButton*>(sender);
|
||||
if(!button)
|
||||
return;
|
||||
|
||||
int index = button->property("index").toInt();*/
|
||||
QWidget* widget = ui->tabWidget->widget(index);
|
||||
ui->tabWidget->removeTab(index);
|
||||
delete widget;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,20 @@ void DBStructureView::removeNode(DBStructureNode* node)
|
|||
}
|
||||
}
|
||||
|
||||
void DBStructureView::openAttributeGroup(DBStructureNode* node)
|
||||
{
|
||||
DBStructureNode* parent = node->parentNode();
|
||||
if(parent && parent->type() == TableNode)
|
||||
{
|
||||
int modelID = parent->data(Qt::UserRole + NodeDataRole::ID).toInt();
|
||||
int groupID = node->data(Qt::UserRole + NodeDataRole::ID).toInt();
|
||||
QString modelName = parent->name();
|
||||
QString groupName = node->name();
|
||||
ModelAttributeGroup attributeGroup(modelID, groupID, modelName, groupName);
|
||||
emit openAttributeInfo(m_curConnection, attributeGroup);
|
||||
}
|
||||
}
|
||||
|
||||
void DBStructureView::disconnectCurConnection()
|
||||
{
|
||||
if(!m_curConnection.isEmpty())
|
||||
|
|
@ -154,16 +168,7 @@ void DBStructureView::itemDoubleClick(const QModelIndex& index)
|
|||
}
|
||||
else if(node->type() == GroupNode)
|
||||
{
|
||||
DBStructureNode* parent = node->parentNode();
|
||||
if(parent && parent->type() == TableNode)
|
||||
{
|
||||
int modelID = parent->data(Qt::UserRole + NodeDataRole::ID).toInt();
|
||||
int groupID = node->data(Qt::UserRole + NodeDataRole::ID).toInt();
|
||||
QString modelName = parent->name();
|
||||
QString groupName = node->name();
|
||||
ModelAttributeGroup attributeGroup(modelID, groupID, modelName, groupName);
|
||||
emit openAttributeInfo(m_curConnection, attributeGroup);
|
||||
}
|
||||
openAttributeGroup(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +232,7 @@ void DBStructureView::showContextMenu(const QPoint& pos)
|
|||
});
|
||||
menu.addSeparator();
|
||||
menu.addAction(QString::fromWCharArray(L"刷新"), []{});
|
||||
menu.addAction(QString::fromWCharArray(L"打开"), []{});
|
||||
menu.addAction(QString::fromWCharArray(L"打开"), [this, node]{openAttributeGroup(node);});
|
||||
menu.addSeparator();
|
||||
menu.addAction(QString::fromWCharArray(L"清空数据"), []{});
|
||||
QPoint originPoint = this->mapToGlobal(QPoint(0,0));
|
||||
|
|
|
|||
|
|
@ -31,11 +31,23 @@
|
|||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QTabBar::close-button {
|
||||
border-image: url(:/img/images/btn_close_default.png);
|
||||
margin:2px;
|
||||
}
|
||||
QTabBar::close-button:hover {
|
||||
border-image: url(:/img/images/btn_close_hover.png);
|
||||
}
|
||||
QTabBar::close-button:pressed {
|
||||
border-image: url(:/img/images/btn_close_pressed.png);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
Loading…
Reference in New Issue