Merge pull request #12217 from luiscuenca/sortOrderFix

Fix sortOrder param on tablet buttons
This commit is contained in:
Seth Alves 2018-01-21 10:40:25 -08:00 committed by GitHub
commit 45a00bebc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 41 additions and 25 deletions

View file

@ -31,6 +31,8 @@
const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system"; const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system";
const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system"; const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system";
const QString TabletScriptingInterface::QML = "hifi/tablet/TabletRoot.qml"; const QString TabletScriptingInterface::QML = "hifi/tablet/TabletRoot.qml";
const QString BUTTON_SORT_ORDER_KEY = "sortOrder";
const int DEFAULT_BUTTON_SORT_ORDER = 100;
static QString getUsername() { static QString getUsername() {
QString username = "Unknown user"; QString username = "Unknown user";
@ -74,11 +76,21 @@ QVariant TabletButtonListModel::data(const QModelIndex& index, int role) const {
} }
TabletButtonProxy* TabletButtonListModel::addButton(const QVariant& properties) { TabletButtonProxy* TabletButtonListModel::addButton(const QVariant& properties) {
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); QVariantMap newProperties = properties.toMap();
if (newProperties.find(BUTTON_SORT_ORDER_KEY) == newProperties.end()) {
newProperties[BUTTON_SORT_ORDER_KEY] = DEFAULT_BUTTON_SORT_ORDER;
}
int index = computeNewButtonIndex(newProperties);
auto button = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(newProperties));
beginResetModel(); beginResetModel();
_buttons.push_back(tabletButtonProxy); int numButtons = (int)_buttons.size();
if (index < numButtons) {
_buttons.insert(_buttons.begin() + index, button);
} else {
_buttons.push_back(button);
}
endResetModel(); endResetModel();
return tabletButtonProxy.data(); return button.data();
} }
void TabletButtonListModel::removeButton(TabletButtonProxy* button) { void TabletButtonListModel::removeButton(TabletButtonProxy* button) {
@ -92,6 +104,20 @@ void TabletButtonListModel::removeButton(TabletButtonProxy* button) {
endResetModel(); endResetModel();
} }
int TabletButtonListModel::computeNewButtonIndex(const QVariantMap& newButtonProperties) {
int numButtons = (int)_buttons.size();
int newButtonSortOrder = newButtonProperties[BUTTON_SORT_ORDER_KEY].toInt();
if (newButtonSortOrder == DEFAULT_BUTTON_SORT_ORDER) return numButtons;
for (int i = 0; i < numButtons; i++) {
QVariantMap tabletButtonProperties = _buttons[i]->getProperties();
int tabletButtonSortOrder = tabletButtonProperties[BUTTON_SORT_ORDER_KEY].toInt();
if (newButtonSortOrder <= tabletButtonSortOrder) {
return i;
}
}
return numButtons;
}
TabletButtonsProxyModel::TabletButtonsProxyModel(QObject *parent) TabletButtonsProxyModel::TabletButtonsProxyModel(QObject *parent)
: QSortFilterProxyModel(parent) { : QSortFilterProxyModel(parent) {
} }

View file

@ -115,6 +115,7 @@ protected:
friend class TabletProxy; friend class TabletProxy;
TabletButtonProxy* addButton(const QVariant& properties); TabletButtonProxy* addButton(const QVariant& properties);
void removeButton(TabletButtonProxy* button); void removeButton(TabletButtonProxy* button);
int computeNewButtonIndex(const QVariantMap& newButtonProperties);
using List = std::list<QSharedPointer<TabletButtonProxy>>; using List = std::list<QSharedPointer<TabletButtonProxy>>;
static QHash<int, QByteArray> _roles; static QHash<int, QByteArray> _roles;
static Qt::ItemFlags _flags; static Qt::ItemFlags _flags;

View file

@ -22,8 +22,7 @@
var button = tablet.addButton({ var button = tablet.addButton({
icon: Script.resolvePath("dynamicsTests.svg"), icon: Script.resolvePath("dynamicsTests.svg"),
text: "Dynamics", text: "Dynamics"
sortOrder: 15
}); });

View file

@ -32,8 +32,7 @@
var button = tablet.addButton({ var button = tablet.addButton({
text: TABLET_BUTTON_NAME, text: TABLET_BUTTON_NAME,
icon: ICON_URL, icon: ICON_URL,
activeIcon: ACTIVE_ICON_URL, activeIcon: ACTIVE_ICON_URL
sortOrder: 1
}); });
var hasEventBridge = false; var hasEventBridge = false;

View file

@ -30,8 +30,7 @@
var button = tablet.addButton({ var button = tablet.addButton({
text: TABLET_BUTTON_NAME, text: TABLET_BUTTON_NAME,
icon: ICON_URL, icon: ICON_URL,
activeIcon: ACTIVE_ICON_URL, activeIcon: ACTIVE_ICON_URL
sortOrder: 1
}); });
var hasEventBridge = false; var hasEventBridge = false;

View file

@ -31,8 +31,7 @@
var button = tablet.addButton({ var button = tablet.addButton({
text: TABLET_BUTTON_NAME, text: TABLET_BUTTON_NAME,
icon: ICON_URL, icon: ICON_URL,
activeIcon: ACTIVE_ICON_URL, activeIcon: ACTIVE_ICON_URL
sortOrder: 1
}); });
var hasEventBridge = false; var hasEventBridge = false;

View file

@ -945,8 +945,7 @@
tabletButton = tablet.addButton({ tabletButton = tablet.addButton({
icon: tabletButtonIcon, icon: tabletButtonIcon,
activeIcon: tabletButtonActiveIcon, activeIcon: tabletButtonActiveIcon,
text: tabletButtonName, text: tabletButtonName
sortOrder: 0
}); });
Messages.subscribe(channelName); Messages.subscribe(channelName);

View file

@ -37,8 +37,7 @@
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({ button = tablet.addButton({
icon: "icons/tablet-icons/goto-i.svg", icon: "icons/tablet-icons/goto-i.svg",
text: buttonName, text: buttonName
sortOrder: 8
}); });
} }

