Header file
------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
{
Q_OBJECT
public:
~MainWindow();
private:
Ui::MainWindow *ui;
private:
//! To collect the list of classrooms and computers added to the coressponding classroom
QList<QTreeWidgetItem *> *m_ClassRoom;
QList<QTreeWidgetItem *> m_computersAddedToCalssroom;
QList<QTreeWidgetItem *> temp;
private slots:
//! To add Computers
void addComputers();
//! To add classroom
void addClassRoom();
private slots:
//! To handle the right click event in The right side bar
void ContextMenuDisplayMethod
(const QPoint &);
private:
private:
//! treewidget context menu
QList<QAction *> actionsList;
private:
//SingleClass SingleClassobj;
//! To add sub Items in tree widget
//! To add sub Items in tree widget
int * index;
};
#endif // MAINWINDOW_H
.cpp File
----
void addComputersToClassroom()
{
m_clientSettingsDlgobj.exec();
m_strIpEntered = m_clientSettingsDlgobj.getIP();;
m_strClassRoomSel = m_clientSettingsDlgobj.getSelClassRoom();
qDebug()<< "MainWindow::addComputers IP Entered : "<<m_strIpEntered;
qDebug()<< "MainWindow::addComputers Cls Room entered : "<<m_strClassRoomSel;
temp = ui->treeWidget->findItems(m_strClassRoomSel , Qt::MatchExactly);
qDebug()<< "MainWindow::addComputers top level size: "<<ui->treeWidget->topLevelItemCount();
for(int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
{
if(ui->treeWidget->topLevelItem(i)->text(0) == m_strClassRoomSel)
{
qDebug()<< "MainWindow::addComputers : Inside the iterator: ";
m_Childlist->setText(0, m_strIpEntered);
m_Childlist->setText(1, m_strIpEntered);
index = new int;
ui->treeWidget->setCurrentItem(temp.at(0));
*m_modelIndex = (ui->treeWidget->currentIndex());
*index = (m_modelIndex->data().toInt());
qDebug()<<"index : "<<*index;// I'm getting the index
m_treelist->insertChild(*index,m_Childlist);// This is not adding the child to classroom
return;
}
}
}
void addClassRoom()
{
bool bOk = false;
tr( "New classroom" ),
tr( "Please enter the name of the classroom you "
"want to create." ),
QLineEdit::Normal, tr
( "New classroom" ),
&bOk
);
if(!classroom_name.isEmpty())
{
bool bTemp = false;
for(int i = 0; i < m_strlistComputer.size(); i++)
{
if(m_strlistComputer.at(i) == classroom_name)
bTemp = true;
}
if(bTemp == false)
{
m_strlistComputer.append(classroom_name);
m_treelist->setText(0,classroom_name);
m_ClassRoom->append(m_treelist);
ui->treeWidget->addTopLevelItem(m_treelist);
}
}
}
Header file
------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private:
//! To collect the list of classrooms and computers added to the coressponding classroom
QList<QTreeWidgetItem *> *m_ClassRoom;
QList<QTreeWidgetItem *> m_computersAddedToCalssroom;
QStringList m_strlistComputer;
QTreeWidgetItem *m_treelist;//(m_strlistComputer);
QList<QTreeWidgetItem *> temp;
private slots:
//! To add Computers
void addComputers();
//! To add classroom
void addClassRoom();
private slots:
//! To handle the right click event in The right side bar
void ContextMenuDisplayMethod(const QPoint &);
private:
QMenu contextMenu;
private:
//! treewidget context menu
QAction * actionClassroom;
QAction * actionComputer;
QList<QAction *> actionsList;
private:
//SingleClass SingleClassobj;
QString m_strIpEntered;
QString m_strClassRoomSel;
//! To add sub Items in tree widget
QModelIndex *m_modelIndex;
//! To add sub Items in tree widget
QTreeWidgetItem *m_Childlist ;
int * index;
};
#endif // MAINWINDOW_H
.cpp File
----
void addComputersToClassroom()
{
m_clientSettingsDlgobj.exec();
m_strIpEntered = m_clientSettingsDlgobj.getIP();;
m_strClassRoomSel = m_clientSettingsDlgobj.getSelClassRoom();
qDebug()<< "MainWindow::addComputers IP Entered : "<<m_strIpEntered;
qDebug()<< "MainWindow::addComputers Cls Room entered : "<<m_strClassRoomSel;
temp = ui->treeWidget->findItems(m_strClassRoomSel , Qt::MatchExactly);
qDebug()<< "MainWindow::addComputers top level size: "<<ui->treeWidget->topLevelItemCount();
QTreeWidgetItemIterator it(ui->treeWidget);
for(int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
{
if(ui->treeWidget->topLevelItem(i)->text(0) == m_strClassRoomSel)
{
qDebug()<< "MainWindow::addComputers : Inside the iterator: ";
m_Childlist = new QTreeWidgetItem;
m_Childlist->setText(0, m_strIpEntered);
m_Childlist->setText(1, m_strIpEntered);
index = new int;
m_modelIndex = new QModelIndex;
ui->treeWidget->setCurrentItem(temp.at(0));
*m_modelIndex = (ui->treeWidget->currentIndex());
*index = (m_modelIndex->data().toInt());
qDebug()<<"index : "<<*index;// I'm getting the index
m_treelist->insertChild(*index,m_Childlist);// This is not adding the child to classroom
return;
}
}
}
void addClassRoom()
{
bool bOk = false;
QString classroom_name = QInputDialog::getText( this,
tr( "New classroom" ),
tr( "Please enter the name of the classroom you "
"want to create." ),
QLineEdit::Normal, tr( "New classroom" ), &bOk );
if(!classroom_name.isEmpty())
{
bool bTemp = false;
for(int i = 0; i < m_strlistComputer.size(); i++)
{
if(m_strlistComputer.at(i) == classroom_name)
bTemp = true;
}
if(bTemp == false)
{
m_strlistComputer.append(classroom_name);
m_treelist = new QTreeWidgetItem;
m_treelist->setText(0,classroom_name);
m_ClassRoom->append(m_treelist);
ui->treeWidget->addTopLevelItem(m_treelist);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks