📄 trackeditorui.cpp
字号:
/*gpsmgr: A program for managing GPS informationCopyright (C) 2003 Austin BinghamThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.You can reach the author at: abingham@spamcop.net*/#include "trackEditorUI.h"#include "groupEditorWidget.h"#include "listItemPopup.h"#include <qcursor.h>#include <qlineedit.h>#include <qlistview.h>#include <qmessagebox.h>#include <qtextedit.h>#include <sstream>#include "trackPointEditorUI.h"namespace{ //-------------------------------------------------------------------------- class PointListItem : public QListViewItem { public: typedef gpsmgr::DataStore::TrackType::PointType PointType; enum { LAT_COL = 0, LON_COL, ALT_COL, TIME_COL }; PointListItem(const PointType& pt, QListView * parent) : QListViewItem (parent), mPoint (pt) {} QString text(int col) const { switch (col) { case LAT_COL: { ostringstream oss; oss << mPoint.position().lat(); return oss.str(); } case LON_COL: { ostringstream oss; oss << mPoint.position().lon(); return oss.str(); } case ALT_COL: { ostringstream oss; oss << mPoint.altitude(); return oss.str(); } case TIME_COL: { ostringstream oss; oss << mPoint.time(); return oss.str(); } default: return "UNKNOWN COLUMN"; } } PointType point() const { return mPoint; } void setPoint(const PointType& pt) { mPoint = pt; } private: PointType mPoint; }; }namespace gpsmgr { namespace ui { TrackEditorUI::TrackEditorUI(QWidget* parent, const char* name, bool modal, WFlags fl) : TrackEditorUIBase (parent, name, modal, fl) {} void TrackEditorUI::setTrack(const DataStore::TrackType& trk) { mNameEdit->setText(trk.name().c_str()); mCommentEdit->setText(trk.comment().c_str()); for (Track::PointList::const_iterator itr = trk.points().begin(); itr != trk.points().end(); ++itr) { new PointListItem(*itr, mPointListView); } mGroupEditorWidget->reset(trk); } DataStore::TrackType TrackEditorUI::track() const { DataStore::TrackType rval; rval.setName(mNameEdit->text()); rval.setComment(mCommentEdit->text()); for (QListViewItemIterator itr(mPointListView); QListViewItem* item = itr.current(); ++itr) { PointListItem* curr = static_cast<PointListItem*>(item); rval.addPoint(curr->point()); } mGroupEditorWidget->updateGroupObject(rval); return rval; } void TrackEditorUI::pointEditorPopup(QListViewItem* item, const QPoint& loc) { ListItemPopup lip(this); lip.setItemEnabled(ListItemPopup::EDIT, item); lip.setItemEnabled(ListItemPopup::DELETE, item); switch(lip.exec(QCursor::pos())) { // Add case 0: addPoint(); break; // Edit case 1: editPoint(); break; // Delete case 2: deletePoint(); break; } } void TrackEditorUI::addPoint() { TrackPointEditorUI tpui(this, "TrackPointEditor", true); tpui.move(QCursor::pos()); if (!tpui.exec()) return; new PointListItem(tpui.point(), mPointListView); } void TrackEditorUI::editPoint() { PointListItem* curr = static_cast<PointListItem*>(mPointListView->currentItem()); if (curr == NULL) return; TrackPointEditorUI tpui(this, "TrackPointEditor", true); tpui.setPoint(curr->point()); if (!tpui.exec()) return; curr->setPoint(tpui.point()); } void TrackEditorUI::deletePoint() { PointListItem* curr = static_cast<PointListItem*>(mPointListView->currentItem()); if (curr == NULL) return; delete curr; } void TrackEditorUI::accept() { using namespace gpsmgr::exceptions; try { DataStore::TrackType trk = track(); } catch (Exception<ParseError>& e) { QMessageBox::warning(this, "Invalid track", e.what(), "OK"); return; } TrackEditorUIBase::accept(); }} }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -