adding pdf pagecount to presentationmodel
This commit is contained in:
parent
92891128fe
commit
f6b6fa8911
2 changed files with 45 additions and 2 deletions
|
@ -33,6 +33,7 @@ static void createPresentationTable()
|
|||
" 'id' INTEGER NOT NULL,"
|
||||
" 'title' TEXT NOT NULL,"
|
||||
" 'filePath' TEXT NOT NULL,"
|
||||
" 'pageCount' INTEGER,"
|
||||
" PRIMARY KEY(id))")) {
|
||||
qFatal("Failed to query database: %s",
|
||||
qPrintable(query.lastError().text()));
|
||||
|
@ -74,10 +75,11 @@ QHash<int, QByteArray> PresentationSqlModel::roleNames() const
|
|||
names[Qt::UserRole] = "id";
|
||||
names[Qt::UserRole + 1] = "title";
|
||||
names[Qt::UserRole + 2] = "filePath";
|
||||
names[Qt::UserRole + 3] = "pageCount";
|
||||
return names;
|
||||
}
|
||||
|
||||
void PresentationSqlModel::newPresentation(const QUrl &filePath) {
|
||||
void PresentationSqlModel::newPresentation(const QUrl &filePath, int pageCount) {
|
||||
qDebug() << "adding new presentation";
|
||||
int rows = rowCount();
|
||||
|
||||
|
@ -87,6 +89,7 @@ void PresentationSqlModel::newPresentation(const QUrl &filePath) {
|
|||
QString title = fileInfo.baseName();
|
||||
recordData.setValue("title", title);
|
||||
recordData.setValue("filePath", filePath);
|
||||
recordData.setValue("pageCount", pageCount);
|
||||
|
||||
if (insertRecord(rows, recordData)) {
|
||||
submitAll();
|
||||
|
@ -176,6 +179,40 @@ void PresentationSqlModel::updateFilePath(const int &row, const QUrl &filePath)
|
|||
emit filePathChanged();
|
||||
}
|
||||
|
||||
int PresentationSqlModel::pageCount() const {
|
||||
return m_pageCount;
|
||||
}
|
||||
|
||||
void PresentationSqlModel::setPageCount(const int &pageCount) {
|
||||
if (pageCount == m_pageCount)
|
||||
return;
|
||||
|
||||
m_pageCount = pageCount;
|
||||
|
||||
select();
|
||||
emit pageCountChanged();
|
||||
}
|
||||
|
||||
// This function is for updating the pageCount from outside the delegate
|
||||
void PresentationSqlModel::updatePageCount(const int &row, const int &pageCount) {
|
||||
qDebug() << "Row is " << row;
|
||||
QSqlQuery query("select id from presentations");
|
||||
QList<int> ids;
|
||||
while (query.next()) {
|
||||
ids.append(query.value(0).toInt());
|
||||
// qDebug() << ids;
|
||||
}
|
||||
int id = ids.indexOf(row,0);
|
||||
|
||||
QSqlRecord rowdata = record(id);
|
||||
qDebug() << rowdata;
|
||||
rowdata.setValue("pageCount", pageCount);
|
||||
setRecord(id, rowdata);
|
||||
qDebug() << rowdata;
|
||||
submitAll();
|
||||
emit pageCountChanged();
|
||||
}
|
||||
|
||||
QVariantMap PresentationSqlModel::getPresentation(const int &row) {
|
||||
// qDebug() << "Row we are getting is " << row;
|
||||
// QUrl presentation;
|
||||
|
|
|
@ -14,6 +14,7 @@ class PresentationSqlModel : public QSqlTableModel
|
|||
Q_PROPERTY(int id READ id)
|
||||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
||||
Q_PROPERTY(QUrl filePath READ filePath WRITE setFilePath NOTIFY filePathChanged)
|
||||
Q_PROPERTY(int pageCount READ pageCount WRITE setPageCount NOTIFY pageCountChanged)
|
||||
QML_ELEMENT
|
||||
|
||||
public:
|
||||
|
@ -22,14 +23,17 @@ public:
|
|||
int id() const;
|
||||
QString title() const;
|
||||
QUrl filePath() const;
|
||||
int pageCount() const;
|
||||
|
||||
void setTitle(const QString &title);
|
||||
void setFilePath(const QUrl &filePath);
|
||||
void setPageCount(const int &pageCount);
|
||||
|
||||
Q_INVOKABLE void updateTitle(const int &row, const QString &title);
|
||||
Q_INVOKABLE void updateFilePath(const int &row, const QUrl &filePath);
|
||||
Q_INVOKABLE void updatePageCount(const int &row, const int &pageCount);
|
||||
|
||||
Q_INVOKABLE void newPresentation(const QUrl &filePath);
|
||||
Q_INVOKABLE void newPresentation(const QUrl &filePath, int pageCount);
|
||||
Q_INVOKABLE void deletePresentation(const int &row);
|
||||
Q_INVOKABLE QVariantMap getPresentation(const int &row);
|
||||
|
||||
|
@ -39,11 +43,13 @@ public:
|
|||
signals:
|
||||
void titleChanged();
|
||||
void filePathChanged();
|
||||
void pageCountChanged();
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
QString m_title;
|
||||
QUrl m_filePath;
|
||||
int m_pageCount;
|
||||
};
|
||||
|
||||
#endif //PRESENTATIONSQLMODEL_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue