Skip to content

Commit 0cc7a59

Browse files
committed
Qt: convert PlaylistModel content rows from QHash to a typed struct
The Qt UI's playlist rows used to round-trip through QHash<QString,QString> with magic string keys ('path', 'label', 'core_path', etc.). This commit replaces that with a typed PlaylistEntry struct. The keys actually used at the call sites collapsed cleanly into 9 fields plus a row index. Other QHash<QString,QString> uses in the file (core-info display rows, core-selection-dialog rows) follow a different schema and are intentionally left alone. * ui_qt_widgets.h: define PlaylistEntry. The struct lives in this header rather than ui_qt.h because PlaylistEntryDialog has it in a default argument and ui_qt_widgets.h is included by ui_qt.h, not the other way round. Q_DECLARE_METATYPE and qRegisterMetaType<PlaylistEntry>() enable QVariant transport. * PlaylistModel: m_contents is now QVector<PlaylistEntry>. getThumbnailPath(), data() (HASH role), and setData() all consume the struct directly. The custom user role enum is renamed HASH -> ENTRY to match. * MainWindow: - getCurrentContentHash() -> getCurrentContentEntry() - getFileContentHash() -> getFileContentEntry() - loadContent(QHash) -> loadContent(PlaylistEntry) - onCurrentItemChanged(QHash) -> onCurrentItemChanged(PlaylistEntry) - updateCurrentPlaylistEntry(QHash) -> (PlaylistEntry) All call sites (setCoreActions, getSelectedCorePath, onRunClicked, onCurrentTableItemDataChanged, onCurrentFileChanged, onFileDoubleClicked, changeThumbnail, deleteCurrentPlaylistItem, the playlist-context-menu handler, and the addFilesToPlaylist flow) updated to read entry.field instead of hash["field"]. * PlaylistEntryDialog::showDialog and setEntryValues now take const PlaylistEntry &. The 'multiple entries' detection that used QHash::isEmpty() now uses entry.path.isEmpty(); previously the addFilesToPlaylist() flow had to write two empty-string keys just to make the QHash non-empty as a signal, which is gone. * Drop the dead 'index' field round-trip. updateCurrentPlaylistEntry() and deleteCurrentPlaylistItem() used to read 'index' from the hash via QString::toUInt, which meant PlaylistModel::addPlaylistItems() had to format every row's index as a decimal string into the hash. PlaylistEntry::index is just an unsigned now. * Drop dead m_currentGridHash member from MainWindow. It was only ever cleared, never written or read, so it always held an empty QHash. Removed along with the related conversions. No behaviour change. All four object files (ui_qt, ui_qt_widgets, moc_ui_qt, moc_ui_qt_widgets) build with zero warnings.
1 parent 1816b93 commit 0cc7a59

4 files changed

Lines changed: 197 additions & 219 deletions

File tree

ui/drivers/ui_qt.cpp

Lines changed: 77 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,6 @@ MainWindow::MainWindow(QWidget *parent) :
15041504
,m_thumbnailType(THUMBNAIL_TYPE_BOXART)
15051505
,m_gridProgressBar(NULL)
15061506
,m_gridProgressWidget(NULL)
1507-
,m_currentGridHash()
15081507
,m_currentGridWidget(NULL)
15091508
,m_allPlaylistsListMaxCount(0)
15101509
,m_allPlaylistsGridMaxCount(0)
@@ -1545,6 +1544,7 @@ MainWindow::MainWindow(QWidget *parent) :
15451544

15461545
qRegisterMetaType<QPointer<ThumbnailWidget> >("ThumbnailWidget");
15471546
qRegisterMetaType<retro_task_callback_t>("retro_task_callback_t");
1547+
qRegisterMetaType<PlaylistEntry>("PlaylistEntry");
15481548

15491549
memset(m_thumbnailPixmaps, 0, sizeof(m_thumbnailPixmaps));
15501550

@@ -2564,13 +2564,13 @@ void MainWindow::changeThumbnailType(ThumbnailType type)
25642564

