|
| 1 | +// Author : XuBenHao |
| 2 | +// Version : 1.0.0 |
| 3 | +// Mail : xbh370970843@163.com |
| 4 | +// Copyright : XuBenHao 2020 - 2030 |
| 5 | + |
| 6 | +#include "datastructwidget.h" |
| 7 | +#include "ui_datastructwidget.h" |
| 8 | +#include "Functions/datastructfactory.h" |
| 9 | +DataStructWidget::DataStructWidget(QWidget *parent) : |
| 10 | + QWidget(parent), |
| 11 | + ui(new Ui::DataStructWidget) |
| 12 | +{ |
| 13 | + ui->setupUi(this); |
| 14 | + Initial(); |
| 15 | +} |
| 16 | + |
| 17 | +DataStructWidget::~DataStructWidget() |
| 18 | +{ |
| 19 | + delete ui; |
| 20 | +} |
| 21 | + |
| 22 | +void DataStructWidget::Initial() |
| 23 | +{ |
| 24 | + QPair<QString, QString> _arrPairs[2] = |
| 25 | + { |
| 26 | + QPair<QString, QString>("数组", "Array"), |
| 27 | + QPair<QString, QString>("链表", "List"), |
| 28 | + }; |
| 29 | + |
| 30 | + /*QStringList theStrings; |
| 31 | + theStrings << "数组" << "链表" << "栈" << "队列"; |
| 32 | + theStrings << "堆" << "优先队列" << "哈希表" << "二叉树"; |
| 33 | + theStrings << "二叉搜索树" << "红黑树" << "BTree" << "BPlusTree"; |
| 34 | + theStrings << "Graph";*/ |
| 35 | + |
| 36 | + theModel = new QStandardItemModel(this); |
| 37 | + ui->listView->setModel(theModel); |
| 38 | + ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); |
| 39 | + QStringList::iterator i; |
| 40 | + for (int i = 0; i < 2; i++) |
| 41 | + { |
| 42 | + QStandardItem* pItem = new QStandardItem(); |
| 43 | + pItem->setData(_arrPairs[i].first, Qt::DisplayRole); |
| 44 | + pItem->setData(_arrPairs[i].second, Qt::UserRole); |
| 45 | + theModel->appendRow(pItem); |
| 46 | + } |
| 47 | + |
| 48 | + // register signal-slot |
| 49 | + connect(ui->listView, |
| 50 | + SIGNAL(doubleClicked(QModelIndex)), |
| 51 | + this, |
| 52 | + SLOT(ListClicked(QModelIndex))); |
| 53 | + //connect(this,SIGNAL(DataStructShow(QWidget*)),parent(),SLOT(AddChildWidget(QWidget*))); |
| 54 | +} |
| 55 | + |
| 56 | +void DataStructWidget::ListClicked(const QModelIndex& index) |
| 57 | +{ |
| 58 | + // how to do |
| 59 | + // emit signal to parent's window,parameter is the name of wanted window |
| 60 | + QVariant var = theModel->data(index, Qt::UserRole); |
| 61 | + emit ShowDataStruct(var.toString()); |
| 62 | + //DataStructFactory* dataFactor = DataStructFactory::Instance(); |
| 63 | + //QWidget* pParent = parentWidget(); |
| 64 | + //QWidget* widget = dataFactor->GetDataStructWidget(var.toString(), pParent); |
| 65 | + //MainWindow::Instance()->AddChildWidget(widget); |
| 66 | + //this->hide(); |
| 67 | + //widget->show(); |
| 68 | +} |
0 commit comments