|
| 1 | +// Author : XuBenHao |
| 2 | +// Version : 1.0.0 |
| 3 | +// Mail : xbh370970843@163.com |
| 4 | +// Copyright : XuBenHao 2020 - 2030 |
| 5 | + |
| 6 | +#include "praticalarraylistwidget.h" |
| 7 | +#include "ui_praticalarraylistwidget.h" |
| 8 | +#include "Ui/Dialog/Array/createarraydialog.h" |
| 9 | +PraticalArrayListWidget::PraticalArrayListWidget(QWidget *parent) : |
| 10 | + QWidget(parent), |
| 11 | + ui(new Ui::PraticalArrayListWidget) |
| 12 | +{ |
| 13 | + ui->setupUi(this); |
| 14 | + Initialize(); |
| 15 | +} |
| 16 | + |
| 17 | +PraticalArrayListWidget::~PraticalArrayListWidget() |
| 18 | +{ |
| 19 | + delete ui; |
| 20 | +} |
| 21 | + |
| 22 | +void PraticalArrayListWidget::Initialize() |
| 23 | +{ |
| 24 | + connect(ui->pre, SIGNAL(clicked(bool)), this, SLOT(Pre(bool))); |
| 25 | + connect(ui->deleteArray, SIGNAL(clicked(bool)), this, SLOT(DeleteArray(bool))); |
| 26 | + connect(ui->createArray, SIGNAL(clicked(bool)), this, SLOT(CreateArray(bool))); |
| 27 | + |
| 28 | + theModel = new QStandardItemModel(this); |
| 29 | + ui->listView->setModel(theModel); |
| 30 | + ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); |
| 31 | + /*QStringList::iterator i; |
| 32 | + for (int i = 0; i < 2; i++) |
| 33 | + { |
| 34 | + QStandardItem* pItem = new QStandardItem(); |
| 35 | + pItem->setData(_arrPairs[i].first, Qt::DisplayRole); |
| 36 | + pItem->setData(_arrPairs[i].second, Qt::UserRole); |
| 37 | + theModel->appendRow(pItem); |
| 38 | + }*/ |
| 39 | + |
| 40 | + // register signal-slot |
| 41 | + connect(ui->listView, |
| 42 | + SIGNAL(doubleClicked(QModelIndex)), |
| 43 | + this, |
| 44 | + SLOT(ListClicked(QModelIndex))); |
| 45 | +} |
| 46 | + |
| 47 | +void PraticalArrayListWidget::Pre(bool checked_) |
| 48 | +{ |
| 49 | + Q_UNUSED(checked_); |
| 50 | + emit ShowDataStruct(QString("Array"), QVariant()); |
| 51 | +} |
| 52 | + |
| 53 | +void PraticalArrayListWidget::DeleteArray(bool checked_) |
| 54 | +{ |
| 55 | + Q_UNUSED(checked_); |
| 56 | + QModelIndex _nIndex = ui->listView->currentIndex(); |
| 57 | + QStandardItem* _pItem = theModel->itemFromIndex(_nIndex); |
| 58 | + int _nId = _nIndex.row(); |
| 59 | + if(_nId < 0 || _nId >= theModel->rowCount()) |
| 60 | + { |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + QVariant _nVar = _pItem->data(Qt::UserRole); |
| 65 | + int _nCapacity = _nVar.toInt(); |
| 66 | + QString _strFile = NModelManager::ModelManager::GetPraticalArrayModelFilePath(_nId, _nCapacity); |
| 67 | + QFile::remove(_strFile); |
| 68 | + theModel->removeRow(_nId); |
| 69 | +} |
| 70 | + |
| 71 | +void PraticalArrayListWidget::CreateArray(bool checked_) |
| 72 | +{ |
| 73 | + Q_UNUSED(checked_); |
| 74 | + CreateArrayDialog *_pCreateArrDia = new CreateArrayDialog(this); |
| 75 | + int _nRet = _pCreateArrDia->exec(); |
| 76 | + if(_nRet == QDialog::Accepted) |
| 77 | + { |
| 78 | + int _nCapacity = _pCreateArrDia->GetCapacity(); |
| 79 | + QStandardItem* pItem = new QStandardItem(); |
| 80 | + pItem->setData(_nCapacity, Qt::DisplayRole); |
| 81 | + pItem->setData(_nCapacity, Qt::UserRole); |
| 82 | + theModel->appendRow(pItem); |
| 83 | + } |
| 84 | + |
| 85 | + delete _pCreateArrDia; |
| 86 | +} |
| 87 | + |
| 88 | +void PraticalArrayListWidget::ListClicked(const QModelIndex& index) |
| 89 | +{ |
| 90 | + Q_UNUSED(index); |
| 91 | + QVariant var = theModel->data(index, Qt::UserRole); |
| 92 | + int _nCapacity = var.toInt(); |
| 93 | + ArrayItem _nItem; |
| 94 | + _nItem.m_nCapacity = _nCapacity; |
| 95 | + _nItem.m_nId = index.row(); |
| 96 | + |
| 97 | + emit ShowDataStruct( |
| 98 | + QString("PraticalArray"), |
| 99 | + QVariant::fromValue(_nItem)); |
| 100 | +} |
0 commit comments