added methods to simplify some common actions

Dieser Commit ist enthalten in:
Reinder Feenstra 2021-04-05 16:23:45 +02:00
Ursprung 6f0c6d3dcf
Commit 39f5a518c3
3 geänderte Dateien mit 22 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -44,12 +44,12 @@ void Board::getTileData()
int Board::addTile(int16_t x, int16_t y, TileRotate rotate, const QString& id, bool replace, std::function<void(const bool&, Message::ErrorCode)> callback)
{
return callMethod(*m_connection, *getMethod("add_tile"), std::move(callback), x, y, rotate, id, replace);
return ::callMethod(*m_connection, *getMethod("add_tile"), std::move(callback), x, y, rotate, id, replace);
}
int Board::deleteTile(int16_t x, int16_t y, std::function<void(const bool&, Message::ErrorCode)> callback)
{
return callMethod(*m_connection, *getMethod("delete_tile"), std::move(callback), x, y);
return ::callMethod(*m_connection, *getMethod("delete_tile"), std::move(callback), x, y);
}
void Board::getTileDataResponse(const Message& response)

Datei anzeigen

@ -59,6 +59,14 @@ AbstractProperty* Object::getProperty(const QString& name)
return dynamic_cast<AbstractProperty*>(m_interfaceItems.find(name));
}
void Object::setPropertyValue(const QString& name, bool value)
{
if(AbstractProperty* property = getProperty(name))
property->setValueBool(value);
else
Q_ASSERT(false);
}
const Method* Object::getMethod(const QString& name) const
{
return dynamic_cast<const Method*>(m_interfaceItems.find(name));
@ -68,3 +76,11 @@ Method* Object::getMethod(const QString& name)
{
return dynamic_cast<Method*>(m_interfaceItems.find(name));
}
void Object::callMethod(const QString& name)
{
if(Method* method = getMethod(name))
method->call();
else
Q_ASSERT(false);
}

Datei anzeigen

@ -63,8 +63,12 @@ class Object : public QObject
const AbstractProperty* getProperty(const QString& name) const;
AbstractProperty* getProperty(const QString& name);
void setPropertyValue(const QString& name, bool value);
const Method* getMethod(const QString& name) const;
Method* getMethod(const QString& name);
void callMethod(const QString& name);
};
#endif