-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmasterview.cpp
More file actions
85 lines (67 loc) · 2.28 KB
/
masterview.cpp
File metadata and controls
85 lines (67 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "masterview.h"
#include "ui_masterview.h"
#include "dbmanager.h" // 确保数据库已初始化
MasterView::MasterView(QWidget *parent)
: QWidget(parent)
, ui(new Ui::MasterView)
{
ui->setupUi(this);
// 1. 初始化数据库 (如果 main.cpp 里没调的话,这里最好调一次)
DbManager::initDatabase();
// 2. 加载子页面
initViews();
}
MasterView::~MasterView()
{
delete ui;
}
void MasterView::initUser(const QString &username)
{
// 设置窗口标题,带上用户名,显得专业点
this->setWindowTitle(QString("企业库存管理系统 - 当前操作员: %1").arg(username));
// 把用户名传给 pageGoods (也就是 MainWindow)
if (pageGoods) {
pageGoods->setCurrentUser(username);
}
}
void MasterView::initViews()
{
// === 页面 1: 货品管理 (MainWindow) ===
pageGoods = new MainWindow(this);
// MainWindow 自带菜单栏和状态栏,嵌入后会自动显示在内部区域
// === 页面 2: 出入库记录 (RecordsDialog) ===
pageRecords = new RecordsDialog(this);
// 【关键】RecordsDialog 原本是弹窗,必须设为 Widget 模式才能嵌入
pageRecords->setWindowFlags(Qt::Widget);
pageWarehouse = new WarehousePage(this);
// === 添加到 StackedWidget ===
// 索引 0
ui->stackedWidget->addWidget(pageGoods);
// 索引 1
ui->stackedWidget->addWidget(pageRecords);
ui->stackedWidget->addWidget(pageWarehouse);
// 默认显示第 0 页
ui->stackedWidget->setCurrentIndex(0);
connect(pageGoods, &MainWindow::dbUpdated,
pageRecords, &RecordsDialog::refreshData);
}
// 切换到“货品管理”
void MasterView::on_btnPageGoods_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
}
// 切换到“出入库记录”
void MasterView::on_btnPageRecords_clicked()
{
// 如果需要每次切过来都刷新数据,可以调用 select()
// pageRecords->refreshData(); // 需要你在 RecordsDialog 可以在 public 里加个刷新函数
ui->stackedWidget->setCurrentIndex(1);
}
// 切换到“仓库信息”
void MasterView::on_btnPageWarehouse_clicked()
{
// 切换到索引 2
ui->stackedWidget->setCurrentIndex(2);
// 可选:每次切过来都刷新一下数据
pageWarehouse->refreshData();
}