Keep property order
Dieser Commit ist enthalten in:
Ursprung
4180adbadc
Commit
33f4db0d4b
@ -25,5 +25,6 @@
|
||||
|
||||
void InterfaceItems::add(InterfaceItem& item)
|
||||
{
|
||||
insert(item.name(), &item);
|
||||
m_items.insert(item.name(), &item);
|
||||
m_itemOrder.append(item.name());
|
||||
}
|
||||
|
||||
@ -24,12 +24,21 @@
|
||||
#define CLIENT_NETWORK_INTERFACEITEMS_HPP
|
||||
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
class InterfaceItem;
|
||||
|
||||
class InterfaceItems : public QMap<QString, InterfaceItem*>
|
||||
class InterfaceItems
|
||||
{
|
||||
protected:
|
||||
QMap<QString, InterfaceItem*> m_items;
|
||||
QStringList m_itemOrder;
|
||||
|
||||
public:
|
||||
const QStringList& names() const { return m_itemOrder; }
|
||||
|
||||
inline InterfaceItem* find(const QString& name) const { return m_items.value(name, nullptr); }
|
||||
|
||||
void add(InterfaceItem& item);
|
||||
};
|
||||
|
||||
|
||||
@ -38,10 +38,10 @@ Object::~Object()
|
||||
|
||||
const Property* Object::getProperty(const QString& name) const
|
||||
{
|
||||
return dynamic_cast<Property*>(m_interfaceItems.value(name, nullptr));
|
||||
return dynamic_cast<Property*>(m_interfaceItems.find(name));
|
||||
}
|
||||
|
||||
Property* Object::getProperty(const QString& name)
|
||||
{
|
||||
return dynamic_cast<Property*>(m_interfaceItems.value(name, nullptr));
|
||||
return dynamic_cast<Property*>(m_interfaceItems.find(name));
|
||||
}
|
||||
|
||||
@ -69,8 +69,8 @@ void ObjectEditWidget::buildForm()
|
||||
{
|
||||
QMap<QString, QWidget*> tabs;
|
||||
|
||||
for(auto item : m_object->interfaceItems())
|
||||
if(Property* property = dynamic_cast<Property*>(item))
|
||||
for(const QString& name : m_object->interfaceItems().names())
|
||||
if(Property* property = m_object->getProperty(name))
|
||||
{
|
||||
QWidget* w = nullptr;
|
||||
|
||||
|
||||
@ -23,7 +23,14 @@
|
||||
#include "interfaceitems.hpp"
|
||||
#include "interfaceitem.hpp"
|
||||
|
||||
InterfaceItem* InterfaceItems::find(const std::string& name) const
|
||||
{
|
||||
auto it = m_items.find(name);
|
||||
return (it != m_items.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
void InterfaceItems::add(InterfaceItem& item)
|
||||
{
|
||||
emplace(item.name(), item);
|
||||
m_items.emplace(item.name(), item);
|
||||
m_itemOrder.push_back(item.name());
|
||||
}
|
||||
|
||||
@ -23,15 +23,30 @@
|
||||
#ifndef SERVER_CORE_INTERFACEITEMS_HPP
|
||||
#define SERVER_CORE_INTERFACEITEMS_HPP
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
class InterfaceItem;
|
||||
|
||||
class InterfaceItems : public std::map<std::string, InterfaceItem&>
|
||||
class InterfaceItems
|
||||
{
|
||||
protected:
|
||||
std::unordered_map<std::string, InterfaceItem&> m_items;
|
||||
std::list<std::string> m_itemOrder;
|
||||
|
||||
public:
|
||||
using const_iterator = std::unordered_map<std::string, InterfaceItem&>::const_iterator;
|
||||
|
||||
inline const_iterator begin() const { return m_items.cbegin(); }
|
||||
inline const_iterator end() const { return m_items.cend(); }
|
||||
|
||||
const std::list<std::string>& names() const { return m_itemOrder; }
|
||||
|
||||
InterfaceItem* find(const std::string& name) const;
|
||||
void add(InterfaceItem& item);
|
||||
|
||||
inline InterfaceItem& operator[](const std::string& name) const { return m_items.at(name); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -34,8 +34,7 @@ Object::~Object()
|
||||
|
||||
InterfaceItem* Object::getItem(const std::string& name)
|
||||
{
|
||||
auto it = m_interfaceItems.find(name);
|
||||
return (it != m_interfaceItems.end()) ? &it->second : nullptr;
|
||||
return m_interfaceItems.find(name);
|
||||
}
|
||||
|
||||
//AbstractMethod* Object::getMethod(const std::string& name)
|
||||
|
||||
@ -245,14 +245,15 @@ void Session::writeObject(Message& message, const ObjectPtr& object)
|
||||
message.write(object->getClassId());
|
||||
|
||||
message.writeBlock(); // items
|
||||
for(auto& it : object->interfaceItems())
|
||||
const InterfaceItems& interfaceItems = object->interfaceItems();
|
||||
for(const std::string& name : interfaceItems.names())
|
||||
{
|
||||
InterfaceItem& item = it.second;
|
||||
InterfaceItem& item = interfaceItems[name];
|
||||
|
||||
// TODO: if(item. internal)
|
||||
|
||||
message.writeBlock(); // item
|
||||
message.write(item.name());
|
||||
message.write(name);
|
||||
|
||||
if(AbstractProperty* property = dynamic_cast<AbstractProperty*>(&item))
|
||||
{
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren