#include "gui.hpp" #include #include MainGUI::MainGUI(const TGWindow* p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h) { SetCleanup(kDeepCleanup); // ---- Main layout TGHorizontalFrame* hframe = new TGHorizontalFrame(this); AddFrame(hframe, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // ---- Sidebar sidebar = new TGVerticalFrame(hframe, 250); hframe->AddFrame(sidebar, new TGLayoutHints(kLHintsLeft | kLHintsExpandY)); sidebar->AddFrame( new TGLabel(sidebar, "Database Tables"), new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5) ); treeCanvas = new TGCanvas(sidebar, 200, 400); sidebar->AddFrame( treeCanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) ); tree = new TGListTree(treeCanvas->GetViewPort()); treeCanvas->SetContainer(tree); TGTextButton* reloadBtn = new TGTextButton(sidebar, "Reload Catalog"); sidebar->AddFrame( reloadBtn, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5) ); reloadBtn->Connect( "Clicked()", "MainGUI", this, "OnReloadCatalog()" ); // ---- Main panel mainPanel = new TGVerticalFrame(hframe); hframe->AddFrame(mainPanel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); mainPanel->AddFrame( new TGLabel(mainPanel, "Column Selection"), new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5) ); // ---- Tree signal tree->Connect( "Clicked(TGListTreeItem*,Int_t)", "MainGUI", this, "OnTreeClick(TGListTreeItem*,Int_t)" ); // ---- Initial load loadCatalogTables("../../config.json"); SetWindowName("My GUI"); MapSubwindows(); Resize(GetDefaultSize()); MapWindow(); Connect("CloseWindow()", "TApplication", gApplication, "Terminate()"); } MainGUI::~MainGUI() { Cleanup(); } void MainGUI::loadCatalogTables(const std::string& configPath) { nodes = loadAllNodes(configPath); const TGPicture* leafIcon = gClient->GetPicture("doc_t.xpm"); for (const auto& n : nodes) { std::string tableLabel = n.database + " | " + n.schema + "." + n.name; TGListTreeItem* tableItem = tree->AddItem(nullptr, tableLabel.c_str()); for (size_t i = 0; i < n.columns.size(); ++i) { std::string colLabel = n.columns[i] + " (" + n.datatypes[i] + ")"; TGListTreeItem* colItem = tree->AddItem(tableItem, colLabel.c_str()); colItem->SetPictures(leafIcon, leafIcon); } tree->CloseItem(tableItem); } } void MainGUI::OnReloadCatalog() { std::cout << "Reload clicked\n"; tree->DeleteChildren(nullptr); loadCatalogTables("../../config.json"); tree->MapSubwindows(); treeCanvas->Layout(); treeCanvas->MapWindow(); } void MainGUI::OnTreeClick(TGListTreeItem* item, Int_t) { if (!item) return; std::cout << "Clicked: " << item->GetText() << std::endl; } ClassImp(MainGUI);