-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cpp
58 lines (53 loc) · 2.06 KB
/
MainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "MainWindow.hpp"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent)
,ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->treeCategories, SIGNAL(itemSelectionChanged()), this, SLOT(categoryChanged()));
connect(ui->treeCategories, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(repositoryExpanded(QTreeWidgetItem*)));
ui->treeCategories->clear();
for(Portage::Repositories::const_iterator iter = m_Portage.getRepositories().constBegin(); iter != m_Portage.getRepositories().constEnd(); ++iter)
{
QTreeWidgetItem* twItem = new QTreeWidgetItem(QStringList(iter->getName()));
twItem->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
ui->treeCategories->addTopLevelItem(twItem);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::categoryChanged()
{
QTreeWidgetItem* selected = ui->treeCategories->selectedItems().first();
if(selected->parent())
{
Portage::Packages packages = m_Portage.getRepository(selected->parent()->text(0)).getPackages(selected->text(0));
ui->treePackages->clear();
for(Portage::Packages::const_iterator iter = packages.constBegin(); iter != packages.constEnd(); ++iter)
{
QTreeWidgetItem* twItem = new QTreeWidgetItem();
twItem->setText(1, *iter);
twItem->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
ui->treePackages->addTopLevelItem(twItem);
}
}
else
{
//selected->setSelected(false);
}
}
void MainWindow::repositoryExpanded(QTreeWidgetItem * item)
{
if(item->childCount() == 0)
{
Repository::Categories setCategories = m_Portage.getRepository(item->text(0)).getCategories();
for(Portage::Categories::const_iterator sub_iter = setCategories.constBegin(); sub_iter != setCategories.constEnd(); ++sub_iter)
{
QTreeWidgetItem* twSubItem = new QTreeWidgetItem(item, QStringList(*sub_iter));
ui->treeCategories->addTopLevelItem(twSubItem);
}
}
}