-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (69 loc) · 2.37 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (69 loc) · 2.37 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
#include <QApplication>
#include <QMainWindow>
#include <QTableView>
#include <QStatusBar>
#include "FinancialProductModel.h"
#include "ProductListModel.h"
#include "Option.h"
#include "Swap.h"
class ProductDetailWindow : public QMainWindow {
public:
ProductDetailWindow(FinancialProduct* product, QWidget* parent = nullptr)
: QMainWindow(parent), m_product(product)
{
m_model = new FinancialProductModel(m_product, this);
m_tableView = new QTableView(this);
setCentralWidget(m_tableView);
m_tableView->setModel(m_model);
setWindowTitle(QString("Product Details - %1").arg(m_product->name()));
resize(600, 300);
connect(m_model, &FinancialProductModel::statusMessage,
statusBar(), [sb = statusBar()](const QString& msg) {
sb->showMessage(msg, 0);
});
}
private:
FinancialProduct* m_product;
FinancialProductModel* m_model;
QTableView* m_tableView;
};
class MainWindow : public QMainWindow {
public:
MainWindow(QWidget* parent = nullptr) : QMainWindow(parent) {
// Create products
m_products = {
new Option("Put Option", 50.0, 100, "Equity option",
120.0, "2024-12-31", 0.3, this),
new Swap("Interest Rate Swap", 0.05, 1000000,
"Fixed vs floating rate", 0.05, 1000000, this)
};
// Setup UI
m_tableView = new QTableView(this);
setCentralWidget(m_tableView);
setWindowTitle("Financial Products List");
resize(600, 300);
showProductList();
connect(m_tableView, &QTableView::doubleClicked,
this, &MainWindow::showProductDetails);
}
private:
void showProductList() {
m_listModel = new ProductListModel(m_products, this);
m_tableView->setModel(m_listModel);
m_tableView->setColumnWidth(0, 200);
m_tableView->setColumnWidth(1, 100);
}
void showProductDetails(const QModelIndex& index) {
auto detailWindow = new ProductDetailWindow(m_products[index.row()]);
detailWindow->show();
}
QVector<FinancialProduct*> m_products;
QTableView* m_tableView;
ProductListModel* m_listModel;
};
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
return app.exec();
}