profile: remove empty state from profile

This was moved to the desktop version. Enter the profile in
the constructor. Somewhat surprisingly, this seems to work.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-07-01 18:56:50 +02:00 committed by Dirk Hohndel
parent 787a23f017
commit 12fd102e4f
3 changed files with 22 additions and 90 deletions

View file

@ -195,7 +195,6 @@ MainWindow::MainWindow() : QMainWindow(),
ui.mainErrorMessage->hide(); ui.mainErrorMessage->hide();
setEnabledToolbar(false); setEnabledToolbar(false);
profile->view->setEmptyState();
initialUiSetup(); initialUiSetup();
readSettings(); readSettings();
diveList->setFocus(); diveList->setFocus();

View file

@ -78,17 +78,17 @@ T *ProfileWidget2::createItem(const DiveCartesianAxis &vAxis, int vColumn, int z
ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double fontPrintScale, QWidget *parent) : QGraphicsView(parent), ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double fontPrintScale, QWidget *parent) : QGraphicsView(parent),
profileScene(new ProfileScene(fontPrintScale)), profileScene(new ProfileScene(fontPrintScale)),
currentState(INVALID), currentState(INIT),
plannerModel(plannerModelIn), plannerModel(plannerModelIn),
zoomLevel(0), zoomLevel(0),
zoomFactor(1.15), zoomFactor(1.15),
isGrayscale(false), isGrayscale(false),
printMode(false), printMode(false),
background(new DivePixmapItem()),
backgroundFile(":poster-icon"),
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
toolTipItem(new ToolTipItem()), toolTipItem(new ToolTipItem()),
#endif #endif
d(nullptr),
dc(0),
diveProfileItem(createItem<DiveProfileItem>(*profileScene->profileYAxis, DivePlotDataModel::DEPTH, 0, fontPrintScale)), diveProfileItem(createItem<DiveProfileItem>(*profileScene->profileYAxis, DivePlotDataModel::DEPTH, 0, fontPrintScale)),
temperatureItem(createItem<DiveTemperatureItem>(*profileScene->temperatureAxis, DivePlotDataModel::TEMPERATURE, 1, fontPrintScale)), temperatureItem(createItem<DiveTemperatureItem>(*profileScene->temperatureAxis, DivePlotDataModel::TEMPERATURE, 1, fontPrintScale)),
meanDepthItem(createItem<DiveMeanDepthItem>(*profileScene->profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH, 1, fontPrintScale)), meanDepthItem(createItem<DiveMeanDepthItem>(*profileScene->profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH, 1, fontPrintScale)),
@ -169,6 +169,8 @@ ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double fo
connect(pp_gas, &qPrefPartialPressureGas::pheChanged, this, &ProfileWidget2::actionRequestedReplot); connect(pp_gas, &qPrefPartialPressureGas::pheChanged, this, &ProfileWidget2::actionRequestedReplot);
connect(pp_gas, &qPrefPartialPressureGas::pn2Changed, this, &ProfileWidget2::actionRequestedReplot); connect(pp_gas, &qPrefPartialPressureGas::pn2Changed, this, &ProfileWidget2::actionRequestedReplot);
connect(pp_gas, &qPrefPartialPressureGas::po2Changed, this, &ProfileWidget2::actionRequestedReplot); connect(pp_gas, &qPrefPartialPressureGas::po2Changed, this, &ProfileWidget2::actionRequestedReplot);
setProfileState();
} }
ProfileWidget2::~ProfileWidget2() ProfileWidget2::~ProfileWidget2()
@ -190,7 +192,6 @@ void ProfileWidget2::addActionShortcut(const Qt::Key shortcut, void (ProfileWidg
void ProfileWidget2::addItemsToScene() void ProfileWidget2::addItemsToScene()
{ {
scene()->addItem(background);
scene()->addItem(diveComputerText); scene()->addItem(diveComputerText);
scene()->addItem(tankItem); scene()->addItem(tankItem);
scene()->addItem(decoModelParameters); scene()->addItem(decoModelParameters);
@ -212,7 +213,6 @@ void ProfileWidget2::addItemsToScene()
void ProfileWidget2::setupItemOnScene() void ProfileWidget2::setupItemOnScene()
{ {
background->setZValue(9999);
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
toolTipItem->setZValue(9998); toolTipItem->setZValue(9998);
toolTipItem->setTimeAxis(profileScene->timeAxis); toolTipItem->setTimeAxis(profileScene->timeAxis);
@ -286,7 +286,6 @@ void ProfileWidget2::setupSceneAndFlags()
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
setMouseTracking(true); setMouseTracking(true);
background->setFlag(QGraphicsItem::ItemIgnoresTransformations);
} }
void ProfileWidget2::resetZoom() void ProfileWidget2::resetZoom()
@ -301,10 +300,14 @@ void ProfileWidget2::resetZoom()
// Currently just one dive, but the plan is to enable All of the selected dives. // Currently just one dive, but the plan is to enable All of the selected dives.
void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool doClearPictures, bool instant) void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool doClearPictures, bool instant)
{ {
// If there was no previously displayed dive, turn off animations
if (!d)
instant = true;
d = dIn; d = dIn;
dc = dcIn; dc = dcIn;
if (!d) { if (!d) {
setEmptyState(); clear();
return; return;
} }
@ -330,12 +333,11 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool doClearPict
const struct divecomputer *currentdc = get_dive_dc_const(d, dc); const struct divecomputer *currentdc = get_dive_dc_const(d, dc);
if (!currentdc || !currentdc->samples) { if (!currentdc || !currentdc->samples) {
setEmptyState(); clear();
return; return;
} }
// special handling when switching from empty state profileScene->animSpeed = instant || printMode ? 0 : qPrefDisplay::animation_speed();
profileScene->animSpeed = instant || currentState == EMPTY || printMode ? 0 : qPrefDisplay::animation_speed();
// restore default zoom level // restore default zoom level
resetZoom(); resetZoom();
@ -345,8 +347,6 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool doClearPict
toolTipItem->setVisible(!printMode); toolTipItem->setVisible(!printMode);
rulerItem->setVisible(prefs.rulergraph && !printMode && currentState != PLAN && currentState != EDIT); rulerItem->setVisible(prefs.rulergraph && !printMode && currentState != PLAN && currentState != EDIT);
#endif #endif
if (currentState == EMPTY)
setProfileState();
updateVisibility(); updateVisibility();
bool setpointflag = (currentdc->divemode == CCR) && prefs.pp_graphs.po2; bool setpointflag = (currentdc->divemode == CCR) && prefs.pp_graphs.po2;
@ -602,7 +602,6 @@ void ProfileWidget2::resizeEvent(QResizeEvent *event)
{ {
QGraphicsView::resizeEvent(event); QGraphicsView::resizeEvent(event);
fitInView(sceneRect(), Qt::IgnoreAspectRatio); fitInView(sceneRect(), Qt::IgnoreAspectRatio);
fixBackgroundPos();
} }
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -642,19 +641,6 @@ void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event)
} }
#endif #endif
void ProfileWidget2::fixBackgroundPos()
{
static QPixmap toBeScaled(backgroundFile);
if (currentState != EMPTY)
return;
QPixmap p = toBeScaled.scaledToHeight(viewport()->height() - 40, Qt::SmoothTransformation);
int x = viewport()->width() / 2 - p.width() / 2;
int y = viewport()->height() / 2 - p.height() / 2;
background->setPixmap(p);
background->setX(mapToScene(x, 0).x());
background->setY(mapToScene(y, 20).y());
}
void ProfileWidget2::scale(qreal sx, qreal sy) void ProfileWidget2::scale(qreal sx, qreal sy)
{ {
QGraphicsView::scale(sx, sy); QGraphicsView::scale(sx, sy);
@ -673,7 +659,7 @@ void ProfileWidget2::scale(qreal sx, qreal sy)
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
void ProfileWidget2::wheelEvent(QWheelEvent *event) void ProfileWidget2::wheelEvent(QWheelEvent *event)
{ {
if (currentState == EMPTY) if (!d)
return; return;
QPoint toolTipPos = mapFromScene(toolTipItem->pos()); QPoint toolTipPos = mapFromScene(toolTipItem->pos());
if (event->buttons() == Qt::LeftButton) if (event->buttons() == Qt::LeftButton)
@ -711,7 +697,7 @@ void ProfileWidget2::scrollViewTo(const QPoint &pos)
{ {
/* since we cannot use translate() directly on the scene we hack on /* since we cannot use translate() directly on the scene we hack on
* the scroll bars (hidden) functionality */ * the scroll bars (hidden) functionality */
if (!zoomLevel || currentState == EMPTY) if (!zoomLevel || !d)
return; return;
QScrollBar *vs = verticalScrollBar(); QScrollBar *vs = verticalScrollBar();
QScrollBar *hs = horizontalScrollBar(); QScrollBar *hs = horizontalScrollBar();
@ -763,64 +749,24 @@ static void hideAll(const T &container)
item->setVisible(false); item->setVisible(false);
} }
void ProfileWidget2::setEmptyState() void ProfileWidget2::clear()
{ {
// Then starting Empty State, move the background up.
if (currentState == EMPTY)
return;
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
clearPictures(); clearPictures();
#endif #endif
disconnectTemporaryConnections(); disconnectTemporaryConnections();
setBackgroundBrush(getColor(::BACKGROUND, isGrayscale));
profileScene->dataModel->clear(); profileScene->dataModel->clear();
currentState = EMPTY;
fixBackgroundPos();
background->setVisible(true);
profileScene->profileYAxis->setVisible(false);
profileScene->gasYAxis->setVisible(false);
profileScene->timeAxis->setVisible(false);
profileScene->temperatureAxis->setVisible(false);
profileScene->cylinderPressureAxis->setVisible(false);
diveComputerText->setVisible(false);
reportedCeiling->setVisible(false);
tankItem->setVisible(false);
pn2GasItem->setVisible(false);
po2GasItem->setVisible(false);
pheGasItem->setVisible(false);
o2SetpointGasItem->setVisible(false);
ccrsensor1GasItem->setVisible(false);
ccrsensor2GasItem->setVisible(false);
ccrsensor3GasItem->setVisible(false);
ocpo2GasItem->setVisible(false);
decoModelParameters->setVisible(false);
diveCeiling->setVisible(false);
#ifndef SUBSURFACE_MOBILE
toolTipItem->clearPlotInfo();
toolTipItem->setVisible(false);
rulerItem->setVisible(false);
mouseFollowerHorizontal->setVisible(false);
mouseFollowerVertical->setVisible(false);
profileScene->heartBeatAxis->setVisible(false);
heartBeatItem->setVisible(false);
#endif
for (AbstractProfilePolygonItem *item: profileItems) for (AbstractProfilePolygonItem *item: profileItems)
item->clear(); item->clear();
#ifndef SUBSURFACE_MOBILE
hideAll(allTissues);
hideAll(allPercentages);
hideAll(handles);
#endif
// the events will have connected slots which can fire after // the events will have connected slots which can fire after
// the dive and its data have been deleted - so explictly delete // the dive and its data have been deleted - so explictly delete
// the DiveEventItems // the DiveEventItems
qDeleteAll(eventItems); qDeleteAll(eventItems);
eventItems.clear(); eventItems.clear();
hideAll(gases); handles.clear();
gases.clear();
} }
void ProfileWidget2::setProfileState(const dive *dIn, int dcIn) void ProfileWidget2::setProfileState(const dive *dIn, int dcIn)
@ -865,23 +811,14 @@ void ProfileWidget2::updateVisibility()
void ProfileWidget2::setProfileState() void ProfileWidget2::setProfileState()
{ {
// Then starting Empty State, move the background up.
if (currentState == PROFILE) if (currentState == PROFILE)
return; return;
disconnectTemporaryConnections(); disconnectTemporaryConnections();
/* show the same stuff that the profile shows. */
currentState = PROFILE; currentState = PROFILE;
setBackgroundBrush(getColor(::BACKGROUND, isGrayscale)); setBackgroundBrush(getColor(::BACKGROUND, isGrayscale));
background->setVisible(false);
profileScene->profileYAxis->setVisible(true);
profileScene->gasYAxis->setVisible(true);
profileScene->timeAxis->setVisible(true);
profileScene->temperatureAxis->setVisible(true);
profileScene->cylinderPressureAxis->setVisible(true);
profileScene->updateAxes(); profileScene->updateAxes();
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -896,11 +833,12 @@ void ProfileWidget2::setProfileState()
tankItem->setPos(itemPos.tankBar.on); tankItem->setPos(itemPos.tankBar.on);
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
hideAll(handles);
mouseFollowerHorizontal->setVisible(false); mouseFollowerHorizontal->setVisible(false);
mouseFollowerVertical->setVisible(false); mouseFollowerVertical->setVisible(false);
#endif #endif
hideAll(gases);
handles.clear();
gases.clear();
} }
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE

View file

@ -32,7 +32,6 @@ class ToolTipItem;
class DiveReportedCeiling; class DiveReportedCeiling;
class DiveTextItem; class DiveTextItem;
class DiveEventItem; class DiveEventItem;
class DivePixmapItem;
class DiveRectItem; class DiveRectItem;
class DiveCartesianAxis; class DiveCartesianAxis;
class DiveProfileItem; class DiveProfileItem;
@ -54,11 +53,10 @@ class ProfileWidget2 : public QGraphicsView {
Q_OBJECT Q_OBJECT
public: public:
enum State { enum State {
EMPTY,
PROFILE, PROFILE,
EDIT, EDIT,
PLAN, PLAN,
INVALID INIT
}; };
// Pass null as plannerModel if no support for planning required // Pass null as plannerModel if no support for planning required
@ -73,6 +71,7 @@ public:
void setPrintMode(bool grayscale = false); void setPrintMode(bool grayscale = false);
bool isPlanner() const; bool isPlanner() const;
void draw(QPainter *painter, const QRect &pos); void draw(QPainter *painter, const QRect &pos);
void clear();
QImage toImage(QSize size); QImage toImage(QSize size);
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
bool eventFilter(QObject *, QEvent *) override; bool eventFilter(QObject *, QEvent *) override;
@ -88,7 +87,6 @@ slots: // Necessary to call from QAction's signals.
void settingsChanged(); void settingsChanged();
void actionRequestedReplot(bool triggered); void actionRequestedReplot(bool triggered);
void divesChanged(const QVector<dive *> &dives, DiveField field); void divesChanged(const QVector<dive *> &dives, DiveField field);
void setEmptyState();
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
void plotPictures(); void plotPictures();
void picturesRemoved(dive *d, QVector<QString> filenames); void picturesRemoved(dive *d, QVector<QString> filenames);
@ -135,7 +133,6 @@ private:
void replot(); void replot();
void changeGas(int tank, int seconds); void changeGas(int tank, int seconds);
void fixBackgroundPos();
void scrollViewTo(const QPoint &pos); void scrollViewTo(const QPoint &pos);
void setupSceneAndFlags(); void setupSceneAndFlags();
template<typename T, class... Args> T *createItem(const DiveCartesianAxis &vAxis, int vColumn, int z, Args&&... args); template<typename T, class... Args> T *createItem(const DiveCartesianAxis &vAxis, int vColumn, int z, Args&&... args);
@ -166,8 +163,6 @@ private:
qreal zoomFactor; qreal zoomFactor;
bool isGrayscale; bool isGrayscale;
bool printMode; bool printMode;
DivePixmapItem *background;
QString backgroundFile;
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
ToolTipItem *toolTipItem; ToolTipItem *toolTipItem;
#endif #endif