View file

@ -41,8 +41,7 @@ if (Settings.getValue("HUDUIEnabled")) {
button = tablet.addButton({ button = tablet.addButton({
icon: "icons/tablet-icons/goto-i.svg", icon: "icons/tablet-icons/goto-i.svg",
activeIcon: "icons/tablet-icons/goto-a.svg", activeIcon: "icons/tablet-icons/goto-a.svg",
text: buttonName, text: buttonName
sortOrder: 8
}); });
} }

View file

@ -10,8 +10,7 @@
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({ var button = tablet.addButton({
icon: Script.resolvePath("assets/images/run.svg"), icon: Script.resolvePath("assets/images/run.svg"),
text: "RUN", text: "RUN"
sortOrder: 15
}); });
function onClicked() { function onClicked() {

View file

@ -37,8 +37,7 @@
var button = tablet.addButton({ var button = tablet.addButton({
icon: "icons/tablet-icons/users-i.svg", icon: "icons/tablet-icons/users-i.svg",
activeIcon: "icons/tablet-icons/users-a.svg", activeIcon: "icons/tablet-icons/users-a.svg",
text: "USERS", text: "USERS"
sortOrder: 11
}); });
var onUsersScreen = false; var onUsersScreen = false;

View file

@ -31,8 +31,7 @@ var activeButton = tablet.addButton({
icon: whiteIcon, icon: whiteIcon,
activeIcon: blackIcon, activeIcon: blackIcon,
text: APP_NAME, text: APP_NAME,
isActive: isActive, isActive: isActive
sortOrder: 11
}); });
if (isActive) { if (isActive) {

View file

@ -32,8 +32,7 @@
var button = tablet.addButton({ var button = tablet.addButton({
icon: ICONS.icon, icon: ICONS.icon,
activeIcon: ICONS.activeIcon, activeIcon: ICONS.activeIcon,
text: TABLET_BUTTON_NAME, text: TABLET_BUTTON_NAME
sortOrder: 1
}); });
var hasEventBridge = false; var hasEventBridge = false;