Skip to content

Commit

Permalink
Perspectives - Part 3 of 4
Browse files Browse the repository at this point in the history
.. New dialog to rename, add and remove perspectives, re-order them
   and move charts from one perspective to another.

.. The focus is on managing perspectives and not the general UI
   layout (ie. add/remove charts and rename things etc) this is
   likely to be something this morphs into, but for now lets
   keep it simple (this was complicated enough !)

.. also found a SEGV in CP chart when hover in allplot before the
   CP chart has been notified in another perspective-- there are
   likely to be a few of these kinds of bugs around.
  • Loading branch information
liversedge committed Jul 4, 2021
1 parent fe2643e commit 1026145
Show file tree
Hide file tree
Showing 10 changed files with 692 additions and 51 deletions.
2 changes: 2 additions & 0 deletions src/Charts/CriticalPowerWindow.cpp
Expand Up @@ -1103,6 +1103,8 @@ CriticalPowerWindow::intervalSelected()
void
CriticalPowerWindow::intervalHover(IntervalItem* x)
{
if (myRideItem == NULL) return;

// ignore in compare mode
if (!amVisible() || context->isCompareIntervals) return;

Expand Down
59 changes: 54 additions & 5 deletions src/Gui/MainWindow.cpp
Expand Up @@ -89,6 +89,8 @@
#include "NewSideBar.h"
#include "HelpWindow.h"
#include "Perspective.h"
#include "PerspectiveDialog.h"

#if !defined(Q_OS_MAC)
#include "QTFullScreen.h" // not mac!
#endif
Expand Down Expand Up @@ -1379,9 +1381,9 @@ MainWindow::perspectiveSelected(int index)
}

// which perspective is currently being shown?
int prior = current->pages_.indexOf(current->page_);
int prior = current->perspectives_.indexOf(current->perspective_);