25652565
QString MainWindow::changeThumbnail(const QImage &image, QString type)
25662566
{
2567-
QHash<QString, QString> hash = getCurrentContentHash();
2567+
PlaylistEntry entry = getCurrentContentEntry();
25682568
QString dirString = m_playlistModel->getPlaylistThumbnailsDir(
2569-
hash["db_name"])
2569+
entry.dbName)
25702570
+ QString("/") + type;
25712571
QString thumbPath = m_playlistModel->getSanitizedThumbnailName(
25722572
dirString + QString("/"),
2573-
hash["label_noext"]);
2573+
entry.labelNoExt);
25742574
QByteArray dirArray = QDir::toNativeSeparators(dirString).toUtf8();
25752575
const char *dirData = dirArray.constData();
25762576
QByteArray thumbArray = QDir::toNativeSeparators(thumbPath).toUtf8();
@@ -2711,7 +2711,7 @@ void MainWindow::onFileDoubleClicked(const QModelIndex &proxyIndex)
27112711
if (m_fileModel->isDir(index))
27122712
m_dirTree->setCurrentIndex(m_dirModel->index(m_fileModel->filePath(index)));
27132713
else
2714-
loadContent(getFileContentHash(index));
2714+
loadContent(getFileContentEntry(index));
27152715
}
27162716

27172717
void MainWindow::selectBrowserDir(QString path)
@@ -2773,22 +2773,22 @@ QModelIndex MainWindow::getCurrentContentIndex()
27732773
return QModelIndex();
27742774
}
27752775

2776-
QHash<QString, QString> MainWindow::getCurrentContentHash()
2776+
PlaylistEntry MainWindow::getCurrentContentEntry()
27772777
{
2778-
return getCurrentContentIndex().data(PlaylistModel::HASH).value<QHash<QString, QString> >();
2778+
return getCurrentContentIndex().data(PlaylistModel::ENTRY).value<PlaylistEntry>();
27792779
}
27802780

2781-
QHash<QString, QString> MainWindow::getFileContentHash(const QModelIndex &index)
2781+
PlaylistEntry MainWindow::getFileContentEntry(const QModelIndex &index)
27822782
{
2783-
QHash<QString, QString> hash;
2783+
PlaylistEntry entry;
27842784
QFileInfo fileInfo = m_fileModel->fileInfo(index);
27852785

2786-
hash["path"] = QDir::toNativeSeparators(m_fileModel->filePath(index));
2787-
hash["label"] = hash["path"];
2788-
hash["label_noext"] = fileInfo.completeBaseName();
2789-
hash["db_name"] = fileInfo.dir().dirName();
2786+
entry.path = QDir::toNativeSeparators(m_fileModel->filePath(index));
2787+
entry.label = entry.path;
2788+
entry.labelNoExt = fileInfo.completeBaseName();
2789+
entry.dbName = fileInfo.dir().dirName();
27902790

2791-
return hash;
2791+
return entry;
27922792
}
27932793

