making future proof refactor of image and video get system

This commit is contained in:
Chris Cochrun 2022-04-11 14:04:03 -05:00
parent 8d07c7355d
commit f1378cc1ff
8 changed files with 72 additions and 44 deletions

View file

@ -157,13 +157,28 @@ void ImageSqlModel::updateFilePath(const int &row, const QUrl &filePath) {
emit filePathChanged();
}
QUrl ImageSqlModel::getImage(const int &row) {
qDebug() << "Row we are getting is " << row;
QUrl image;
QSqlRecord rec = record(row);
qDebug() << rec.value("filePath").toUrl();
// image.append(rec.value("title"));
// image.append(rec.value("filePath"));
image = rec.value("filePath").toUrl();
return image;
QVariantMap ImageSqlModel::getImage(const int &row) {
// qDebug() << "Row we are getting is " << row;
// QUrl image;
// QSqlRecord rec = record(row);
// qDebug() << rec.value("filePath").toUrl();
// // image.append(rec.value("title"));
// // image.append(rec.value("filePath"));
// image = rec.value("filePath").toUrl();
// return image;
QVariantMap data;
const QModelIndex idx = this->index(row,0);
// qDebug() << idx;
if( !idx.isValid() )
return data;
const QHash<int,QByteArray> rn = roleNames();
// qDebug() << rn;
QHashIterator<int,QByteArray> it(rn);
while (it.hasNext()) {
it.next();
qDebug() << it.key() << ":" << it.value();
data[it.value()] = idx.data(it.key());
}
return data;
}

View file

@ -31,7 +31,7 @@ public:
Q_INVOKABLE void newImage(const QUrl &filePath);
Q_INVOKABLE void deleteImage(const int &row);
Q_INVOKABLE QUrl getImage(const int &row);
Q_INVOKABLE QVariantMap getImage(const int &row);
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;

View file

@ -43,18 +43,6 @@ Item {
implicitWidth: 100
hoverEnabled: true
}
Controls.ToolButton {
text: "B"
hoverEnabled: true
}
Controls.ToolButton {
text: "I"
hoverEnabled: true
}
Controls.ToolButton {
text: "U"
hoverEnabled: true
}
Controls.ToolSeparator {}
Item { Layout.fillWidth: true }
Controls.ToolSeparator {}
@ -66,7 +54,7 @@ Item {
}
Controls.ToolButton {
id: backgroundButton
text: "Background"
text: "Select Image"
icon.name: "fileopen"
hoverEnabled: true
onClicked: backgroundType.open()
@ -175,7 +163,7 @@ Item {
}
function changeImage(image) {
root.image = image;
print(image.toString());
root.image = image.filePath;
print(image.filePath.toString());
}
}

View file

@ -820,7 +820,7 @@ Item {
videoLibraryList.currentIndex = videosqlmodel.rowCount();
print(videosqlmodel.getVideo(videoLibraryList.currentIndex));
const video = videosqlmodel.getVideo(videoLibraryList.currentIndex);
showPassiveNotification("newest video: " + video);
showPassiveNotification("newest video: " + video.title);
if (!editMode)
editMode = true;
editSwitch("video", video);

View file

@ -138,7 +138,7 @@ Item {
Layout.rightMargin: 20
placeholderText: "Song Title..."
text: video[0]
text: video.title
padding: 10
/* onEditingFinished: updateTitle(text); */
}
@ -170,7 +170,7 @@ Item {
Component.onCompleted: mpvLoadingTimer.start()
onPositionChanged: videoSlider.value = position
onFileLoaded: {
showPassiveNotification(video[0] + " has been loaded");
showPassiveNotification(video.title + " has been loaded");
videoPreview.pause();
}
}
@ -220,7 +220,7 @@ Item {
id: mpvLoadingTimer
interval: 100
onTriggered: {
videoPreview.loadFile(video[1].toString());
videoPreview.loadFile(video.filePath.toString());
/* showPassiveNotification(video[0]); */
}
}

View file

@ -156,12 +156,28 @@ void VideoSqlModel::updateFilePath(const int &row, const QUrl &filePath) {
emit filePathChanged();
}
QVariantList VideoSqlModel::getVideo(const int &row) {
qDebug() << "Row we are getting is " << row;
QVariantList video;
QSqlRecord rec = record(row);
qDebug() << rec.value("title");
video.append(rec.value("title"));
video.append(rec.value("filePath"));
return video;
QVariantMap VideoSqlModel::getVideo(const int &row) {
// qDebug() << "Row we are getting is " << row;
// QVariantList video;
// QSqlRecord rec = record(row);
// qDebug() << rec.value("title");
// video.append(rec.value("title"));
// video.append(rec.value("filePath"));
// return video;
QVariantMap data;
const QModelIndex idx = this->index(row,0);
// qDebug() << idx;
if( !idx.isValid() )
return data;
const QHash<int,QByteArray> rn = roleNames();
// qDebug() << rn;
QHashIterator<int,QByteArray> it(rn);
while (it.hasNext()) {
it.next();
qDebug() << it.key() << ":" << it.value();
data[it.value()] = idx.data(it.key());
}
return data;
}

View file

@ -31,7 +31,7 @@ public:
Q_INVOKABLE void newVideo(const QUrl &filePath);
Q_INVOKABLE void deleteVideo(const int &row);
Q_INVOKABLE QVariantList getVideo(const int &row);
Q_INVOKABLE QVariantMap getVideo(const int &row);
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;