-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadditemwindow.cpp
More file actions
83 lines (74 loc) · 2.94 KB
/
Copy pathadditemwindow.cpp
File metadata and controls
83 lines (74 loc) · 2.94 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "additemwindow.h"
#include "ui_additemwindow.h"
#include "textbook.h"
#include "chapter.h"
#include "courselist.h"
#include <QDebug>
AddItemWindow::AddItemWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::AddItemWindow)
{
ui->setupUi(this);
}
AddItemWindow::~AddItemWindow()
{
delete ui;
}
void AddItemWindow::setMainWidget(MainWindow* window){
mainWidget = window;
}
void AddItemWindow::setLabelName(QString name){
ui->titleLabel->setText("Add New "+name);
}
void AddItemWindow::setButtonName(QString name){
ui->createBtn->setText("Create New "+name);
}
void AddItemWindow::on_createBtn_clicked()
{
QString name = ui->nameInput->text();
if(!name.isEmpty()){
//if parent is null then its a course
//otherwise keep searching for the parent and then add appropriately
if(mainWidget->getCurrentItem()->parent() != NULL){
//adding a chapter
int courseIndex = mainWidget->getCourseList().CourseIndex(mainWidget->getCurrentItem()->parent()->text(0));
if(courseIndex >= 0){
int textbookIndex = mainWidget->getCourseList().getCourse(courseIndex)->findIndex(mainWidget->getCurrentItem()->text(0));
if(textbookIndex >= 0){//make sure that the textbook exists
Chapter* chapter = new Chapter(name);
mainWidget->getCourseList().getCourse(courseIndex)->getTextbook(textbookIndex)->addChapter(chapter);
//add to treewidget
mainWidget->addChild(mainWidget->getCurrentItem(),name);
//make directory for it
QString path = mainWidget->getProjectPath() + +"/"+ mainWidget->getParentNames(mainWidget->getCurrentItem()) + "/";
QDir dir(path);
if(!dir.exists(name)){
dir.mkdir(name);
}else{
qDebug() << "Dir Doesnt exist " << path;
}
}
}
}else{
//adding a textbook
int courseIndex = mainWidget->getCourseList().CourseIndex(mainWidget->getCurrentItem()->text(0));
if(courseIndex >= 0){
Textbook* temp = new Textbook();
temp->setTextbookName(name);
mainWidget->getCourseList().getCourse(courseIndex)->addTextbook(temp);
//add to treewidget
mainWidget->addChild(mainWidget->getCurrentItem(),name);
//make directory for it
QString path = mainWidget->getProjectPath() + +"/"+ mainWidget->getParentNames(mainWidget->getCurrentItem()) + "/";
QDir dir(path);
if(!dir.exists(name)){
dir.mkdir(name);
}else{
qDebug() << "Dir Doesnt exist " << path;
}
}
}
//reset input
ui->nameInput->setText("");
}
}