From 83ba1bae08a5c09154fd27ad1329eca8bd424c2b Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Fri, 8 Nov 2019 00:40:18 -0500 Subject: [PATCH] add path setting via text box --- source/quam/project.cc | 62 ++++++++++++++++++++++++++---------------- source/quam/project.h | 5 ++-- source/quam/project.ui | 11 +++++--- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/source/quam/project.cc b/source/quam/project.cc index 477379b..5d8ef78 100644 --- a/source/quam/project.cc +++ b/source/quam/project.cc @@ -20,6 +20,8 @@ Project::Project(std::istream &st, QErrorMessage *errors, QWidget *parent) : this, &Project::dirChanged); connect(tableView, &QAbstractItemView::doubleClicked, m_model, &Arc::Model::setDirToIndex); + connect(dirName, &QLineEdit::returnPressed, + this, &Project::goPath); dirName->setValidator(m_arc->validator); m_sorter->setSourceModel(m_model); @@ -30,28 +32,6 @@ Project::Project(std::istream &st, QErrorMessage *errors, QWidget *parent) : Project::~Project() { } -void Project::dirChanged(Arc::Dir *from, Arc::Dir *to) { - if(!m_seekingDir) { - if(std::ptrdiff_t(m_histPos) < std::ptrdiff_t(m_hist.size()) - 1) { - auto beg = m_hist.begin(); - std::advance(beg, m_histPos + 1); - m_hist.erase(beg, m_hist.end()); - } - - m_hist.push_back(to->getPath()); - m_histPos = m_hist.size() - 1; - } else { - m_seekingDir = false; - } - - tableView->sortByColumn(int(Arc::Column::Type), Qt::AscendingOrder); - tableView->resizeColumnsToContents(); -} - -void Project::seekTop() { - m_model->setDir(&m_arc->root); -} - bool Project::seekHistory(std::ptrdiff_t newPos) { if(newPos < 0 || newPos >= m_hist.size()) { return false; @@ -77,6 +57,14 @@ bool Project::seekHistory(std::ptrdiff_t newPos) { } } +bool Project::seekPath(std::string path) { + return m_model->goPath(path); +} + +void Project::seekTop() { + m_model->setDir(&m_arc->root); +} + bool Project::goBack() { return seekHistory(std::ptrdiff_t(m_histPos) - 1); } @@ -94,8 +82,34 @@ bool Project::goUp() { return m_model->goUp(); } -bool Project::goPath(std::string path) { - return m_model->goPath(path); +bool Project::goPath() { + auto newPath = dirName->text().toStdString(); + if(!m_model->goPath(newPath)) { + m_errors->showMessage(tr("could not find directory") + + QString::fromStdString(" '"s + newPath + "'")); + return false; + } else { + return true; + } +} + +void Project::dirChanged(Arc::Dir *from, Arc::Dir *to) { + if(!m_seekingDir) { + if(std::ptrdiff_t(m_histPos) < std::ptrdiff_t(m_hist.size()) - 1) { + auto beg = m_hist.begin(); + std::advance(beg, m_histPos + 1); + m_hist.erase(beg, m_hist.end()); + } + + m_hist.push_back(to->getPath()); + m_histPos = m_hist.size() - 1; + } else { + m_seekingDir = false; + } + + dirName->setText(QString::fromStdString(to->getPath())); + tableView->sortByColumn(int(Arc::Column::Type), Qt::AscendingOrder); + tableView->resizeColumnsToContents(); } // EOF diff --git a/source/quam/project.h b/source/quam/project.h index 2098b7d..d52015c 100644 --- a/source/quam/project.h +++ b/source/quam/project.h @@ -18,6 +18,7 @@ public: virtual ~Project(); bool seekHistory(std::ptrdiff_t newPos); + bool seekPath(std::string path); void seekTop(); public slots: @@ -26,9 +27,9 @@ public slots: bool goTop(); bool goUp(); - bool goPath(std::string path); - private slots: + bool goPath(); + void dirChanged(Arc::Dir *from, Arc::Dir *to); private: diff --git a/source/quam/project.ui b/source/quam/project.ui index 02c6323..2645be0 100644 --- a/source/quam/project.ui +++ b/source/quam/project.ui @@ -19,7 +19,7 @@ Qt::Horizontal - + @@ -32,7 +32,8 @@ - + + .. true @@ -48,7 +49,8 @@ - + + .. true @@ -64,7 +66,8 @@ - + + .. true