27942794
void MainWindow::onContentItemDoubleClicked(const QModelIndex &index)
@@ -2819,7 +2819,7 @@ void MainWindow::onStartCoreClicked()
28192819
* mode, no current item, or no default core for the playlist). */
28202820
QString MainWindow::getSelectedCorePath()
28212821
{
2822-
QHash<QString, QString> contentHash;
2822+
PlaylistEntry entry;
28232823
QVariantMap coreMap = m_launchWithComboBox->currentData(
28242824
Qt::UserRole).value<QVariantMap>();
28252825
core_selection coreSelection = static_cast<core_selection>(
@@ -2829,10 +2829,10 @@ QString MainWindow::getSelectedCorePath()
28292829
/* The content row only matters for the two playlist branches —
28302830
* CORE_SELECTION_CURRENT just hands back whatever core is loaded.
28312831
* Original behaviour: an "other" view type (e.g. while transitioning)
2832-
* returned an empty hash from all three branches. */
2832+
* returned an empty entry from all three branches. */
28332833
if (viewType == VIEW_TYPE_LIST || viewType == VIEW_TYPE_ICONS)
2834-
contentHash = getCurrentContentIndex().data(PlaylistModel::HASH)
2835-
.value<QHash<QString, QString> >();
2834+
entry = getCurrentContentIndex().data(PlaylistModel::ENTRY)
2835+
.value<PlaylistEntry>();
28362836
else
28372837
return QString();
28382838

@@ -2841,20 +2841,16 @@ QString MainWindow::getSelectedCorePath()
28412841
case CORE_SELECTION_CURRENT:
28422842
return QString::fromUtf8(path_get(RARCH_PATH_CORE));
28432843
case CORE_SELECTION_PLAYLIST_SAVED:
2844-
if ( !contentHash.isEmpty()
2845-
&& !contentHash["core_path"].isEmpty())
2846-
return contentHash["core_path"];
2844+
if (!entry.corePath.isEmpty())
2845+
return entry.corePath;
28472846
break;
28482847
case CORE_SELECTION_PLAYLIST_DEFAULT:
28492848
{
28502849
QString plName;
28512850
QString defaultCorePath;
28522851

2853-
if (contentHash.isEmpty())
2854-
break;
2855-
2856-
plName = contentHash["pl_name"].isEmpty()
2857-
? contentHash["db_name"] : contentHash["pl_name"];
2852+
plName = entry.plName.isEmpty()
2853+
? entry.dbName : entry.plName;
28582854

28592855
if (plName.isEmpty())
28602856
break;
@@ -2883,7 +2879,7 @@ core_name - The display name of the core, or "DETECT" if unknown
28832879
label_noext - The display name of the content that is guaranteed not
28842880
to contain a file extension
28852881
*/
2886-
void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
2882+
void MainWindow::loadContent(const PlaylistEntry &entry)
28872883
{
28882884
content_ctx_info_t content_info;
28892885
QByteArray corePathArray;
@@ -2916,9 +2912,9 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
29162912
{
29172913
QStringList extensionFilters;
29182914

2919-
if (contentHash.contains("path"))
2915+
if (!entry.path.isEmpty())
29202916
{
2921-
QByteArray pathArray = contentHash["path"].toUtf8();
2917+
QByteArray pathArray = entry.path.toUtf8();
29222918
const char *pathData = pathArray.constData();
29232919
const char *ext = path_get_extension(pathData);
29242920

@@ -2959,26 +2955,26 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
29592955
{
29602956
case CORE_SELECTION_CURRENT:
29612957
corePathArray = path_get(RARCH_PATH_CORE);
2962-
contentPathArray = contentHash["path"].toUtf8();
2963-
contentLabelArray = contentHash["label_noext"].toUtf8();
2958+
contentPathArray = entry.path.toUtf8();
2959+
contentLabelArray = entry.labelNoExt.toUtf8();
29642960
break;
29652961
case CORE_SELECTION_PLAYLIST_SAVED:
2966-
corePathArray = contentHash["core_path"].toUtf8();
2967-
contentPathArray = contentHash["path"].toUtf8();
2968-
contentLabelArray = contentHash["label_noext"].toUtf8();
2962+
corePathArray = entry.corePath.toUtf8();
2963+
contentPathArray = entry.path.toUtf8();
2964+
contentLabelArray = entry.labelNoExt.toUtf8();
29692965
break;
29702966
case CORE_SELECTION_PLAYLIST_DEFAULT:
29712967
{
2972-
QString plName = contentHash["pl_name"].isEmpty()
2973-
? contentHash["db_name"] : contentHash["pl_name"];
2968+
QString plName = entry.plName.isEmpty()
2969+
? entry.dbName : entry.plName;
29742970

29752971
QString defaultCorePath = getPlaylistDefaultCore(plName);
29762972

29772973
if (!defaultCorePath.isEmpty())
29782974
{
29792975
corePathArray = defaultCorePath.toUtf8();
2980-
contentPathArray = contentHash["path"].toUtf8();
2981-
contentLabelArray = contentHash["label_noext"].toUtf8();
2976+
contentPathArray = entry.path.toUtf8();
2977+
contentLabelArray = entry.labelNoExt.toUtf8();
29822978
}
29832979

29842980
break;
@@ -2987,8 +2983,8 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
29872983
return;
29882984
}
29892985

2990-
contentDbNameArray = contentHash["db_name"].toUtf8();
2991-
contentCrc32Array = contentHash["crc32"].toUtf8();
2986+
contentDbNameArray = entry.dbName.toUtf8();
2987+
contentCrc32Array = entry.crc32.toUtf8();
29922988

29932989
core_path = corePathArray.constData();
29942990
content_path = contentPathArray.constData();
@@ -3047,21 +3043,21 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
30473043

30483044
void MainWindow::onRunClicked()
30493045
{
3050-
QHash<QString, QString> contentHash;
3046+
PlaylistEntry entry;
30513047

30523048
switch (m_currentBrowser)
30533049
{
30543050
case BROWSER_TYPE_FILES:
3055-
contentHash = getFileContentHash(
3051+
entry = getFileContentEntry(
30563052
m_proxyFileModel->mapToSource(m_fileTableView->currentIndex()));
30573053
break;
30583054
case BROWSER_TYPE_PLAYLISTS:
3059-
contentHash = getCurrentContentHash();
3055+
entry = getCurrentContentEntry();
30603056
break;
30613057
}
30623058

3063-
if (!contentHash.isEmpty())
3064-
loadContent(contentHash);
3059+
if (!entry.path.isEmpty())
3060+
loadContent(entry);
30653061
}
30663062

30673063
PlaylistEntryDialog* MainWindow::playlistEntryDialog()
@@ -3074,7 +3070,7 @@ ViewOptionsDialog* MainWindow::viewOptionsDialog() {return m_viewOptionsDialog;}
30743070
void MainWindow::setCoreActions()
30753071
{
30763072
QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem();
3077-
QHash<QString, QString> hash = getCurrentContentHash();
3073+
PlaylistEntry entry = getCurrentContentEntry();
30783074
QString currentPlaylistFileName = QString();
30793075
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
30803076

@@ -3101,39 +3097,36 @@ void MainWindow::setCoreActions()
31013097

31023098
if (m_currentBrowser == BROWSER_TYPE_PLAYLISTS)
31033099
{
3104-
if (!hash.isEmpty())
3105-
{
3106-
QString coreName = hash["core_name"];
3100+
const QString &coreName = entry.coreName;
31073101

3108-
if (!coreName.isEmpty() && coreName != QLatin1String("DETECT"))
3102+
if (!coreName.isEmpty() && coreName != QLatin1String("DETECT"))
3103+
{
3104+
if (m_launchWithComboBox->findText(coreName) == -1)
31093105
{
3110-
if (m_launchWithComboBox->findText(coreName) == -1)
3106+
int i;
3107+
bool found_existing = false;
3108+
3109+
for (i = 0; i < m_launchWithComboBox->count(); i++)
31113110
{
3112-
int i;
3113-
bool found_existing = false;
3111+
QVariantMap map = m_launchWithComboBox->itemData(
3112+
i, Qt::UserRole).toMap();
31143113

3115-
for (i = 0; i < m_launchWithComboBox->count(); i++)
3114+
if ( map.value("core_path").toString() == entry.corePath
3115+
|| map.value("core_name").toString() == coreName)
31163116
{
3117-
QVariantMap map = m_launchWithComboBox->itemData(
3118-
i, Qt::UserRole).toMap();
3119-
3120-
if ( map.value("core_path").toString() == hash["core_path"]
3121-
|| map.value("core_name").toString() == coreName)
3122-
{
3123-
found_existing = true;
3124-
break;
3125-
}
3117+
found_existing = true;
3118+
break;
31263119
}
3120+
}
31273121

3128-
if (!found_existing)
3129-
{
3130-
QVariantMap comboBoxMap;
3131-
comboBoxMap["core_name"] = coreName;
3132-
comboBoxMap["core_path"] = hash["core_path"];
3133-
comboBoxMap["core_selection"] = CORE_SELECTION_PLAYLIST_SAVED;
3134-
m_launchWithComboBox->addItem(coreName,
3135-
QVariant::fromValue(comboBoxMap));
3136-
}
3122+
if (!found_existing)
3123+
{
3124+
QVariantMap comboBoxMap;
3125+
comboBoxMap["core_name"] = coreName;
3126+
comboBoxMap["core_path"] = entry.corePath;
3127+
comboBoxMap["core_selection"] = CORE_SELECTION_PLAYLIST_SAVED;
3128+
m_launchWithComboBox->addItem(coreName,
3129+
QVariant::fromValue(comboBoxMap));
31373130
}
31383131
}
31393132
}
@@ -3142,8 +3135,8 @@ void MainWindow::setCoreActions()
31423135
switch(m_currentBrowser)
31433136
{
31443137
case BROWSER_TYPE_PLAYLISTS:
3145-
currentPlaylistFileName = hash["pl_name"].isEmpty()
3146-
? hash["db_name"] : hash["pl_name"];
3138+
currentPlaylistFileName = entry.plName.isEmpty()
3139+
? entry.dbName : entry.plName;
31473140
break;
31483141
case BROWSER_TYPE_FILES:
31493142
currentPlaylistFileName = m_fileModel->rootDirectory().dirName();
@@ -3456,16 +3449,16 @@ void MainWindow::onSearchEnterPressed()
34563449
void MainWindow::onCurrentTableItemDataChanged(const QModelIndex &topLeft,
34573450
const QModelIndex &bottomRight, const QVector<int> &roles)
34583451
{
3459-
QHash<QString, QString> hash;
3452+
PlaylistEntry entry;
34603453

34613454
if (!roles.contains(Qt::EditRole))
34623455
return;
34633456
if (topLeft != bottomRight)
34643457
return;
34653458

3466-
hash = topLeft.data(PlaylistModel::HASH).value<QHash<QString, QString>>();
3459+
entry = topLeft.data(PlaylistModel::ENTRY).value<PlaylistEntry>();
34673460

3468-
updateCurrentPlaylistEntry(hash);
3461+
updateCurrentPlaylistEntry(entry);
34693462

34703463
onCurrentItemChanged(topLeft);
34713464
}
@@ -3551,20 +3544,20 @@ void MainWindow::renamePlaylistItem(QListWidgetItem *item, QString newName)
35513544
void MainWindow::onCurrentItemChanged(const QModelIndex &index)
35523545
{
35533546
onCurrentItemChanged(index.data(
3554-
PlaylistModel::HASH).value<QHash<QString, QString>>());
3547+
PlaylistModel::ENTRY).value<PlaylistEntry>());
35553548
}
35563549

35573550
void MainWindow::onCurrentFileChanged(const QModelIndex &index)
35583551
{
3559-
onCurrentItemChanged(getFileContentHash(
3552+
onCurrentItemChanged(getFileContentEntry(
35603553
m_proxyFileModel->mapToSource(index)));
35613554
}
35623555

3563-
void MainWindow::onCurrentItemChanged(const QHash<QString, QString> &hash)
3556+
void MainWindow::onCurrentItemChanged(const PlaylistEntry &entry)
35643557
{
35653558
size_t i;
3566-
QString path = hash["path"];
3567-
bool acceptDrop = false;
3559+
const QString &path = entry.path;
3560+
bool acceptDrop = false;
35683561

35693562
for (i = 0; i < 4; i++)
35703563
{
@@ -3596,7 +3589,7 @@ void MainWindow::onCurrentItemChanged(const QHash<QString, QString> &hash)
35963589
else
35973590
{
35983591
QString thumbnailsDir = m_playlistModel->getPlaylistThumbnailsDir(
3599-
hash["db_name"]);
3592+
entry.dbName);
36003593

36013594
/* Clear any pending file-browser preview request: this code
36023595
* path serves the playlist views, not the file browser, so a
@@ -3608,7 +3601,7 @@ void MainWindow::onCurrentItemChanged(const QHash<QString, QString> &hash)
36083601
QString name = m_playlistModel->getSanitizedThumbnailName(
36093602
thumbnailsDir + QString("/")
36103603
+ qt_thumbnail_subdirs[i] + QString("/"),
3611-
hash["label_noext"]);
3604+
entry.labelNoExt);
36123605
m_thumbnailPixmaps[i] = new QPixmap(pixmapFromPathRA(name));
36133606
}
36143607

@@ -3923,8 +3916,6 @@ void MainWindow::initContentTableWidget()
39233916
if (!item)
39243917
return;
39253918

3926-
m_currentGridHash.clear();
3927-
39283919
if (m_currentGridWidget)
39293920
{
39303921
m_currentGridWidget->setObjectName("thumbnailWidget");

0 commit comments

Comments
 (0)