Skip to content

Commit ec91b05

Browse files
committed
init
0 parents  commit ec91b05

File tree

13 files changed

+775
-0
lines changed

13 files changed

+775
-0
lines changed

addbook.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "addbook.h"
2+
#include "ui_addbook.h"
3+
#include <QFileDialog>
4+
#include <QFile>
5+
#include <QDebug>
6+
7+
AddBook::AddBook(QWidget *parent) :
8+
QDialog(parent),
9+
ui(new Ui::AddBook)
10+
{
11+
ui->setupUi(this);
12+
ui->file_tbl->setColumnWidth(0,ui->file_tbl->width()*3);
13+
}
14+
15+
AddBook::~AddBook()
16+
{
17+
delete ui;
18+
}
19+
20+
void AddBook::on_pushButton_clicked()
21+
{
22+
23+
fileList = QFileDialog::getOpenFileNames(this);
24+
qDebug()<<fileList<<fileList.count();
25+
ui->file_tbl->setRowCount(fileList.count());
26+
for(int i=0; i< fileList.count();++i)
27+
{
28+
QFile file;
29+
file.setFileName(fileList[i]);
30+
ui->file_tbl->setItem(i,0,new QTableWidgetItem(file.fileName()));
31+
ui->file_tbl->setItem(i,1,new QTableWidgetItem(QString::number((float)file.size()/1024,'f',2)+"Kb"));
32+
}
33+
34+
}
35+
36+
void AddBook::on_pushButton_2_clicked()
37+
{
38+
int row=ui->file_tbl->currentRow();
39+
if(row>-1)
40+
ui->file_tbl->removeRow(row);
41+
}
42+
43+
void AddBook::on_buttonBox_accepted()
44+
{
45+
_book=new book;
46+
_book->author=ui->ln_author->text();
47+
_book->theme=ui->ln_theme->text();
48+
_book->tags=ui->ln_tags->text();
49+
_book->files=fileList;
50+
emit newBook(_book);
51+
}

addbook.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef ADDBOOK_H
2+
#define ADDBOOK_H
3+
4+
#include <QDialog>
5+
#include <QAbstractButton>
6+
#include "book.h"
7+
8+
namespace Ui {
9+
class AddBook;
10+
}
11+
12+
class AddBook : public QDialog
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit AddBook(QWidget *parent = 0);
18+
~AddBook();
19+
20+
signals:
21+
void newBook(book* _newBook);
22+
23+
private slots:
24+
void on_pushButton_clicked();
25+
26+
void on_pushButton_2_clicked();
27+
28+
void on_buttonBox_accepted();
29+
30+
private:
31+
book * _book;
32+
Ui::AddBook *ui;
33+
QStringList fileList;
34+
};
35+
36+
#endif // ADDBOOK_H

addbook.ui

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>AddBook</class>
4+
<widget class="QDialog" name="AddBook">
5+
<property name="windowModality">
6+
<enum>Qt::ApplicationModal</enum>
7+
</property>
8+
<property name="geometry">
9+
<rect>
10+
<x>0</x>
11+
<y>0</y>
12+
<width>400</width>
13+
<height>379</height>
14+
</rect>
15+
</property>
16+
<property name="windowTitle">
17+
<string>Dialog</string>
18+
</property>
19+
<property name="modal">
20+
<bool>true</bool>
21+
</property>
22+
<layout class="QVBoxLayout" name="verticalLayout_3">
23+
<item>
24+
<layout class="QHBoxLayout" name="horizontalLayout">
25+
<item>
26+
<layout class="QVBoxLayout" name="verticalLayout">
27+
<item>
28+
<widget class="QLabel" name="label">
29+
<property name="text">
30+
<string>Author</string>
31+
</property>
32+
</widget>
33+
</item>
34+
<item>
35+
<widget class="QLabel" name="label_2">
36+
<property name="text">
37+
<string>Theme</string>
38+
</property>
39+
</widget>
40+
</item>
41+
<item>
42+
<widget class="QLabel" name="label_3">
43+
<property name="text">
44+
<string>Tags</string>
45+
</property>
46+
</widget>
47+
</item>
48+
</layout>
49+
</item>
50+
<item>
51+
<layout class="QVBoxLayout" name="verticalLayout_2">
52+
<item>
53+
<widget class="QLineEdit" name="ln_author"/>
54+
</item>
55+
<item>
56+
<widget class="QLineEdit" name="ln_theme"/>
57+
</item>
58+
<item>
59+
<widget class="QLineEdit" name="ln_tags"/>
60+
</item>
61+
</layout>
62+
</item>
63+
</layout>
64+
</item>
65+
<item>
66+
<widget class="QTableWidget" name="file_tbl">
67+
<attribute name="horizontalHeaderStretchLastSection">
68+
<bool>true</bool>
69+
</attribute>
70+
<column>
71+
<property name="text">
72+
<string>File</string>
73+
</property>
74+
</column>
75+
<column>
76+
<property name="text">
77+
<string>Size</string>
78+
</property>
79+
</column>
80+
</widget>
81+
</item>
82+
<item>
83+
<layout class="QHBoxLayout" name="horizontalLayout_2">
84+
<item>
85+
<widget class="QPushButton" name="pushButton">
86+
<property name="text">
87+
<string>Add File</string>
88+
</property>
89+
</widget>
90+
</item>
91+
<item>
92+
<widget class="QPushButton" name="pushButton_2">
93+
<property name="text">
94+
<string>Delete File</string>
95+
</property>
96+
</widget>
97+
</item>
98+
</layout>
99+
</item>
100+
<item>
101+
<widget class="QDialogButtonBox" name="buttonBox">
102+
<property name="orientation">
103+
<enum>Qt::Horizontal</enum>
104+
</property>
105+
<property name="standardButtons">
106+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
107+
</property>
108+
</widget>
109+
</item>
110+
</layout>
111+
</widget>
112+
<resources/>
113+
<connections>
114+
<connection>
115+
<sender>buttonBox</sender>
116+
<signal>accepted()</signal>
117+
<receiver>AddBook</receiver>
118+
<slot>accept()</slot>
119+
<hints>
120+
<hint type="sourcelabel">
121+
<x>248</x>
122+
<y>254</y>
123+
</hint>
124+
<hint type="destinationlabel">
125+
<x>157</x>
126+
<y>274</y>
127+
</hint>
128+
</hints>
129+
</connection>
130+
<connection>
131+
<sender>buttonBox</sender>
132+
<signal>rejected()</signal>
133+
<receiver>AddBook</receiver>
134+
<slot>reject()</slot>
135+
<hints>
136+
<hint type="sourcelabel">
137+
<x>316</x>
138+
<y>260</y>
139+
</hint>
140+
<hint type="destinationlabel">
141+
<x>286</x>
142+
<y>274</y>
143+
</hint>
144+
</hints>
145+
</connection>
146+
</connections>
147+
</ui>

