JobPathEditor: add next/prev jobs views
- Use a splitter to lay 3 views vertically - New context menu for Jobs views
This commit is contained in:
parent
62ee86b8b5
commit
5d643196e0
|
@ -6,18 +6,12 @@
|
|||
|
||||
#include "viewmanager/viewmanager.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include "utils/files/recentdirstore.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include "utils/owningqpointer.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include "model/stopmodel.h"
|
||||
#include "stopdelegate.h"
|
||||
#include "jobs/jobsmanager/model/jobshelper.h"
|
||||
|
||||
#include "model/nextprevrsjobsmodel.h"
|
||||
|
||||
#include "jobs/jobeditor/editstopdialog.h"
|
||||
|
||||
#include "utils/jobcategorystrings.h"
|
||||
|
@ -33,7 +27,15 @@
|
|||
#include "utils/delegates/sql/customcompletionlineedit.h"
|
||||
#include "shifts/shiftcombomodel.h"
|
||||
|
||||
|
||||
#include "utils/owningqpointer.h"
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include "utils/files/recentdirstore.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
|
||||
|
||||
JobPathEditor::JobPathEditor(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
@ -66,16 +68,27 @@ JobPathEditor::JobPathEditor(QWidget *parent) :
|
|||
ui->formLayout->getWidgetPosition(ui->categoryCombo, &categoryRow, &unusedRole);
|
||||
ui->formLayout->insertRow(categoryRow + 1, tr("Shift:"), shiftCombo);
|
||||
|
||||
//Stops
|
||||
stopModel = new StopModel(Session->m_Db, this);
|
||||
connect(shiftCombo, &CustomCompletionLineEdit::dataIdChanged, stopModel, &StopModel::setNewShiftId);
|
||||
ui->view->setModel(stopModel);
|
||||
ui->stopsView->setModel(stopModel);
|
||||
|
||||
delegate = new StopDelegate(Session->m_Db, this);
|
||||
ui->view->setItemDelegateForColumn(0, delegate);
|
||||
ui->stopsView->setItemDelegateForColumn(0, delegate);
|
||||
|
||||
ui->stopsView->setResizeMode(QListView::Adjust);
|
||||
ui->stopsView->setMovement(QListView::Static);
|
||||
ui->stopsView->setSelectionMode(QListView::ContiguousSelection);
|
||||
|
||||
//Next/Prev Jobs
|
||||
prevJobsModel = new NextPrevRSJobsModel(Session->m_Db, this);
|
||||
prevJobsModel->setMode(NextPrevRSJobsModel::PrevJobs);
|
||||
ui->prevJobsView->setModel(prevJobsModel);
|
||||
|
||||
nextJobsModel = new NextPrevRSJobsModel(Session->m_Db, this);
|
||||
nextJobsModel->setMode(NextPrevRSJobsModel::NextJobs);
|
||||
ui->nextJobsView->setModel(nextJobsModel);
|
||||
|
||||
ui->view->setResizeMode(QListView::Adjust);
|
||||
ui->view->setMovement(QListView::Static);
|
||||
ui->view->setSelectionMode(QListView::ContiguousSelection);
|
||||
|
||||
connect(ui->categoryCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), stopModel, &StopModel::setCategory);
|
||||
connect(stopModel, &StopModel::categoryChanged, this, &JobPathEditor::onCategoryChanged);
|
||||
|
@ -90,9 +103,15 @@ JobPathEditor::JobPathEditor(QWidget *parent) :
|
|||
|
||||
connect(ui->sheetBut, &QPushButton::clicked, this, &JobPathEditor::onSaveSheet);
|
||||
|
||||
ui->view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->view, &QListView::customContextMenuRequested, this, &JobPathEditor::showContextMenu);
|
||||
connect(ui->view, &QListView::clicked, this, &JobPathEditor::onIndexClicked);
|
||||
ui->stopsView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->stopsView, &QListView::customContextMenuRequested, this, &JobPathEditor::showStopsContextMenu);
|
||||
connect(ui->stopsView, &QListView::clicked, this, &JobPathEditor::onStopIndexClicked);
|
||||
|
||||
ui->prevJobsView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->prevJobsView, &QListView::customContextMenuRequested, this, &JobPathEditor::showJobContextMenu);
|
||||
|
||||
ui->nextJobsView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->nextJobsView, &QListView::customContextMenuRequested, this, &JobPathEditor::showJobContextMenu);
|
||||
|
||||
connect(Session, &MeetingSession::jobRemoved, this, &JobPathEditor::onJobRemoved);
|
||||
connect(&AppSettings, &MRTPSettings::jobColorsChanged, this, &JobPathEditor::updateSpinColor);
|
||||
|
@ -156,7 +175,10 @@ bool JobPathEditor::setJob_internal(db_id jobId)
|
|||
}
|
||||
|
||||
//If read-only hide 'AddHere' row (last one)
|
||||
ui->view->setRowHidden(stopModel->rowCount() - 1, m_readOnly);
|
||||
ui->stopsView->setRowHidden(stopModel->rowCount() - 1, m_readOnly);
|
||||
|
||||
prevJobsModel->setJobId(jobId);
|
||||
nextJobsModel->setJobId(jobId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -233,9 +255,9 @@ bool JobPathEditor::createNewJob(db_id *out)
|
|||
return true;
|
||||
}
|
||||
|
||||
void JobPathEditor::showContextMenu(const QPoint& pos)
|
||||
void JobPathEditor::showStopsContextMenu(const QPoint& pos)
|
||||
{
|
||||
QModelIndex index = ui->view->indexAt(pos);
|
||||
QModelIndex index = ui->stopsView->indexAt(pos);
|
||||
if(!index.isValid() || index.row()>= stopModel->rowCount() || stopModel->isAddHere(index))
|
||||
return;
|
||||
|
||||
|
@ -257,12 +279,12 @@ void JobPathEditor::showContextMenu(const QPoint& pos)
|
|||
const StopItem stop = stopModel->getItemAt(index.row());
|
||||
showStationSVG->setEnabled(stop.stationId != 0); //Enable only if station is set
|
||||
|
||||
QAction *act = menu->exec(ui->view->viewport()->mapToGlobal(pos));
|
||||
QAction *act = menu->exec(ui->stopsView->viewport()->mapToGlobal(pos));
|
||||
|
||||
QItemSelectionModel *sm = ui->view->selectionModel();
|
||||
QItemSelectionModel *sm = ui->stopsView->selectionModel();
|
||||
|
||||
QItemSelectionRange range;
|
||||
QItemSelection s = ui->view->selectionModel()->selection();
|
||||
QItemSelection s = ui->stopsView->selectionModel()->selection();
|
||||
if(s.count() > 0)
|
||||
{
|
||||
//Take the first range only
|
||||
|
@ -317,6 +339,56 @@ void JobPathEditor::showContextMenu(const QPoint& pos)
|
|||
}
|
||||
}
|
||||
|
||||
void JobPathEditor::showJobContextMenu(const QPoint& pos)
|
||||
{
|
||||
QTableView *jobView = qobject_cast<QTableView *>(sender());
|
||||
NextPrevRSJobsModel *jobModel = nextJobsModel;
|
||||
|
||||
if(jobView == ui->prevJobsView)
|
||||
jobModel = prevJobsModel;
|
||||
|
||||
QModelIndex index = jobView->indexAt(pos);
|
||||
|
||||
NextPrevRSJobsModel::Item item = jobModel->getItemAtRow(index.row());
|
||||
|
||||
OwningQPointer<QMenu> menu = new QMenu(this);
|
||||
QAction *goToStop = menu->addAction(tr("Go to Stop"));
|
||||
QAction *goToJob = menu->addAction(tr("Show Job"));
|
||||
QAction *showRSPlan = menu->addAction(tr("Show RS Plan"));
|
||||
menu->addSeparator();
|
||||
QAction *refreshViews = menu->addAction(tr("Refresh"));
|
||||
|
||||
//Enable only if RS is not going to depot
|
||||
goToStop->setEnabled(index.isValid());
|
||||
goToJob->setEnabled(index.isValid() && item.otherJobId != 0);
|
||||
showRSPlan->setEnabled(index.isValid());
|
||||
|
||||
QAction *act = menu->exec(jobView->viewport()->mapToGlobal(pos));
|
||||
|
||||
if(act == goToStop)
|
||||
{
|
||||
selectStop(item.stopId);
|
||||
}
|
||||
else if(act == goToJob)
|
||||
{
|
||||
if(isEdited()) //Prevent selecting other job before saving
|
||||
{
|
||||
if(!maybeSave())
|
||||
return;
|
||||
}
|
||||
Session->getViewManager()->requestJobSelection(item.otherJobId, true, true);
|
||||
}
|
||||
else if(act == showRSPlan)
|
||||
{
|
||||
Session->getViewManager()->requestRSInfo(item.rsId);
|
||||
}
|
||||
else if(act == refreshViews)
|
||||
{
|
||||
prevJobsModel->refreshData();
|
||||
nextJobsModel->refreshData();
|
||||
}
|
||||
}
|
||||
|
||||
bool JobPathEditor::clearJob()
|
||||
{
|
||||
DEBUG_ENTRY;
|
||||
|
@ -427,8 +499,12 @@ bool JobPathEditor::saveChanges()
|
|||
|
||||
stopModel->commitChanges();
|
||||
|
||||
db_id newJobId = stopModel->getJobId();
|
||||
prevJobsModel->setJobId(newJobId);
|
||||
nextJobsModel->setJobId(newJobId);
|
||||
|
||||
//When updating the path selection gets cleared so we restore it
|
||||
Session->getViewManager()->requestJobSelection(stopModel->getJobId(), true, true);
|
||||
Session->getViewManager()->requestJobSelection(newJobId, true, true);
|
||||
|
||||
canSetJob = true;
|
||||
return true;
|
||||
|
@ -602,15 +678,15 @@ void JobPathEditor::setReadOnly(bool readOnly)
|
|||
//If read-only hide 'AddHere' row (last one)
|
||||
int size = stopModel->rowCount();
|
||||
if(size > 0)
|
||||
ui->view->setRowHidden(size - 1, m_readOnly);
|
||||
ui->stopsView->setRowHidden(size - 1, m_readOnly);
|
||||
|
||||
if(m_readOnly)
|
||||
{
|
||||
ui->view->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->stopsView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->view->setEditTriggers(QAbstractItemView::DoubleClicked);
|
||||
ui->stopsView->setEditTriggers(QAbstractItemView::DoubleClicked);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -645,7 +721,7 @@ void JobPathEditor::onSaveSheet()
|
|||
utils::OpenFileInFolderDlg::askUser(tr("Job Sheet Saved"), fileName, this);
|
||||
}
|
||||
|
||||
void JobPathEditor::onIndexClicked(const QModelIndex& index)
|
||||
void JobPathEditor::onStopIndexClicked(const QModelIndex& index)
|
||||
{
|
||||
DEBUG_ENTRY;
|
||||
|
||||
|
@ -668,9 +744,9 @@ void JobPathEditor::onIndexClicked(const QModelIndex& index)
|
|||
|
||||
//Edit former Last Stop
|
||||
QModelIndex prev = stopModel->index(row - 1, 0);
|
||||
ui->view->setCurrentIndex(prev);
|
||||
ui->view->scrollTo(prev);
|
||||
ui->view->edit(prev);
|
||||
ui->stopsView->setCurrentIndex(prev);
|
||||
ui->stopsView->scrollTo(prev);
|
||||
ui->stopsView->edit(prev);
|
||||
|
||||
//Tell editor to popup lines combo
|
||||
//QAbstractItemView::edit doesn't let you pass additional arguments
|
||||
|
@ -681,9 +757,9 @@ void JobPathEditor::onIndexClicked(const QModelIndex& index)
|
|||
else
|
||||
{
|
||||
QModelIndex lastStop = stopModel->index(row, 0);
|
||||
ui->view->setCurrentIndex(lastStop);
|
||||
ui->view->scrollTo(lastStop);
|
||||
ui->view->edit(lastStop);
|
||||
ui->stopsView->setCurrentIndex(lastStop);
|
||||
ui->stopsView->scrollTo(lastStop);
|
||||
ui->stopsView->edit(lastStop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -695,8 +771,8 @@ bool JobPathEditor::getCanSetJob() const
|
|||
|
||||
void JobPathEditor::closeStopEditor()
|
||||
{
|
||||
QModelIndex idx = ui->view->currentIndex();
|
||||
QWidget *ed = ui->view->indexWidget(idx);
|
||||
QModelIndex idx = ui->stopsView->currentIndex();
|
||||
QWidget *ed = ui->stopsView->indexWidget(idx);
|
||||
if(ed == nullptr)
|
||||
return;
|
||||
emit delegate->commitData(ed);
|
||||
|
@ -725,7 +801,7 @@ void JobPathEditor::selectStop(db_id stopId)
|
|||
if(row >= 0)
|
||||
{
|
||||
QModelIndex idx = stopModel->index(row, 0);
|
||||
ui->view->setCurrentIndex(idx);
|
||||
ui->view->scrollTo(idx, QListView::EnsureVisible);
|
||||
ui->stopsView->setCurrentIndex(idx);
|
||||
ui->stopsView->scrollTo(idx, QListView::EnsureVisible);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ class StopDelegate;
|
|||
class CustomCompletionLineEdit;
|
||||
|
||||
class StopModel;
|
||||
class NextPrevRSJobsModel;
|
||||
|
||||
namespace Ui {
|
||||
class JobPathEditor;
|
||||
|
@ -67,8 +68,11 @@ protected:
|
|||
private slots:
|
||||
void setEdited(bool val);
|
||||
|
||||
void showContextMenu(const QPoint &pos);
|
||||
void onIndexClicked(const QModelIndex &index);
|
||||
void showJobContextMenu(const QPoint &pos);
|
||||
void showStopsContextMenu(const QPoint &pos);
|
||||
|
||||
void onStopIndexClicked(const QModelIndex &index);
|
||||
|
||||
void onJobRemoved(db_id jobId);
|
||||
|
||||
void startJobNumberTimer();
|
||||
|
@ -94,6 +98,9 @@ private:
|
|||
StopModel *stopModel;
|
||||
StopDelegate *delegate;
|
||||
|
||||
NextPrevRSJobsModel *prevJobsModel;
|
||||
NextPrevRSJobsModel *nextJobsModel;
|
||||
|
||||
int jobNumberTimerId;
|
||||
|
||||
//TODO: there are too many bools
|
||||
|
|
|
@ -6,46 +6,15 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>320</width>
|
||||
<height>515</height>
|
||||
<width>350</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="numberLabel">
|
||||
<property name="text">
|
||||
<string>Number:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="jobIdSpin">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>99999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="categoryLabel">
|
||||
<property name="text">
|
||||
<string>Category:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="categoryCombo">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
|
@ -60,17 +29,93 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QListView" name="view"/>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="categoryLabel">
|
||||
<property name="text">
|
||||
<string>Category:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="numberLabel">
|
||||
<property name="text">
|
||||
<string>Number:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="jobIdSpin">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>99999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="splitterLay1">
|
||||
<item>
|
||||
<widget class="QLabel" name="stopsLabel">
|
||||
<property name="text">
|
||||
<string>Stops:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="stopsView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="prevJobsLabel">
|
||||
<property name="text">
|
||||
<string>Prev Jobs:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="prevJobsView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="splitterLay3">
|
||||
<item>
|
||||
<widget class="QLabel" name="nextJobsLabel">
|
||||
<property name="text">
|
||||
<string>Next Jobs:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="nextJobsView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="sheetBut">
|
||||
<property name="text">
|
||||
<string>Save Sheet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<item row="9" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
|
|
Loading…
Reference in New Issue