#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "addfile.h"
#include "addModel.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->treeView->setModel(model);
{
if (!docDoc.setContent(&file)) {
readFile(domElemNode);
}
file.close();
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
// Создание формы Ð´Ð»Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑÑылки
void MainWindow::on_pushButton_clicked()
{
messAdd_www->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
messAdd_www
->setFrameStyle
(QFrame::WinPanel |
QFrame::Raised);
messAdd_www->setLineWidth(2);
closeButton->setGeometry(120,180,90,30);
addButton->setGeometry(20,180,90,30);
messAdd_www->show();
[COLOR="red"]connect(ui->treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(addChild(const QModelIndex&))); [/COLOR]// THERE NOT WORKING
connect(addButton,SIGNAL(clicked()),messAdd_www,SLOT(close()));
connect(closeButton,SIGNAL(clicked()),messAdd_www,SLOT(close()));
}
// Создание формы Ð´Ð»Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÐºÐ°Ñ‚ÐµÐ³Ð¾Ñ€Ð¸Ð¸
void MainWindow::on_pushButton_2_clicked()
{
categoryAdd->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
categoryAdd
->setFrameStyle
(QFrame::WinPanel |
QFrame::Raised);
categoryAdd->setLineWidth(2);
closeCategory->setGeometry(120,180,90,30);
addCategory->setGeometry(20,180,90,30);
categoryAdd->show();
connect(addCategory,SIGNAL(clicked()),this,SLOT(appendixCategory()));
connect(addCategory,SIGNAL(clicked()),this,SLOT(addInFile()));
connect(addCategory,SIGNAL(clicked()),categoryAdd,SLOT(close()));
connect(closeCategory,SIGNAL(clicked()),categoryAdd,SLOT(close()));
}
void MainWindow
::on_tabWidget_currentChanged(QWidget* ) {
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "addfile.h"
#include "addModel.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model=new QStandardItemModel(0,4);
ui->treeView->setModel(model);
ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
QDomDocument docDoc;
QFile file("BDwww.xml");
if (!file.open(QIODevice::ReadOnly))
{
if (!docDoc.setContent(&file)) {
QDomElement domElemNode= docDoc.documentElement();
readFile(domElemNode);
}
file.close();
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
// Создание формы Ð´Ð»Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑÑылки
void MainWindow::on_pushButton_clicked()
{
QFrame *messAdd_www = new QFrame;
messAdd_www->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
messAdd_www->setGeometry(QRect(QPoint(QCursor::pos().x(), QCursor::pos().y()), QSize(250, 250)));
messAdd_www->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
messAdd_www->setLineWidth(2);
closeButton= new QPushButton ("Closse",messAdd_www);
closeButton->setGeometry(120,180,90,30);
addButton=new QPushButton(tr("Add"),messAdd_www);
addButton->setGeometry(20,180,90,30);
linkWWW= new QLineEdit(messAdd_www);
messAdd_www->show();
[COLOR="red"]connect(ui->treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(addChild(const QModelIndex&))); [/COLOR]// THERE NOT WORKING
connect(addButton,SIGNAL(clicked()),messAdd_www,SLOT(close()));
connect(closeButton,SIGNAL(clicked()),messAdd_www,SLOT(close()));
}
// Создание формы Ð´Ð»Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÐºÐ°Ñ‚ÐµÐ³Ð¾Ñ€Ð¸Ð¸
void MainWindow::on_pushButton_2_clicked()
{
QFrame *categoryAdd = new QFrame;
categoryAdd->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
categoryAdd->setGeometry(QRect(QPoint(QCursor::pos().x(), QCursor::pos().y()), QSize(250, 250)));
categoryAdd->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
categoryAdd->setLineWidth(2);
closeCategory= new QPushButton ("Closse",categoryAdd);
closeCategory->setGeometry(120,180,90,30);
addCategory=new QPushButton(tr("Add"),categoryAdd);
addCategory->setGeometry(20,180,90,30);
nameCategory= new QLineEdit(categoryAdd);
categoryAdd->show();
connect(addCategory,SIGNAL(clicked()),this,SLOT(appendixCategory()));
connect(addCategory,SIGNAL(clicked()),this,SLOT(addInFile()));
connect(addCategory,SIGNAL(clicked()),categoryAdd,SLOT(close()));
connect(closeCategory,SIGNAL(clicked()),categoryAdd,SLOT(close()));
}
void MainWindow::on_tabWidget_currentChanged(QWidget* )
{
}
To copy to clipboard, switch view to plain text mode
.h
#define ADDMODEL_H
#include "mainwindow.h"
// Добавление потомка в категорию
void MainWindow::appendixWWW(const QModelIndex&)
{
qDebug()<<"Slot activ";
childItem->setText(linkWWW->text());
parentItem->setChild(0,childItem);
}
//Добавление категории в модель
void MainWindow::appendixCategory()
{
parentItem->setText(nameCategory->text());
model->setItem(model->rowCount(),0, parentItem);
}
// Второй вариант Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¿Ð¾Ñ‚Ð¾Ð¼ÐºÐ°
void MainWindow::addChild(const QModelIndex&)
{
qDebug()<<"Slot activ";
QModelIndex index
= ui
->treeView
->selectionModel
()->currentIndex
();
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
{
return;
}
}
if (!model->insertRow(0, index))
{
return;
}
for (int column = 0; column < model->columnCount(index); ++column)
{
model
->setData
(child,
QVariant("[No data]"), Qt
::EditRole);
if (!model->headerData(column, Qt::Horizontal).isValid())
{
model
->setHeaderData
(column, Qt
::Horizontal,
QVariant("[No header]"),Qt
::EditRole);
}
}
}
#endif // ADDMODEL_H
#define ADDMODEL_H
#include "mainwindow.h"
// Добавление потомка в категорию
void MainWindow::appendixWWW(const QModelIndex&)
{
qDebug()<<"Slot activ";
childItem = new QStandardItem();
childItem->setText(linkWWW->text());
parentItem->setChild(0,childItem);
}
//Добавление категории в модель
void MainWindow::appendixCategory()
{
parentItem = new QStandardItem();
parentItem->setText(nameCategory->text());
model->setItem(model->rowCount(),0, parentItem);
}
// Второй вариант Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¿Ð¾Ñ‚Ð¾Ð¼ÐºÐ°
void MainWindow::addChild(const QModelIndex&)
{
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;
}
for (int column = 0; column < model->columnCount(index); ++column)
{
QModelIndex child = model->index(0, column, index);
model->setData(child, QVariant("[No data]"), Qt::EditRole);
if (!model->headerData(column, Qt::Horizontal).isValid())
{
model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"),Qt::EditRole);
}
}
}
#endif // ADDMODEL_H
To copy to clipboard, switch view to plain text mode
I've tried, and so the same problem slot is not called.
connect(ui->treeView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(addChild(const QItemSelection&,const QItemSelection&)));
connect(ui->treeView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(addChild(const QItemSelection&,const QItemSelection&)));
To copy to clipboard, switch view to plain text mode
Bookmarks