if (index < current->pages_.count()) {
if (index < current->perspectives_.count()) {

// a perspectives was selected
switch (view) {
Expand All @@ -1400,7 +1402,7 @@ MainWindow::perspectiveSelected(int index)
perspectiveSelector->setCurrentIndex(prior);

// now open dialog etc
switch (index - current->pages_.count()) {
switch (index - current->perspectives_.count()) {
case 1 : // add perspectives
{
QString name;
Expand All @@ -1414,19 +1416,66 @@ MainWindow::perspectiveSelected(int index)
current->setPerspectives(perspectiveSelector);

// and select remember pactive is true, so we do the heavy lifting here
perspectiveSelector->setCurrentIndex(current->pages_.count()-1);
perspectiveSelector->setCurrentIndex(current->perspectives_.count()-1);
current->perspectiveSelected(perspectiveSelector->currentIndex());
}
}
break;
case 2 : // manage perspectives
// XXX todo
PerspectiveDialog *dialog = new PerspectiveDialog(this, current);
connect(dialog, SIGNAL(perspectivesChanged()), this, SLOT(perspectivesChanged())); // update the selector and view
dialog->exec();
break;
}
pactive = false;
}
}

// manage perspectives has done something (remove/add/reorder perspectives)
// pactive MUST be true, see above
void
MainWindow::perspectivesChanged()
{
int view = currentTab->currentView();
TabView *current = NULL;

switch (view) {
case 0: current = currentTab->homeView; break;
case 1: current = currentTab->analysisView; break;
case 2: current = currentTab->diaryView; break;
case 3: current = currentTab->trainView; break;
}

// which perspective is currently being selected (before we go setting the combobox)
Perspective *prior = current->perspective_;

// ok, so reset the combobox
current->setPerspectives(perspectiveSelector);

// is the old selected perspective still available?
int index = current->perspectives_.indexOf(prior);

// pretend a selection was made if the index needs to change
if (index >= 0 ) {
// still exists, but not currently selected for some reason
if (perspectiveSelector->currentIndex() != index)
perspectiveSelector->setCurrentIndex(index);

// no need to signal as its currently being shown
} else {

pactive = false; // dialog is active, but we need to force a change

// need to choose first as current got deleted
if (perspectiveSelector->currentIndex() != 0)
perspectiveSelector->setCurrentIndex(0);
else
emit perspectiveSelector->currentIndexChanged(0);

pactive = true;
}
}

/*----------------------------------------------------------------------
* Drag and Drop
*--------------------------------------------------------------------*/
Expand Down
1 change: 1 addition & 0 deletions src/Gui/MainWindow.h
Expand Up @@ -143,6 +143,7 @@ class MainWindow : public QMainWindow

// perspective selected
void perspectiveSelected(int index);
void perspectivesChanged(); // when the list of perspectives is updated in PerspectivesDialog

// chart importing
void importCharts(QStringList);
Expand Down
25 changes: 21 additions & 4 deletions src/Gui/Perspective.cpp
Expand Up @@ -50,7 +50,7 @@ static const int tileSpacing = 10;

Perspective::Perspective(Context *context, QString title, int type) :
GcWindow(context), context(context), active(false), clicked(NULL), dropPending(false),
type(type), title(title), chartCursor(-2)
type(type), title_(title), chartCursor(-2)
{
// setup control area
QWidget *cw = new QWidget(this);
Expand Down Expand Up @@ -749,8 +749,23 @@ Perspective::addChart(GcChartWindow* newone)
active = false;
}

GcChartWindow *
Perspective::takeChart(GcChartWindow *chart)
{
// lets find it...
int index = charts.indexOf(chart);

if (index >= 0) {
removeChart(index, false, true);
return chart;
}

// failed to find it
return NULL;
}

bool
Perspective::removeChart(int num, bool confirm)
Perspective::removeChart(int num, bool confirm, bool keep)
{
if (num >= charts.count()) return false; // out of bounds (!)

Expand Down Expand Up @@ -791,8 +806,10 @@ Perspective::removeChart(int num, bool confirm)
default:
break; // never reached
}
((GcChartWindow*)(charts[num]))->close(); // disconnect
((GcChartWindow*)(charts[num]))->deleteLater();

((GcChartWindow*)(charts[num]))->close(); // disconnect chart
((GcChartWindow*)(charts[num]))->removeEventFilter(this); // stop watching events
if (!keep) ((GcChartWindow*)(charts[num]))->deleteLater();
charts.removeAt(num);

update();
Expand Down
9 changes: 7 additions & 2 deletions src/Gui/Perspective.h
Expand Up @@ -42,6 +42,7 @@ class ChartBar;
class LTMSettings;
class TabView;
class ViewParser;
class PerspectiveDialog;

class Perspective : public GcWindow
{
Expand All @@ -50,12 +51,15 @@ class Perspective : public GcWindow

friend ::TabView;
friend ::ViewParser;
friend ::PerspectiveDialog;

public:

Perspective(Context *, QString title, int type);
~Perspective();

QString title() const { return title_; }

void resetLayout();
void importChart(QMap<QString,QString> properties, bool select);

Expand Down Expand Up @@ -91,7 +95,8 @@ class Perspective : public GcWindow
void addChart(GcChartWindow* newone);
void addChartFromMenu(QAction*action); // called with an action
void appendChart(GcWinID id); // called from Context *to inset chart
bool removeChart(int, bool confirm = true);
bool removeChart(int, bool confirm = true, bool keep = false);
GcChartWindow *takeChart(GcChartWindow *wndow); // remove from view, but do not delete
void titleChanged();

// window wants to close...
Expand Down Expand Up @@ -126,7 +131,7 @@ class Perspective : public GcWindow
QString view;

// top bar
QString title;
QString title_;
QLineEdit *titleEdit;

QComboBox *styleSelector;
Expand Down

0 comments on commit 1026145

Please sign in to comment.