-
Notifications
You must be signed in to change notification settings - Fork 0
/
addbook.cpp
92 lines (82 loc) · 2.21 KB
/
addbook.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
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
84
85
86
87
88
89
90
91
92
#include "addbook.h"
#include "ui_addbook.h"
#include <QFileDialog>
#include <QFile>
#include <QDebug>
#include <QMessageBox>
#include <QFileInfo>
AddBook::AddBook(SqlClient *sql, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddBook)
{
ui->setupUi(this);
winTag=new AddTag(sql,this);
connect(winTag,SIGNAL(addedTag()),this,SLOT(tagsChanged()));
ui->file_tbl->setColumnWidth(0,ui->file_tbl->width()*3);
_tags= sql->getTags();
for (int i=0; i<_tags.count();++i)
{
ui->ln_tags->addItem(_tags.value(i).second);
}
}
AddBook::~AddBook()
{
delete ui;
delete winTag;
}
void AddBook::on_pushButton_clicked()
{
fileList = QFileDialog::getOpenFileNames(this);
qDebug()<<fileList<<fileList.count();
ui->file_tbl->setRowCount(fileList.count());
for(int i=0; i< fileList.count();++i)
{
QFileInfo info;
info.setFile(fileList[i]);
ui->file_tbl->setItem(i,0,new QTableWidgetItem(info.fileName()));
ui->file_tbl->setItem(i,1,new QTableWidgetItem(QString::number((float)info.size()/1024,'f',2)+"Kb"));
}
}
void AddBook::on_pushButton_2_clicked()
{
int row=ui->file_tbl->currentRow();
if(row>-1)
ui->file_tbl->removeRow(row);
}
void AddBook::on_buttonBox_accepted()
{
if(ui->ln_tags->getDisplayText()=="")
{
QMessageBox::warning(this,"Ошибка! ","Проверьте заполненость полей",
QMessageBox::Ok);
return;
}
_book=new book;
_book->author=ui->ln_author->text();
_book->theme=ui->ln_theme->text();
QString tags=ui->ln_tags->getDisplayText();
QStringList tagList=tags.split(",");
QList<int> indexTag;
for (int i=0; i<tagList.count();++i)
{
for (int j=0; j<_tags.count();++j)
if(tagList.at(i)==_tags.at(j).second)
indexTag.append(_tags.at(j).first);
}
_book->tags=indexTag;
_book->files=fileList;
emit newBook(_book);
}
void AddBook::on_pushButton_3_clicked()
{
winTag->show();
}
void AddBook::tagsChanged()
{
_tags= _sql->getTags();
ui->ln_tags->clear();
for (int i=0; i<_tags.count();++i)
{
ui->ln_tags->addItem(_tags.value(i).second);
}
}