2019-09-29 22:30:32 -07:00
|
|
|
#include "quam/project.h"
|
|
|
|
|
|
|
|
#include <QErrorMessage>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
2019-11-06 22:42:59 -08:00
|
|
|
Project::Project(std::istream &st, QErrorMessage *errors, QWidget *parent) :
|
|
|
|
QWidget{parent},
|
2019-09-29 22:30:32 -07:00
|
|
|
Ui::Project{},
|
2019-11-06 22:42:59 -08:00
|
|
|
m_seekingDir{false},
|
|
|
|
m_histPos{0},
|
|
|
|
m_hist(),
|
2019-10-09 16:06:14 -07:00
|
|
|
m_arc{new Arc::Arc{st, this}},
|
2019-10-04 10:37:34 -07:00
|
|
|
m_errors{errors},
|
2019-10-05 16:58:19 -07:00
|
|
|
m_model{new Arc::Model{this}},
|
2019-10-04 10:37:34 -07:00
|
|
|
m_sorter{new QSortFilterProxyModel{this}}
|
2019-09-29 22:30:32 -07:00
|
|
|
{
|
2019-11-06 22:42:59 -08:00
|
|
|
setupUi(this);
|
2019-10-04 10:37:34 -07:00
|
|
|
|
2019-10-08 20:43:35 -07:00
|
|
|
connect(m_model, &Arc::Model::dirChanged,
|
|
|
|
this, &Project::dirChanged);
|
|
|
|
connect(tableView, &QAbstractItemView::doubleClicked,
|
2019-10-09 16:06:14 -07:00
|
|
|
m_model, &Arc::Model::setDirToIndex);
|
2019-11-07 21:40:18 -08:00
|
|
|
connect(dirName, &QLineEdit::returnPressed,
|
|
|
|
this, &Project::goPath);
|
2019-10-05 16:58:19 -07:00
|
|
|
|
2019-10-10 14:29:08 -07:00
|
|
|
dirName->setValidator(m_arc->validator);
|
2019-10-04 10:37:34 -07:00
|
|
|
m_sorter->setSourceModel(m_model);
|
|
|
|
tableView->setModel(m_sorter);
|
2019-11-06 22:42:59 -08:00
|
|
|
seekTop();
|
2019-09-29 22:30:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Project::~Project() {
|
|
|
|
}
|
|
|
|
|
2019-11-06 22:42:59 -08:00
|
|
|
bool Project::seekHistory(std::ptrdiff_t newPos) {
|
|
|
|
if(newPos < 0 || newPos >= m_hist.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_histPos = newPos;
|
|
|
|
|
|
|
|
auto newPath = m_hist.at(newPos);
|
|
|
|
if(auto node = m_model->findPath(newPath)) {
|
|
|
|
if(auto dir = node->getDir()) {
|
|
|
|
m_seekingDir = true;
|
|
|
|
m_model->setDir(dir);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
m_errors->showMessage(QString::fromStdString("'"s + newPath + "' ") +
|
|
|
|
tr("is not a directory"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_errors->showMessage(tr("could not find directory") +
|
|
|
|
QString::fromStdString(" '"s + newPath + "'"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:40:18 -08:00
|
|
|
bool Project::seekPath(std::string path) {
|
|
|
|
return m_model->goPath(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Project::seekTop() {
|
|
|
|
m_model->setDir(&m_arc->root);
|
|
|
|
}
|
|
|
|
|
2019-11-06 22:42:59 -08:00
|
|
|
bool Project::goBack() {
|
|
|
|
return seekHistory(std::ptrdiff_t(m_histPos) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::goForward() {
|
|
|
|
return seekHistory(std::ptrdiff_t(m_histPos) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::goTop() {
|
|
|
|
seekTop();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::goUp() {
|
|
|
|
return m_model->goUp();
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:40:18 -08:00
|
|
|
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();
|
2019-10-10 14:29:08 -07:00
|
|
|
}
|
|
|
|
|
2019-09-29 22:30:32 -07:00
|
|
|
// EOF
|