mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 02:30:14 +02:00
Simplify bookmark handling
This commit is contained in:
parent
1ffe22d5e9
commit
d9bd7f019f
3 changed files with 7 additions and 15 deletions
|
@ -15,14 +15,9 @@ Bookmarks::Bookmarks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bookmarks::insert(const QString& name, const QString& address) {
|
void Bookmarks::insert(const QString& name, const QString& address) {
|
||||||
QString key = name.toLower();
|
_bookmarks.insert(name, address);
|
||||||
|
|
||||||
QJsonObject bookmark;
|
if (contains(name)) {
|
||||||
bookmark.insert("name", name);
|
|
||||||
bookmark.insert("address", address);
|
|
||||||
_bookmarks.insert(key, bookmark);
|
|
||||||
|
|
||||||
if (contains(key)) {
|
|
||||||
qDebug() << "Added bookmark: " << name << ", " << address;
|
qDebug() << "Added bookmark: " << name << ", " << address;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Couldn't add bookmark: " << name << ", " << address;
|
qDebug() << "Couldn't add bookmark: " << name << ", " << address;
|
||||||
|
@ -30,11 +25,9 @@ void Bookmarks::insert(const QString& name, const QString& address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bookmarks::remove(const QString& name) {
|
void Bookmarks::remove(const QString& name) {
|
||||||
QString key = name.toLower();
|
_bookmarks.remove(name);
|
||||||
|
|
||||||
_bookmarks.remove(key);
|
if (!contains(name)) {
|
||||||
|
|
||||||
if (!contains(key)) {
|
|
||||||
qDebug() << "Removed bookmark: " << name;
|
qDebug() << "Removed bookmark: " << name;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Couldn't remove bookmark: " << name;
|
qDebug() << "Couldn't remove bookmark: " << name;
|
||||||
|
@ -42,5 +35,5 @@ void Bookmarks::remove(const QString& name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bookmarks::contains(const QString& name) const {
|
bool Bookmarks::contains(const QString& name) const {
|
||||||
return _bookmarks.contains(name.toLower());
|
return _bookmarks.contains(name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@ public:
|
||||||
bool contains(const QString& name) const;
|
bool contains(const QString& name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, QJsonObject> _bookmarks; // key: { name: string, address: string }
|
QVariantMap _bookmarks; // { name: address, ... }
|
||||||
// key is a lowercase copy of name, used to make the bookmarks case insensitive.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Bookmarks_h
|
#endif // hifi_Bookmarks_h
|
|
@ -1069,7 +1069,7 @@ void Menu::bookmarkLocation() {
|
||||||
addActionToQMenuAndActionHash(_bookmarksMenu, teleportAction, bookmarkName, 0,
|
addActionToQMenuAndActionHash(_bookmarksMenu, teleportAction, bookmarkName, 0,
|
||||||
QAction::NoRole, position);
|
QAction::NoRole, position);
|
||||||
|
|
||||||
bookmarks->insert(bookmarkName, bookmarkAddress);
|
bookmarks->insert(bookmarkName, bookmarkAddress); // Overwrites any item with the same bookmarkName.
|
||||||
|
|
||||||
_bookmarksMenu->setEnabled(true);
|
_bookmarksMenu->setEnabled(true);
|
||||||
_deleteBookmarksMenu->setEnabled(true);
|
_deleteBookmarksMenu->setEnabled(true);
|
||||||
|
|
Loading…
Reference in a new issue