Skip to content

Commit

Permalink
Make CurrentDirectory be set to the right directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ailujezi committed Dec 19, 2023
1 parent 6dfa474 commit f6dd219
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ namespace hal
Q_OBJECT
Q_PROPERTY(QString disabledIconStyle READ disabledIconStyle WRITE setDisabledIconStyle)
Q_PROPERTY(QString newViewIconPath READ newViewIconPath WRITE setNewViewIconPath)
Q_PROPERTY(QString newDirIconPath READ newDirIconPath WRITE setNewDirIconPath)
Q_PROPERTY(QString newViewIconStyle READ newViewIconStyle WRITE setNewViewIconStyle)
Q_PROPERTY(QString renameIconPath READ renameIconPath WRITE setRenameIconPath)
Q_PROPERTY(QString renameIconStyle READ renameIconStyle WRITE setRenameIconStyle)
Expand Down Expand Up @@ -100,6 +99,13 @@ namespace hal
*/
GraphContext* getCurrentContext();

/**
* Get the currently selected directory in the table.
*
* @return The ContextTreeItem.
*/
ContextTreeItem* getCurrentItem();

/**
* Opens the currently selected GraphContext in hal's GraphTabWidget
*/
Expand All @@ -122,7 +128,6 @@ namespace hal
///@{
QString disabledIconStyle() const;
QString newViewIconPath() const;
QString newDirIconPath() const;
QString newViewIconStyle() const;
QString renameIconPath() const;
QString renameIconStyle() const;
Expand All @@ -142,7 +147,6 @@ namespace hal
///@{
void setDisabledIconStyle(const QString &path);
void setNewViewIconPath(const QString &path);
void setNewDirIconPath(const QString &path);
void setNewViewIconStyle(const QString &style);
void setRenameIconPath(const QString &path);
void setRenameIconStyle(const QString &style);
Expand Down Expand Up @@ -174,15 +178,15 @@ namespace hal

private Q_SLOTS:

void handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget);
void handleFocusChanged(QWidget* oldWidget, QWidget* newWidget);


private:
GraphTabWidget* mTabView;

QTreeView* mContextTreeView;
ContextTreeModel* mContextTreeModel;
ContextTableProxyModel* mContextTableProxyModel;
ContextTableProxyModel* mContextTreeProxyModel;

Searchbar* mSearchbar;

Expand All @@ -192,7 +196,6 @@ namespace hal

QAction* mNewViewAction;
QString mNewViewIconPath;
QString mNewDirIconPath;
QString mNewViewIconStyle;

QAction* mRenameAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,17 @@ namespace hal
*
* @return A vector of all GraphContext%s.
*/
const QVector<GraphContext*>& list();
const QVector<GraphContext*>& list();

/**
* Sets the CurrentDirectory.
*
* @param ContextTreeItem - The Currently focused Item.
*/
void setCurrentDirectory(ContextTreeItem* currentItem);

private Q_SLOTS:
void handleDataChanged();
void itemFocusChanged(const QModelIndex &newIndex);


private:
Expand Down
50 changes: 27 additions & 23 deletions plugins/gui/src/context_manager_widget/context_manager_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace hal

mOpenAction->setIcon(gui_utility::getStyledSvgIcon(mOpenIconStyle, mOpenIconPath));
mNewViewAction->setIcon(gui_utility::getStyledSvgIcon(mNewViewIconStyle, mNewViewIconPath));
mNewDirectoryAction->setIcon(gui_utility::getStyledSvgIcon(mNewViewIconStyle, mNewDirIconPath));
mNewDirectoryAction->setIcon(gui_utility::getStyledSvgIcon(mNewViewIconStyle, mNewViewIconPath));
mRenameAction->setIcon(gui_utility::getStyledSvgIcon(mRenameIconStyle, mRenameIconPath));
mDuplicateAction->setIcon(gui_utility::getStyledSvgIcon(mDuplicateIconStyle, mDuplicateIconPath));
mDeleteAction->setIcon(gui_utility::getStyledSvgIcon(mDeleteIconStyle, mDeleteIconPath));
Expand Down Expand Up @@ -76,12 +76,12 @@ namespace hal

mContextTreeModel = gGraphContextManager->getContextTableModel();

mContextTableProxyModel = new ContextTableProxyModel(this);
mContextTableProxyModel->setSourceModel(mContextTreeModel);
mContextTableProxyModel->setSortRole(Qt::UserRole);
mContextTreeProxyModel = new ContextTableProxyModel(this);
mContextTreeProxyModel->setSourceModel(mContextTreeModel);
mContextTreeProxyModel->setSortRole(Qt::UserRole);

mContextTreeView = new QTreeView(this);
mContextTreeView->setModel(mContextTableProxyModel);
mContextTreeView->setModel(mContextTreeProxyModel);
mContextTreeView->setSortingEnabled(true);
mContextTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
mContextTreeView->setSelectionMode(QAbstractItemView::SingleSelection); // ERROR ???
Expand All @@ -95,8 +95,8 @@ namespace hal
mContentLayout->addWidget(mSearchbar);

mSearchbar->hide();
mSearchbar->setColumnNames(mContextTableProxyModel->getColumnNames());
enableSearchbar(mContextTableProxyModel->rowCount() > 0);
mSearchbar->setColumnNames(mContextTreeProxyModel->getColumnNames());
enableSearchbar(mContextTreeProxyModel->rowCount() > 0);

connect(mOpenAction, &QAction::triggered, this, &ContextManagerWidget::handleOpenContextClicked);
connect(mNewViewAction, &QAction::triggered, this, &ContextManagerWidget::handleCreateContextClicked);
Expand All @@ -113,15 +113,15 @@ namespace hal
connect(mContextTreeModel, &ContextTreeModel::rowsInserted, this, &ContextManagerWidget::handleDataChanged);

