void MainWindow::appendixCategory(){ parentItem = new QStandardItem(); parentItem->setText(nameCategory->text()); model->setItem(model->rowCount(),0, parentItem);}
void MainWindow::appendixWWW(){ childItem = new QStandardItem(); childItem->setText(linkWWW->text()); parentItem->setChild(parentItem->rowCount(),childItem); }
void MainWindow::mousePressEvent(QMouseEvent *event){ if (event->button() == Qt::LeftButton) { QModelIndex ind = ui->treeView->indexAt(event->pos()); if (ind.isValid()) { appendixWWW(); } } MainWindow::mousePressEvent(event);}//Добавление категории в модельvoid MainWindow::appendixCategory(){ parentItem = new QStandardItem(); parentItem->setText(nameCategory->text()); model->setItem(model->rowCount(),0, parentItem);}// Добавление потомка в категориюvoid MainWindow::appendixWWW(){ childItem = new QStandardItem(); childItem->setText(linkWWW->text()); parentItem->setChild(parentItem->rowCount(),childItem); }
void MainWindow::addChild(){ qDebug()<<"Slot activ"; QModelIndex index = ui->treeView->selectionModel()->currentIndex(); QAbstractItemModel *model = ui->treeView->model(); if (model->columnCount(index) == 0) { if (!model->insertColumn(0, index)) { return; } } if (!model->insertRow(0, index)) { return; }int column = ui->treeView->selectionModel()->currentIndex().column();int row=ui->treeView->selectionModel()->currentIndex().row(); model->setData(model->index(row, column, index), QVariant(linkWWW->text()), Qt::EditRole); model->insertColumn(column +1, index); model->setData(model->index(row, column + 1, index), QVariant(nameWWW->text()), Qt::EditRole); model->insertColumn(column +2, index); model->setData(model->index(row, column + 2, index), QVariant(tegWWW->text()), Qt::EditRole); model->insertColumn(column +3, index); model->setData(model->index(row, column + 3, index), QVariant(tegWWW->text()), Qt::EditRole);}void MainWindow::insertRow(){ QModelIndex index = ui->treeView->selectionModel()->currentIndex(); QAbstractItemModel *model = ui->treeView->model(); if (!model->insertRow(index.row()+1, index.parent())) return; for (int column = 0; column < model->columnCount(index.parent()); ++column) { QModelIndex child = model->index(index.row()+1, column, index.parent()); model->setData(child, QVariant("[No data]"), Qt::EditRole); }}