Skip to content

Commit

Permalink
plugins/openmv: Finish model zoo browser logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwagyeman committed Feb 24, 2025
1 parent c095983 commit 58033c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
32 changes: 29 additions & 3 deletions src/plugins/openmv/openmvmodelzoo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define LAST_MODEL_ZOO_DIALOG_GEOMETRY "OpenMVModelZooDialogGeometry"
#define LAST_MODEL_ZOO_DIALOG_SPLITTER_STATE "OpenMVModelZooDialogSplitterState"
#define LAST_MODEL_ZOO_DIALOG_EXPANDED_STATE "OpenMVModelZooDialogExpandedState"
#define LAST_MODEL_ZOO_DIALOG_SELECTED_INDEX "OpenMVModelZooDialogSelectedIndex"

namespace OpenMV {
namespace Internal {
Expand Down Expand Up @@ -92,6 +93,14 @@ OpenMVModelZooBrowser::OpenMVModelZooBrowser(Utils::QtcSettings *settings, QWidg
connect(m_model, &QFileSystemModel::directoryLoaded, this, [this]() {
QStringList list = m_settings->value(LAST_MODEL_ZOO_DIALOG_EXPANDED_STATE).toStringList();
restoreExpandedState(QString(), list, m_treeView->rootIndex());

if ((!m_initialized) && m_settings->contains(LAST_MODEL_ZOO_DIALOG_SELECTED_INDEX))
{
QModelIndex index = m_filter->mapFromSource(m_model->index(m_settings->value(LAST_MODEL_ZOO_DIALOG_SELECTED_INDEX).toString()));
m_treeView->setCurrentIndex(index);
m_treeView->scrollTo(index, QTreeView::PositionAtCenter);
m_initialized = true;
}
});
}
else
Expand All @@ -101,6 +110,7 @@ OpenMVModelZooBrowser::OpenMVModelZooBrowser(Utils::QtcSettings *settings, QWidg
}

m_selectedModel = QString();
m_initialized = false;

#ifndef Q_OS_MAC
m_styleSheet = QStringLiteral( // https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtreeview
Expand All @@ -110,11 +120,18 @@ OpenMVModelZooBrowser::OpenMVModelZooBrowser(Utils::QtcSettings *settings, QWidg
#endif

m_highDPIStyleSheet = QString(m_styleSheet).replace(QStringLiteral(".png"), QStringLiteral("_2x.png"));

m_devicePixelRatio = 0;

connect(m_treeView, &QTreeView::clicked, this, [this, ok, textBrowser](const QModelIndex &index) {
QString path = m_model->filePath(m_filter->mapToSource(index));
connect(m_treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, ok, textBrowser](const QItemSelection &selected, const QItemSelection &deselected) {
QModelIndexList indexes = selected.indexes();
Q_UNUSED(deselected)

if (indexes.isEmpty())
{
return;
}

QString path = m_model->filePath(m_filter->mapToSource(indexes.first()));

if (QFileInfo(path).isDir())
{
Expand Down Expand Up @@ -253,6 +270,15 @@ OpenMVModelZooBrowser::~OpenMVModelZooBrowser()
QStringList list;
saveExpandedState(QString(), list, m_treeView->rootIndex());
m_settings->setValue(LAST_MODEL_ZOO_DIALOG_EXPANDED_STATE, list);

if (m_treeView->selectionModel()->hasSelection())
{
m_settings->setValue(LAST_MODEL_ZOO_DIALOG_SELECTED_INDEX, m_model->filePath(m_filter->mapToSource(m_treeView->currentIndex())));
}
else
{
m_settings->remove(LAST_MODEL_ZOO_DIALOG_SELECTED_INDEX);
}
}

// We have to do this because Qt does not update the icons when switching between
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/openmv/openmvmodelzoo.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public slots:
Core::MiniSplitter *m_splitter;
OpenMVModelZooBrowserFilter *m_filter;
QString m_selectedModel;

bool m_initialized;
QString m_styleSheet, m_highDPIStyleSheet;
qreal m_devicePixelRatio;
};
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/openmv/openmvplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,6 @@ void OpenMVPlugin::extensionsInitialized()
Core::Command *romfsCommand = Core::ActionManager::registerAction(m_romfsAction, Utils::Id("OpenMV.ROMFS"));
toolsMenu->addAction(romfsCommand);
connect(m_romfsAction, &QAction::triggered, this, &OpenMVPlugin::romfsClicked);
// DISABLED
m_romfsAction->setVisible(false);

toolsMenu->addSeparator();

Expand Down
9 changes: 4 additions & 5 deletions src/plugins/openmv/openmvpluginconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,10 @@ void OpenMVPlugin::connectClicked(bool forceBootloader, QString forceFirmwarePat
{
QTimer::singleShot(0, m_eraseAction, &QAction::trigger);
}
// DISABLED
// else if(combo->currentIndex() == 3)
// {
// QTimer::singleShot(0, m_romfsAction, &QAction::trigger);
// }
else if(combo->currentIndex() == 3)
{
QTimer::singleShot(0, m_romfsAction, &QAction::trigger);
}
}

delete dialog;
Expand Down

0 comments on commit 58033c5

Please sign in to comment.