connect(mSearchbar, &Searchbar::triggerNewSearch, this, &ContextManagerWidget::updateSearchIcon);
connect(mSearchbar, &Searchbar::triggerNewSearch, mContextTableProxyModel, &ContextTableProxyModel::startSearch);
connect(mSearchbar, &Searchbar::triggerNewSearch, mContextTreeProxyModel, &ContextTableProxyModel::startSearch);

mShortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this);
mShortCutDeleteItem->setEnabled(false);

connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, mShortCutDeleteItem, &QShortcut::setKey);
connect(mShortCutDeleteItem, &QShortcut::activated, this, &ContextManagerWidget::handleDeleteContextClicked);

connect(qApp, &QApplication::focusChanged, this, &ContextManagerWidget::handleDeleteShortcutOnFocusChanged);
connect(qApp, &QApplication::focusChanged, this, &ContextManagerWidget::handleFocusChanged);
}

void ContextManagerWidget::handleCreateContextClicked()
Expand Down Expand Up @@ -250,7 +250,7 @@ namespace hal

void ContextManagerWidget::handleDataChanged()
{
enableSearchbar(mContextTableProxyModel->rowCount() > 0);
enableSearchbar(mContextTreeProxyModel->rowCount() > 0);
}

void ContextManagerWidget::updateSearchIcon()
Expand All @@ -264,7 +264,7 @@ namespace hal
void ContextManagerWidget::selectViewContext(GraphContext* context)
{
const QModelIndex source_model_index = mContextTreeModel->getIndexFromContext(context);
const QModelIndex proxy_model_index = mContextTableProxyModel->mapFromSource(source_model_index);
const QModelIndex proxy_model_index = mContextTreeProxyModel->mapFromSource(source_model_index);

if(proxy_model_index.isValid())
mContextTreeView->setCurrentIndex(proxy_model_index);
Expand All @@ -275,11 +275,23 @@ namespace hal
GraphContext* ContextManagerWidget::getCurrentContext()
{
QModelIndex proxy_model_index = mContextTreeView->currentIndex();
QModelIndex source_model_index = mContextTableProxyModel->mapToSource(proxy_model_index);
QModelIndex source_model_index = mContextTreeProxyModel->mapToSource(proxy_model_index);

return mContextTreeModel->getContext(source_model_index);
}

ContextTreeItem *ContextManagerWidget::getCurrentItem()
{
QModelIndex proxy_model_index = mContextTreeView->currentIndex();
QModelIndex source_model_index = mContextTreeProxyModel->mapToSource(proxy_model_index);

BaseTreeItem* currentItem = mContextTreeModel->getItemFromIndex(source_model_index);
if (currentItem != mContextTreeModel->getRootItem())
return static_cast<ContextTreeItem*>(currentItem);

return nullptr;
}

void ContextManagerWidget::setupToolbar(Toolbar* toolbar)
{
toolbar->addAction(mNewDirectoryAction);
Expand Down Expand Up @@ -364,11 +376,6 @@ namespace hal
return mNewViewIconPath;
}

QString ContextManagerWidget::newDirIconPath() const
{
return mNewDirIconPath;
}

QString ContextManagerWidget::newViewIconStyle() const
{
return mNewViewIconStyle;
Expand Down Expand Up @@ -439,11 +446,6 @@ namespace hal
mNewViewIconPath = path;
}

void ContextManagerWidget::setNewDirIconPath(const QString& path)
{
mNewDirIconPath = path;
}

void ContextManagerWidget::setNewViewIconStyle(const QString& style)
{
mNewViewIconStyle = style;
Expand Down Expand Up @@ -504,8 +506,10 @@ namespace hal
mSearchActiveIconStyle = style;
}

void ContextManagerWidget::handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget)
void ContextManagerWidget::handleFocusChanged(QWidget* oldWidget, QWidget* newWidget)
{
mContextTreeModel->setCurrentDirectory(getCurrentItem());

if(!newWidget) return;
if(newWidget->parent() == this)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ namespace hal
ContextTreeModel::ContextTreeModel(QObject* parent) : BaseTreeModel(parent), mCurrentDirectory(nullptr), mMinDirectoryId(std::numeric_limits<u32>::max())
{
setHeaderLabels(QStringList() << "View Name" << "Timestamp");
//connect(qApp, &QApplication::focusChanged, this, &ContextTreeModel::itemFocusChanged);

}

Expand Down Expand Up @@ -242,7 +241,7 @@ namespace hal
BaseTreeItem* item = getItemFromIndex(index);

if (static_cast<ContextTreeItem*>(item)->isDirectory()) return nullptr;
GraphContext* context;
GraphContext* context = nullptr;
for (auto &i : mContextMap) {
if (i.second == item) {
context = i.first;
Expand All @@ -261,10 +260,12 @@ namespace hal
return mContextList;
}

void ContextTreeModel::itemFocusChanged(const QModelIndex &newIndex)
void ContextTreeModel::setCurrentDirectory(ContextTreeItem* currentItem)
{
BaseTreeItem* currentItem = getItemFromIndex(newIndex);
if(currentItem != mRootItem && static_cast<ContextTreeItem*>(currentItem)->isDirectory())
mCurrentDirectory = static_cast<ContextTreeItem*>(currentItem);
if(currentItem->isContext())
mCurrentDirectory = (currentItem->getParent() == mRootItem) ? nullptr : static_cast<ContextTreeItem*>(currentItem->getParent());

else if (currentItem->isDirectory())
mCurrentDirectory = currentItem;
}
}

0 comments on commit f6dd219

Please sign in to comment.