160 lines
6.2 KiB
C++
160 lines
6.2 KiB
C++
#include "Demo_Gallery.h"
|
|
#include "YSGraphic_Core/Qt/File_Gather_Widget.h"
|
|
#include "YSGraphic_Core/Qt/File_Player_Widget.h"
|
|
#include "YSGraphic_Core/Qt/Value_Select.h"
|
|
#include <QtWidgets>
|
|
using namespace Psc;
|
|
QStandardItem* Demo_Gallery::getFromData(const TData& data) {
|
|
auto w = new QWidget;
|
|
auto l = new QVBoxLayout(w);
|
|
l->setContentsMargins({0, 0, 0, 0});
|
|
l->setSpacing(0);
|
|
l->addWidget(data.mPlot);
|
|
//l->addStretch();
|
|
mDataMap[data.mName] = w;
|
|
return new QStandardItem(data.mName);
|
|
}
|
|
QList<QStandardItem*> Demo_Gallery::getList(const QVector<TData>& datas) {
|
|
QList<QStandardItem*> ret;
|
|
for (const TData& data : datas) {
|
|
ret.append(getFromData(data));
|
|
}
|
|
return ret;
|
|
}
|
|
void Demo_Gallery::change_to(const QString& name) {
|
|
if (mDataMap.contains(name)) {
|
|
QWidget* associatedWidget = mDataMap[name];
|
|
int i = mTabWidget->indexOf(associatedWidget);
|
|
if (i == -1) {
|
|
// 标签页不存在,添加新的标签页
|
|
mTabWidget->addTab(associatedWidget, name);
|
|
mTabWidget->setCurrentIndex(mTabWidget->indexOf(associatedWidget));
|
|
}
|
|
else {
|
|
// 标签页已经存在,设置为当前标签页
|
|
mTabWidget->setCurrentIndex(i);
|
|
}
|
|
}
|
|
}
|
|
class ComboBoxExample : public QWidget {
|
|
public:
|
|
ComboBoxExample(QWidget* parent = nullptr) : QWidget(parent) {
|
|
// 创建一个QComboBox
|
|
QComboBox* comboBox = new QComboBox(this);
|
|
// 向QComboBox添加一些选项
|
|
comboBox->addItem("Option 1");
|
|
comboBox->addItem("Option 2");
|
|
comboBox->addItem("Option 3");
|
|
// 创建一个标签用来显示选中的选项
|
|
QLabel* label = new QLabel("Selected: ", this);
|
|
QObject::connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index) {
|
|
// 这里你可以获取当前选择项的索引
|
|
label->setText("Selected: " + comboBox->currentText());
|
|
});
|
|
// 布局
|
|
QVBoxLayout* layout = new QVBoxLayout;
|
|
layout->addWidget(comboBox);
|
|
layout->addWidget(label);
|
|
setLayout(layout);
|
|
}
|
|
};
|
|
Demo_Gallery::Demo_Gallery() :
|
|
treeView(new QTreeView(this)),
|
|
standardModel(new QStandardItemModel(this)),
|
|
mTabWidget(new QTabWidget) {
|
|
mMainLayout = new QHBoxLayout(this);
|
|
mMainLayout->setContentsMargins(0, 0, 0, 0);
|
|
mMainLayout->setSpacing(0);
|
|
treeView->setFixedWidth(200);
|
|
treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
mMainLayout->addWidget(treeView);
|
|
mTabWidget->setTabsClosable(true);
|
|
mMainLayout->addWidget(mTabWidget);
|
|
//treeView->setItemDelegate(new Delegate);
|
|
treeView->setHeaderHidden(true);
|
|
QStandardItem* root = standardModel->invisibleRootItem();
|
|
auto plottable = new QStandardItem("plottable");
|
|
plottable->appendRows(getList({
|
|
{"余晖图", createAfterglow()},
|
|
{"音频图", createAudioPlot()},
|
|
{"星座图", create_planisphere_plot()},
|
|
{"频谱图", create_spectrun_plot()},
|
|
{"瀑布图", create_Water_Fall_Plot()},
|
|
{"扫频图", create_sweep_frequent_plot()},
|
|
}));
|
|
auto base = new QStandardItem("基础元素");
|
|
base->appendRows(getList({
|
|
{"轴测试", createAxisTestPlot()},
|
|
{"时间轴测试", create_time_axis_test_plot()},
|
|
{"频率轴测试", create_frequent_axis_test_plot()},
|
|
{"多选框测试", create_Muti_Select_Plot()},
|
|
}));
|
|
auto t1 = new Byte_Select;
|
|
auto t2 = new Test_File_Gather_Widget;
|
|
auto t3 = new Test_File_Play_Widget;
|
|
auto custom_widget = new QStandardItem("自定义控件");
|
|
custom_widget->appendRows(getList({
|
|
{"Enum_Select", t1},
|
|
{"Test_File_Gather_Widget", t2},
|
|
{"Test_File_Play_Widget", t3},
|
|
{"表格", create_Table_View()},
|
|
{"树", create_Tree_View()},
|
|
}));
|
|
auto Qt_raw_widget = new QStandardItem("Qt原生元素");
|
|
Qt_raw_widget->appendRows(getList({
|
|
// QSizeGrip 一个改变大小的注脚
|
|
// QDesktopWidget 不知道干嘛的
|
|
// QFocusFrame 不知道干嘛的
|
|
{"QKeySequenceEdit", new QKeySequenceEdit},
|
|
{"ComboBoxExample", new ComboBoxExample},
|
|
//像QWidget 但不知到有什么区别
|
|
{"QPushButton", new QPushButton},
|
|
{"QFrame", new QFrame},
|
|
{"QStatusBar", new QStatusBar},
|
|
{"QGroupBox", new QGroupBox},
|
|
{"QSplashScreen", new QSplashScreen},
|
|
{"QAbstractSlider", new QAbstractSlider},
|
|
{"QRubberBand::Line", new QRubberBand(QRubberBand::Line)},
|
|
{"QRubberBand::Rectangle", new QRubberBand(QRubberBand::Rectangle)},
|
|
{"QProgressBar", new QProgressBar()},
|
|
{"QDialog", new QDialog},
|
|
{"QTabBar", new QTabBar},
|
|
{"QDialogButtonBox", new QDialogButtonBox},
|
|
{"QCalendarWidget", new QCalendarWidget},
|
|
{"QMenuBar", new QMenuBar},
|
|
{"QTabWidget", new QTabWidget},
|
|
{"QOpenGLWidget", new QOpenGLWidget},
|
|
{"QMdiSubWindow", new QMdiSubWindow},
|
|
{"QDockWidget", new QDockWidget},
|
|
{"QAbstractSpinBox", new QAbstractSpinBox},
|
|
//{"QAbstractButton", new QAbstractButton},
|
|
{"QTabBar", new QTabBar},
|
|
{"QComboBox", new QComboBox},
|
|
{"QMainWindow", new QMainWindow},
|
|
{"QMenu", new QMenu},
|
|
//{"QWindowContainer", new QWindowContainer},
|
|
//{"QDesktopScreenWidget", new QDesktopScreenWidget},
|
|
{"QColumnView", new QColumnView},
|
|
{"QWizardPage", new QWizardPage},
|
|
}));
|
|
//change_to("表格");
|
|
change_to("Test_File_Gather_Widget");
|
|
//change_to("树");
|
|
root->appendRows({plottable, base, custom_widget, Qt_raw_widget});
|
|
treeView->setModel(standardModel);
|
|
treeView->expandAll();
|
|
QObject::connect(mTabWidget, &QTabWidget::tabCloseRequested, [this](int index) {
|
|
// 处理标签页关闭请求
|
|
qDebug() << "Closing tab at index:" << index;
|
|
// 从 QTabWidget 中移除指定的标签页
|
|
mTabWidget->removeTab(index);
|
|
});
|
|
QObject::connect(treeView, &QTreeView::clicked, [this](const QModelIndex& index) {
|
|
QStandardItem* item = this->standardModel->itemFromIndex(index);
|
|
if (item) {
|
|
QString itemName = item->text();
|
|
change_to(itemName);
|
|
}
|
|
});
|
|
}
|