Skip to content

Commit

Permalink
Refactor GUI map preview (#1385)
Browse files Browse the repository at this point in the history
* refactor map preview

"Show Only This ..." will pan to the selected waypoint or frame the
selected track or route.
"Show All ..." will recenter the map and reset the bounds.
  • Loading branch information
tsteven4 authored Nov 18, 2024
1 parent c8fc044 commit 186ed56
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 669 deletions.
480 changes: 175 additions & 305 deletions gui/gmapdlg.cc

Large diffs are not rendered by default.

69 changes: 24 additions & 45 deletions gui/gmapdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <QDialog> // for QDialog
#include <QItemSelection> // for QItemSelection
#include <QList> // for QList
#include <QModelIndex> // for QModelIndex
#include <QObject> // for Q_OBJECT, slots
#include <QPlainTextEdit> // for QPlainTextEdit
Expand All @@ -42,60 +41,40 @@ class GMapDialog: public QDialog
{
Q_OBJECT
public:
GMapDialog(QWidget* parent, const QString& gpxFileName, QPlainTextEdit* te);
GMapDialog(QWidget* parent, const Gpx& mapData, QPlainTextEdit* te);

private:
static constexpr bool debug_ = false;

Ui_GMapDlg ui_;
Map* mapWidget_;
QStandardItemModel* model_;
QStandardItem* wptItem_, *trkItem_, *rteItem_;
QList<QStandardItem*> wptList_, trkList_, rteList_;
Gpx gpx_;
int menuIndex_;
QStandardItem* wptItem_;
QStandardItem* trkItem_;
QStandardItem* rteItem_;
const Gpx& gpx_;

static void appendWaypointInfo(QStandardItem* it, const GpxWaypoint& wpt);
static void appendTrackInfo(QStandardItem* it, const GpxTrack& trk);
static void appendRouteInfo(QStandardItem* it, const GpxRoute& rte);

void appendWaypointInfo(QStandardItem* it, const GpxWaypoint& wpt);
void appendTrackInfo(QStandardItem* it, const GpxTrack& trk);
void appendRouteInfo(QStandardItem* it, const GpxRoute& rte);
static QString formatLength(double l);

int waypointIndex(QStandardItem* it);
int trackIndex(QStandardItem* it);
int routeIndex(QStandardItem* it);
QString formatLength(double l);
static void trace(const QString& label, const QStandardItem* it);
void expandCollapseAll(QStandardItem* top, bool exp);
void showHideAll(QStandardItem* top, bool ck);
void showHideChild(const QStandardItem* child);
void showHideChildren(const QStandardItem* top);
void itemClickedX(const QStandardItem* it);
void showOnlyThis(QStandardItem* top, int menuRow);
void showTopContextMenu(const QStringList& text, QStandardItem* top, const QPoint& pt);
void showChildContextMenu(const QString& text, const QStandardItem* child, const QPoint& pt);

//
private slots:
void itemChangedX(QStandardItem*);
void waypointClickedX(int i);
void trackClickedX(int i);
void routeClickedX(int i);
void itemChangedX(QStandardItem* it);
void treeDoubleClicked(const QModelIndex& idx);
void selectionChangedX(const QItemSelection&, const QItemSelection&);
void showContextMenu(const QPoint&);


void expandCollapseAll(const QList<QStandardItem*>& li,
QStandardItem* it, bool exp);
void checkUncheckAll(const QList<QStandardItem*>& li,
QStandardItem* it, bool exp);
void expandAllWaypoints();
void expandAllTracks();
void expandAllRoutes();

void collapseAllWaypoints();
void collapseAllTracks();
void collapseAllRoutes();

void hideAllWaypoints();
void hideAllTracks();
void hideAllRoutes();

void showAllWaypoints();
void showAllTracks();
void showAllRoutes();

void showOnlyThisWaypoint();
void showOnlyThisTrack();
void showOnlyThisRoute();
void selectionChangedX(const QItemSelection& sel, const QItemSelection& desel);
void showContextMenu(const QPoint& pt);
};

#endif
63 changes: 34 additions & 29 deletions gui/gpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,7 @@ static bool trackIsEmpty(const GpxTrack& trk)
class GpxHandler
{
public:
GpxHandler()

{
state = e_noop;
}

enum elementState {e_noop, e_wpt, e_trk,
e_trkpt, e_trkseg, e_rte, e_rtept
};
QString textChars;
GpxWaypoint currentWpt;
QList <GpxWaypoint> wptList;

QList <GpxTrack> trkList;
GpxTrack currentTrk;
GpxTrackPoint currentTrkPt;
GpxTrackSegment currentTrkSeg;

QList <GpxRoute> rteList;
GpxRoute currentRte;
GpxRoutePoint currentRtePt;

elementState state;
QList <elementState> stateStack;
/* Member Functions */

void startElement(QStringView localName,
const QXmlStreamAttributes& atts)
Expand Down Expand Up @@ -204,22 +181,50 @@ class GpxHandler
{
textChars = x;
}

/* Data Members */

QList <GpxWaypoint> wptList;
QList <GpxTrack> trkList;
QList <GpxRoute> rteList;

private:
/* Types */

enum elementState {e_noop, e_wpt, e_trk,
e_trkpt, e_trkseg, e_rte, e_rtept
};

/* Data Memebers */

QString textChars;
GpxWaypoint currentWpt;

GpxTrack currentTrk;
GpxTrackPoint currentTrkPt;
GpxTrackSegment currentTrkSeg;

GpxRoute currentRte;
GpxRoutePoint currentRtePt;

elementState state{e_noop};
QList <elementState> stateStack;
};


//------------------------------------------------------------------------

bool Gpx::read(const QString& fileName)
QString Gpx::read(const QString& fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
return false;
return QStringLiteral("Error opening file %1").arg(fileName);
}

QXmlStreamReader reader(&file);
GpxHandler gpxHandler;

for (bool atEnd = false; !reader.atEnd() && !atEnd;) {
for (bool atEnd = false; !reader.atEnd() && !atEnd;) {
reader.readNext();
// do processing
switch (reader.tokenType()) {
Expand Down Expand Up @@ -249,8 +254,8 @@ bool Gpx::read(const QString& fileName)
wayPoints = gpxHandler.wptList;
tracks = gpxHandler.trkList;
routes = gpxHandler.rteList;
return true;
return {};
}
return false;
return QStringLiteral("Error parsing map file: %1").arg(reader.errorString());

}
Loading

0 comments on commit 186ed56

Please sign in to comment.