book.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef BOOK_H
2+
#define BOOK_H
3+
#include <QStringList>
4+
5+
struct book{
6+
QString author;
7+
QString theme;
8+
QString tags;
9+
QStringList files;
10+
};
11+
12+
#endif // BOOK_H

eBook.pro

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2014-07-12T18:23:59
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui sql
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = eBook
12+
TEMPLATE = app
13+
14+
15+
SOURCES += main.cpp\
16+
mainform.cpp \
17+
sqlclient.cpp \
18+
addbook.cpp \
19+
multilist.cpp
20+
21+
HEADERS += mainform.h \
22+
sqlclient.h \
23+
addbook.h \
24+
book.h \
25+
multilist.h
26+
27+
FORMS += mainform.ui \
28+
addbook.ui

main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "mainform.h"
2+
#include <QApplication>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
MainForm w;
8+
w.show();
9+
10+
return a.exec();
11+
}

mainform.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "mainform.h"
2+
#include "ui_mainform.h"
3+
#include "sqlclient.h"
4+
#include <QDebug>
5+
6+
7+
MainForm::MainForm(QWidget *parent) :
8+
QMainWindow(parent),
9+
ui(new Ui::MainForm)
10+
{
11+
ui->setupUi(this);
12+
13+
14+
15+
SqlClient sql;
16+
sql.getBooks();
17+
ui->bookView->setModel(sql.getBooks());
18+
ui->bookView->hideColumn(0);
19+
}
20+
21+
MainForm::~MainForm()
22+
{
23+
delete ui;
24+
}
25+
26+
27+
28+
void MainForm::on_bookView_pressed(const QModelIndex &index)
29+
{
30+
ui->bookView->selectRow(index.row());
31+
}
32+
33+
void MainForm::on_bookView_clicked(const QModelIndex &index)
34+
{
35+
ui->bookView->selectRow(index.row());
36+
}
37+
38+
void MainForm::accept()
39+
{
40+
qDebug()<<"add book";
41+
addBookForm->deleteLater();
42+
}
43+
44+
void MainForm::cancelAddBook()
45+
{
46+
qDebug()<<"cancel";
47+
addBookForm->deleteLater();
48+
}
49+
50+
void MainForm::addBook(book *_newBook)
51+
{
52+
newBook=_newBook;
53+
qDebug()<<newBook->author;
54+
}
55+
void MainForm::on_bt_addBook_clicked()
56+
{
57+
addBookForm= new AddBook(this);
58+
connect(addBookForm,SIGNAL(accepted()),this,SLOT(accept()));
59+
connect(addBookForm,SIGNAL(newBook(book*)),this,SLOT(addBook(book*)));
60+
connect(addBookForm,SIGNAL(rejected()),this,SLOT(cancelAddBook()));
61+
addBookForm->show();
62+
}
63+

mainform.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef MAINFORM_H
2+
#define MAINFORM_H
3+
4+
#include <QMainWindow>
5+
#include "addbook.h"
6+
#include "book.h"
7+
8+
namespace Ui {
9+
class MainForm;
10+
}
11+
12+
class MainForm : public QMainWindow
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit MainForm(QWidget *parent = 0);
18+
~MainForm();
19+
20+
private slots:
21+
22+
void on_bookView_pressed(const QModelIndex &index);
23+
24+
void on_bt_addBook_clicked();
25+
26+
void on_bookView_clicked(const QModelIndex &index);
27+
28+
void accept();
29+
void cancelAddBook();
30+
void addBook(book* _newBook);
31+
32+
private:
33+
Ui::MainForm *ui;
34+
AddBook *addBookForm;
35+
book *newBook;
36+
};
37+
38+
#endif // MAINFORM_H

0 commit comments

Comments
 (0)