switch from spaces to tabs
This commit is contained in:
@ -28,38 +28,38 @@
|
|||||||
|
|
||||||
QJoysticks::QJoysticks()
|
QJoysticks::QJoysticks()
|
||||||
{
|
{
|
||||||
/* Initialize input methods */
|
/* Initialize input methods */
|
||||||
m_sdlJoysticks = new SDL_Joysticks(this);
|
m_sdlJoysticks = new SDL_Joysticks(this);
|
||||||
m_virtualJoystick = new VirtualJoystick(this);
|
m_virtualJoystick = new VirtualJoystick(this);
|
||||||
|
|
||||||
/* Configure SDL joysticks */
|
/* Configure SDL joysticks */
|
||||||
connect(sdlJoysticks(), &SDL_Joysticks::POVEvent, this, &QJoysticks::POVEvent);
|
connect(sdlJoysticks(), &SDL_Joysticks::POVEvent, this, &QJoysticks::POVEvent);
|
||||||
connect(sdlJoysticks(), &SDL_Joysticks::axisEvent, this, &QJoysticks::axisEvent);
|
connect(sdlJoysticks(), &SDL_Joysticks::axisEvent, this, &QJoysticks::axisEvent);
|
||||||
connect(sdlJoysticks(), &SDL_Joysticks::buttonEvent, this, &QJoysticks::buttonEvent);
|
connect(sdlJoysticks(), &SDL_Joysticks::buttonEvent, this, &QJoysticks::buttonEvent);
|
||||||
connect(sdlJoysticks(), &SDL_Joysticks::countChanged, this, &QJoysticks::updateInterfaces);
|
connect(sdlJoysticks(), &SDL_Joysticks::countChanged, this, &QJoysticks::updateInterfaces);
|
||||||
|
|
||||||
/* Configure virtual joysticks */
|
/* Configure virtual joysticks */
|
||||||
connect(virtualJoystick(), &VirtualJoystick::povEvent, this, &QJoysticks::POVEvent);
|
connect(virtualJoystick(), &VirtualJoystick::povEvent, this, &QJoysticks::POVEvent);
|
||||||
connect(virtualJoystick(), &VirtualJoystick::axisEvent, this, &QJoysticks::axisEvent);
|
connect(virtualJoystick(), &VirtualJoystick::axisEvent, this, &QJoysticks::axisEvent);
|
||||||
connect(virtualJoystick(), &VirtualJoystick::buttonEvent, this, &QJoysticks::buttonEvent);
|
connect(virtualJoystick(), &VirtualJoystick::buttonEvent, this, &QJoysticks::buttonEvent);
|
||||||
connect(virtualJoystick(), &VirtualJoystick::enabledChanged, this, &QJoysticks::updateInterfaces);
|
connect(virtualJoystick(), &VirtualJoystick::enabledChanged, this, &QJoysticks::updateInterfaces);
|
||||||
|
|
||||||
/* React to own signals to create QML signals */
|
/* React to own signals to create QML signals */
|
||||||
connect(this, &QJoysticks::POVEvent, this, &QJoysticks::onPOVEvent);
|
connect(this, &QJoysticks::POVEvent, this, &QJoysticks::onPOVEvent);
|
||||||
connect(this, &QJoysticks::axisEvent, this, &QJoysticks::onAxisEvent);
|
connect(this, &QJoysticks::axisEvent, this, &QJoysticks::onAxisEvent);
|
||||||
connect(this, &QJoysticks::buttonEvent, this, &QJoysticks::onButtonEvent);
|
connect(this, &QJoysticks::buttonEvent, this, &QJoysticks::onButtonEvent);
|
||||||
|
|
||||||
/* Configure the settings */
|
/* Configure the settings */
|
||||||
m_sortJoyticks = 0;
|
m_sortJoyticks = 0;
|
||||||
m_settings = new QSettings(qApp->organizationName(), qApp->applicationName());
|
m_settings = new QSettings(qApp->organizationName(), qApp->applicationName());
|
||||||
m_settings->beginGroup("Blacklisted Joysticks");
|
m_settings->beginGroup("Blacklisted Joysticks");
|
||||||
}
|
}
|
||||||
|
|
||||||
QJoysticks::~QJoysticks()
|
QJoysticks::~QJoysticks()
|
||||||
{
|
{
|
||||||
delete m_settings;
|
delete m_settings;
|
||||||
delete m_sdlJoysticks;
|
delete m_sdlJoysticks;
|
||||||
delete m_virtualJoystick;
|
delete m_virtualJoystick;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,8 +67,8 @@ QJoysticks::~QJoysticks()
|
|||||||
*/
|
*/
|
||||||
QJoysticks *QJoysticks::getInstance()
|
QJoysticks *QJoysticks::getInstance()
|
||||||
{
|
{
|
||||||
static QJoysticks joysticks;
|
static QJoysticks joysticks;
|
||||||
return &joysticks;
|
return &joysticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,7 +79,7 @@ QJoysticks *QJoysticks::getInstance()
|
|||||||
*/
|
*/
|
||||||
int QJoysticks::count() const
|
int QJoysticks::count() const
|
||||||
{
|
{
|
||||||
return inputDevices().count();
|
return inputDevices().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,13 +88,13 @@ int QJoysticks::count() const
|
|||||||
*/
|
*/
|
||||||
int QJoysticks::nonBlacklistedCount()
|
int QJoysticks::nonBlacklistedCount()
|
||||||
{
|
{
|
||||||
int cnt = count();
|
int cnt = count();
|
||||||
|
|
||||||
for (int i = 0; i < count(); ++i)
|
for (int i = 0; i < count(); ++i)
|
||||||
if (isBlacklisted(i))
|
if (isBlacklisted(i))
|
||||||
--cnt;
|
--cnt;
|
||||||
|
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,12 +105,12 @@ int QJoysticks::nonBlacklistedCount()
|
|||||||
*/
|
*/
|
||||||
QStringList QJoysticks::deviceNames() const
|
QStringList QJoysticks::deviceNames() const
|
||||||
{
|
{
|
||||||
QStringList names;
|
QStringList names;
|
||||||
|
|
||||||
foreach (QJoystickDevice *joystick, inputDevices())
|
foreach (QJoystickDevice *joystick, inputDevices())
|
||||||
names.append(joystick->name);
|
names.append(joystick->name);
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,10 +118,10 @@ QStringList QJoysticks::deviceNames() const
|
|||||||
*/
|
*/
|
||||||
int QJoysticks::getPOV(const int index, const int pov)
|
int QJoysticks::getPOV(const int index, const int pov)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return getInputDevice(index)->povs.at(pov);
|
return getInputDevice(index)->povs.at(pov);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,10 +129,10 @@ int QJoysticks::getPOV(const int index, const int pov)
|
|||||||
*/
|
*/
|
||||||
double QJoysticks::getAxis(const int index, const int axis)
|
double QJoysticks::getAxis(const int index, const int axis)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return getInputDevice(index)->axes.at(axis);
|
return getInputDevice(index)->axes.at(axis);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,10 +140,10 @@ double QJoysticks::getAxis(const int index, const int axis)
|
|||||||
*/
|
*/
|
||||||
bool QJoysticks::getButton(const int index, const int button)
|
bool QJoysticks::getButton(const int index, const int button)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return getInputDevice(index)->buttons.at(button);
|
return getInputDevice(index)->buttons.at(button);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,10 +151,10 @@ bool QJoysticks::getButton(const int index, const int button)
|
|||||||
*/
|
*/
|
||||||
int QJoysticks::getNumAxes(const int index)
|
int QJoysticks::getNumAxes(const int index)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return getInputDevice(index)->axes.count();
|
return getInputDevice(index)->axes.count();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,10 +162,10 @@ int QJoysticks::getNumAxes(const int index)
|
|||||||
*/
|
*/
|
||||||
int QJoysticks::getNumPOVs(const int index)
|
int QJoysticks::getNumPOVs(const int index)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return getInputDevice(index)->povs.count();
|
return getInputDevice(index)->povs.count();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,10 +173,10 @@ int QJoysticks::getNumPOVs(const int index)
|
|||||||
*/
|
*/
|
||||||
int QJoysticks::getNumButtons(const int index)
|
int QJoysticks::getNumButtons(const int index)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return getInputDevice(index)->buttons.count();
|
return getInputDevice(index)->buttons.count();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,10 +184,10 @@ int QJoysticks::getNumButtons(const int index)
|
|||||||
*/
|
*/
|
||||||
bool QJoysticks::isBlacklisted(const int index)
|
bool QJoysticks::isBlacklisted(const int index)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return inputDevices().at(index)->blacklisted;
|
return inputDevices().at(index)->blacklisted;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,7 +196,7 @@ bool QJoysticks::isBlacklisted(const int index)
|
|||||||
*/
|
*/
|
||||||
bool QJoysticks::joystickExists(const int index)
|
bool QJoysticks::joystickExists(const int index)
|
||||||
{
|
{
|
||||||
return (index >= 0) && (count() > index);
|
return (index >= 0) && (count() > index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,10 +204,10 @@ bool QJoysticks::joystickExists(const int index)
|
|||||||
*/
|
*/
|
||||||
QString QJoysticks::getName(const int index)
|
QString QJoysticks::getName(const int index)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return m_devices.at(index)->name;
|
return m_devices.at(index)->name;
|
||||||
|
|
||||||
return "Invalid Joystick";
|
return "Invalid Joystick";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,7 +217,7 @@ QString QJoysticks::getName(const int index)
|
|||||||
*/
|
*/
|
||||||
SDL_Joysticks *QJoysticks::sdlJoysticks() const
|
SDL_Joysticks *QJoysticks::sdlJoysticks() const
|
||||||
{
|
{
|
||||||
return m_sdlJoysticks;
|
return m_sdlJoysticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -230,7 +230,7 @@ SDL_Joysticks *QJoysticks::sdlJoysticks() const
|
|||||||
*/
|
*/
|
||||||
VirtualJoystick *QJoysticks::virtualJoystick() const
|
VirtualJoystick *QJoysticks::virtualJoystick() const
|
||||||
{
|
{
|
||||||
return m_virtualJoystick;
|
return m_virtualJoystick;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -238,10 +238,10 @@ VirtualJoystick *QJoysticks::virtualJoystick() const
|
|||||||
*/
|
*/
|
||||||
QJoystickDevice *QJoysticks::getInputDevice(const int index)
|
QJoystickDevice *QJoysticks::getInputDevice(const int index)
|
||||||
{
|
{
|
||||||
if (joystickExists(index))
|
if (joystickExists(index))
|
||||||
return inputDevices().at(index);
|
return inputDevices().at(index);
|
||||||
|
|
||||||
return Q_NULLPTR;
|
return Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -251,7 +251,7 @@ QJoystickDevice *QJoysticks::getInputDevice(const int index)
|
|||||||
*/
|
*/
|
||||||
QList<QJoystickDevice *> QJoysticks::inputDevices() const
|
QList<QJoystickDevice *> QJoysticks::inputDevices() const
|
||||||
{
|
{
|
||||||
return m_devices;
|
return m_devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -260,11 +260,11 @@ QList<QJoystickDevice *> QJoysticks::inputDevices() const
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::setSortJoysticksByBlacklistState(bool sort)
|
void QJoysticks::setSortJoysticksByBlacklistState(bool sort)
|
||||||
{
|
{
|
||||||
if (m_sortJoyticks != sort)
|
if (m_sortJoyticks != sort)
|
||||||
{
|
{
|
||||||
m_sortJoyticks = sort;
|
m_sortJoyticks = sort;
|
||||||
updateInterfaces();
|
updateInterfaces();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -275,31 +275,31 @@ void QJoysticks::setSortJoysticksByBlacklistState(bool sort)
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::setBlacklisted(const int index, bool blacklisted)
|
void QJoysticks::setBlacklisted(const int index, bool blacklisted)
|
||||||
{
|
{
|
||||||
Q_ASSERT(joystickExists(index));
|
Q_ASSERT(joystickExists(index));
|
||||||
|
|
||||||
/* Netrualize the joystick */
|
/* Netrualize the joystick */
|
||||||
if (blacklisted)
|
if (blacklisted)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < getNumAxes(index); ++i)
|
for (int i = 0; i < getNumAxes(index); ++i)
|
||||||
emit axisChanged(index, i, 0);
|
emit axisChanged(index, i, 0);
|
||||||
|
|
||||||
for (int i = 0; i < getNumButtons(index); ++i)
|
for (int i = 0; i < getNumButtons(index); ++i)
|
||||||
emit buttonChanged(index, i, false);
|
emit buttonChanged(index, i, false);
|
||||||
|
|
||||||
for (int i = 0; i < getNumPOVs(index); ++i)
|
for (int i = 0; i < getNumPOVs(index); ++i)
|
||||||
emit povChanged(index, i, 0);
|
emit povChanged(index, i, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if blacklist value was actually changed */
|
/* See if blacklist value was actually changed */
|
||||||
bool changed = m_devices.at(index)->blacklisted != blacklisted;
|
bool changed = m_devices.at(index)->blacklisted != blacklisted;
|
||||||
|
|
||||||
/* Save settings */
|
/* Save settings */
|
||||||
m_devices.at(index)->blacklisted = blacklisted;
|
m_devices.at(index)->blacklisted = blacklisted;
|
||||||
m_settings->setValue(getName(index), blacklisted);
|
m_settings->setValue(getName(index), blacklisted);
|
||||||
|
|
||||||
/* Re-scan joysticks if blacklist value has changed */
|
/* Re-scan joysticks if blacklist value has changed */
|
||||||
if (changed)
|
if (changed)
|
||||||
updateInterfaces();
|
updateInterfaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -307,76 +307,76 @@ void QJoysticks::setBlacklisted(const int index, bool blacklisted)
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::updateInterfaces()
|
void QJoysticks::updateInterfaces()
|
||||||
{
|
{
|
||||||
m_devices.clear();
|
m_devices.clear();
|
||||||
|
|
||||||
/* Put blacklisted joysticks at the bottom of the list */
|
/* Put blacklisted joysticks at the bottom of the list */
|
||||||
if (m_sortJoyticks)
|
if (m_sortJoyticks)
|
||||||
{
|
{
|
||||||
/* Register non-blacklisted SDL joysticks */
|
/* Register non-blacklisted SDL joysticks */
|
||||||
foreach (QJoystickDevice *joystick, sdlJoysticks()->joysticks())
|
foreach (QJoystickDevice *joystick, sdlJoysticks()->joysticks())
|
||||||
{
|
{
|
||||||
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
||||||
if (!joystick->blacklisted)
|
if (!joystick->blacklisted)
|
||||||
addInputDevice(joystick);
|
addInputDevice(joystick);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register the virtual joystick (if its not blacklisted) */
|
/* Register the virtual joystick (if its not blacklisted) */
|
||||||
if (virtualJoystick()->joystickEnabled())
|
if (virtualJoystick()->joystickEnabled())
|
||||||
{
|
{
|
||||||
QJoystickDevice *joystick = virtualJoystick()->joystick();
|
QJoystickDevice *joystick = virtualJoystick()->joystick();
|
||||||
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
||||||
|
|
||||||
if (!joystick->blacklisted)
|
if (!joystick->blacklisted)
|
||||||
{
|
{
|
||||||
addInputDevice(joystick);
|
addInputDevice(joystick);
|
||||||
virtualJoystick()->setJoystickID(inputDevices().count() - 1);
|
virtualJoystick()->setJoystickID(inputDevices().count() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register blacklisted SDL joysticks */
|
/* Register blacklisted SDL joysticks */
|
||||||
foreach (QJoystickDevice *joystick, sdlJoysticks()->joysticks())
|
foreach (QJoystickDevice *joystick, sdlJoysticks()->joysticks())
|
||||||
{
|
{
|
||||||
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
||||||
if (joystick->blacklisted)
|
if (joystick->blacklisted)
|
||||||
addInputDevice(joystick);
|
addInputDevice(joystick);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register the virtual joystick (if its blacklisted) */
|
/* Register the virtual joystick (if its blacklisted) */
|
||||||
if (virtualJoystick()->joystickEnabled())
|
if (virtualJoystick()->joystickEnabled())
|
||||||
{
|
{
|
||||||
QJoystickDevice *joystick = virtualJoystick()->joystick();
|
QJoystickDevice *joystick = virtualJoystick()->joystick();
|
||||||
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
||||||
|
|
||||||
if (joystick->blacklisted)
|
if (joystick->blacklisted)
|
||||||
{
|
{
|
||||||
addInputDevice(joystick);
|
addInputDevice(joystick);
|
||||||
virtualJoystick()->setJoystickID(inputDevices().count() - 1);
|
virtualJoystick()->setJoystickID(inputDevices().count() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sort normally */
|
/* Sort normally */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Register SDL joysticks */
|
/* Register SDL joysticks */
|
||||||
foreach (QJoystickDevice *joystick, sdlJoysticks()->joysticks())
|
foreach (QJoystickDevice *joystick, sdlJoysticks()->joysticks())
|
||||||
{
|
{
|
||||||
addInputDevice(joystick);
|
addInputDevice(joystick);
|
||||||
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register virtual joystick */
|
/* Register virtual joystick */
|
||||||
if (virtualJoystick()->joystickEnabled())
|
if (virtualJoystick()->joystickEnabled())
|
||||||
{
|
{
|
||||||
QJoystickDevice *joystick = virtualJoystick()->joystick();
|
QJoystickDevice *joystick = virtualJoystick()->joystick();
|
||||||
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
joystick->blacklisted = m_settings->value(joystick->name, false).toBool();
|
||||||
|
|
||||||
addInputDevice(joystick);
|
addInputDevice(joystick);
|
||||||
virtualJoystick()->setJoystickID(inputDevices().count() - 1);
|
virtualJoystick()->setJoystickID(inputDevices().count() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,7 +387,7 @@ void QJoysticks::updateInterfaces()
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::setVirtualJoystickRange(qreal range)
|
void QJoysticks::setVirtualJoystickRange(qreal range)
|
||||||
{
|
{
|
||||||
virtualJoystick()->setAxisRange(range);
|
virtualJoystick()->setAxisRange(range);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -395,12 +395,12 @@ void QJoysticks::setVirtualJoystickRange(qreal range)
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::setVirtualJoystickEnabled(bool enabled)
|
void QJoysticks::setVirtualJoystickEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
virtualJoystick()->setJoystickEnabled(enabled);
|
virtualJoystick()->setJoystickEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QJoysticks::setVirtualJoystickAxisSensibility(qreal sensibility)
|
void QJoysticks::setVirtualJoystickAxisSensibility(qreal sensibility)
|
||||||
{
|
{
|
||||||
virtualJoystick()->setAxisSensibility(sensibility);
|
virtualJoystick()->setAxisSensibility(sensibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -408,8 +408,8 @@ void QJoysticks::setVirtualJoystickAxisSensibility(qreal sensibility)
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::resetJoysticks()
|
void QJoysticks::resetJoysticks()
|
||||||
{
|
{
|
||||||
m_devices.clear();
|
m_devices.clear();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -417,8 +417,8 @@ void QJoysticks::resetJoysticks()
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::addInputDevice(QJoystickDevice *device)
|
void QJoysticks::addInputDevice(QJoystickDevice *device)
|
||||||
{
|
{
|
||||||
Q_ASSERT(device);
|
Q_ASSERT(device);
|
||||||
m_devices.append(device);
|
m_devices.append(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -427,17 +427,17 @@ void QJoysticks::addInputDevice(QJoystickDevice *device)
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::onPOVEvent(const QJoystickPOVEvent &e)
|
void QJoysticks::onPOVEvent(const QJoystickPOVEvent &e)
|
||||||
{
|
{
|
||||||
if (e.joystick == nullptr)
|
if (e.joystick == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isBlacklisted(e.joystick->id))
|
if (!isBlacklisted(e.joystick->id))
|
||||||
{
|
{
|
||||||
if (e.pov < getInputDevice(e.joystick->id)->povs.count())
|
if (e.pov < getInputDevice(e.joystick->id)->povs.count())
|
||||||
{
|
{
|
||||||
getInputDevice(e.joystick->id)->povs[e.pov] = e.angle;
|
getInputDevice(e.joystick->id)->povs[e.pov] = e.angle;
|
||||||
emit povChanged(e.joystick->id, e.pov, e.angle);
|
emit povChanged(e.joystick->id, e.pov, e.angle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -446,17 +446,17 @@ void QJoysticks::onPOVEvent(const QJoystickPOVEvent &e)
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::onAxisEvent(const QJoystickAxisEvent &e)
|
void QJoysticks::onAxisEvent(const QJoystickAxisEvent &e)
|
||||||
{
|
{
|
||||||
if (e.joystick == nullptr)
|
if (e.joystick == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isBlacklisted(e.joystick->id))
|
if (!isBlacklisted(e.joystick->id))
|
||||||
{
|
{
|
||||||
if (e.axis < getInputDevice(e.joystick->id)->axes.count())
|
if (e.axis < getInputDevice(e.joystick->id)->axes.count())
|
||||||
{
|
{
|
||||||
getInputDevice(e.joystick->id)->axes[e.axis] = e.value;
|
getInputDevice(e.joystick->id)->axes[e.axis] = e.value;
|
||||||
emit axisChanged(e.joystick->id, e.axis, e.value);
|
emit axisChanged(e.joystick->id, e.axis, e.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -465,15 +465,15 @@ void QJoysticks::onAxisEvent(const QJoystickAxisEvent &e)
|
|||||||
*/
|
*/
|
||||||
void QJoysticks::onButtonEvent(const QJoystickButtonEvent &e)
|
void QJoysticks::onButtonEvent(const QJoystickButtonEvent &e)
|
||||||
{
|
{
|
||||||
if (e.joystick == nullptr)
|
if (e.joystick == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isBlacklisted(e.joystick->id))
|
if (!isBlacklisted(e.joystick->id))
|
||||||
{
|
{
|
||||||
if (e.button < getInputDevice(e.joystick->id)->buttons.count())
|
if (e.button < getInputDevice(e.joystick->id)->buttons.count())
|
||||||
{
|
{
|
||||||
getInputDevice(e.joystick->id)->buttons[e.button] = e.pressed;
|
getInputDevice(e.joystick->id)->buttons[e.button] = e.pressed;
|
||||||
emit buttonChanged(e.joystick->id, e.button, e.pressed);
|
emit buttonChanged(e.joystick->id, e.button, e.pressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,73 +50,73 @@ class VirtualJoystick;
|
|||||||
*/
|
*/
|
||||||
class QJoysticks : public QObject
|
class QJoysticks : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||||
Q_PROPERTY(int nonBlacklistedCount READ nonBlacklistedCount NOTIFY countChanged)
|
Q_PROPERTY(int nonBlacklistedCount READ nonBlacklistedCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(QStringList deviceNames READ deviceNames NOTIFY countChanged)
|
Q_PROPERTY(QStringList deviceNames READ deviceNames NOTIFY countChanged)
|
||||||
|
|
||||||
friend class Test_QJoysticks;
|
friend class Test_QJoysticks;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void countChanged();
|
void countChanged();
|
||||||
void enabledChanged(const bool enabled);
|
void enabledChanged(const bool enabled);
|
||||||
void POVEvent(const QJoystickPOVEvent &event);
|
void POVEvent(const QJoystickPOVEvent &event);
|
||||||
void axisEvent(const QJoystickAxisEvent &event);
|
void axisEvent(const QJoystickAxisEvent &event);
|
||||||
void buttonEvent(const QJoystickButtonEvent &event);
|
void buttonEvent(const QJoystickButtonEvent &event);
|
||||||
void povChanged(const int js, const int pov, const int angle);
|
void povChanged(const int js, const int pov, const int angle);
|
||||||
void axisChanged(const int js, const int axis, const qreal value);
|
void axisChanged(const int js, const int axis, const qreal value);
|
||||||
void buttonChanged(const int js, const int button, const bool pressed);
|
void buttonChanged(const int js, const int button, const bool pressed);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QJoysticks *getInstance();
|
static QJoysticks *getInstance();
|
||||||
|
|
||||||
int count() const;
|
int count() const;
|
||||||
int nonBlacklistedCount();
|
int nonBlacklistedCount();
|
||||||
QStringList deviceNames() const;
|
QStringList deviceNames() const;
|
||||||
|
|
||||||
Q_INVOKABLE int getPOV(const int index, const int pov);
|
Q_INVOKABLE int getPOV(const int index, const int pov);
|
||||||
Q_INVOKABLE double getAxis(const int index, const int axis);
|
Q_INVOKABLE double getAxis(const int index, const int axis);
|
||||||
Q_INVOKABLE bool getButton(const int index, const int button);
|
Q_INVOKABLE bool getButton(const int index, const int button);
|
||||||
|
|
||||||
Q_INVOKABLE int getNumAxes(const int index);
|
Q_INVOKABLE int getNumAxes(const int index);
|
||||||
Q_INVOKABLE int getNumPOVs(const int index);
|
Q_INVOKABLE int getNumPOVs(const int index);
|
||||||
Q_INVOKABLE int getNumButtons(const int index);
|
Q_INVOKABLE int getNumButtons(const int index);
|
||||||
Q_INVOKABLE bool isBlacklisted(const int index);
|
Q_INVOKABLE bool isBlacklisted(const int index);
|
||||||
Q_INVOKABLE bool joystickExists(const int index);
|
Q_INVOKABLE bool joystickExists(const int index);
|
||||||
Q_INVOKABLE QString getName(const int index);
|
Q_INVOKABLE QString getName(const int index);
|
||||||
|
|
||||||
SDL_Joysticks *sdlJoysticks() const;
|
SDL_Joysticks *sdlJoysticks() const;
|
||||||
VirtualJoystick *virtualJoystick() const;
|
VirtualJoystick *virtualJoystick() const;
|
||||||
QJoystickDevice *getInputDevice(const int index);
|
QJoystickDevice *getInputDevice(const int index);
|
||||||
QList<QJoystickDevice *> inputDevices() const;
|
QList<QJoystickDevice *> inputDevices() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateInterfaces();
|
void updateInterfaces();
|
||||||
void setVirtualJoystickRange(qreal range);
|
void setVirtualJoystickRange(qreal range);
|
||||||
void setVirtualJoystickEnabled(bool enabled);
|
void setVirtualJoystickEnabled(bool enabled);
|
||||||
void setVirtualJoystickAxisSensibility(qreal sensibility);
|
void setVirtualJoystickAxisSensibility(qreal sensibility);
|
||||||
void setSortJoysticksByBlacklistState(bool sort);
|
void setSortJoysticksByBlacklistState(bool sort);
|
||||||
void setBlacklisted(int index, bool blacklisted);
|
void setBlacklisted(int index, bool blacklisted);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit QJoysticks();
|
explicit QJoysticks();
|
||||||
~QJoysticks();
|
~QJoysticks();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void resetJoysticks();
|
void resetJoysticks();
|
||||||
void addInputDevice(QJoystickDevice *device);
|
void addInputDevice(QJoystickDevice *device);
|
||||||
void onPOVEvent(const QJoystickPOVEvent &e);
|
void onPOVEvent(const QJoystickPOVEvent &e);
|
||||||
void onAxisEvent(const QJoystickAxisEvent &e);
|
void onAxisEvent(const QJoystickAxisEvent &e);
|
||||||
void onButtonEvent(const QJoystickButtonEvent &e);
|
void onButtonEvent(const QJoystickButtonEvent &e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_sortJoyticks;
|
bool m_sortJoyticks;
|
||||||
|
|
||||||
QSettings *m_settings;
|
QSettings *m_settings;
|
||||||
SDL_Joysticks *m_sdlJoysticks;
|
SDL_Joysticks *m_sdlJoysticks;
|
||||||
VirtualJoystick *m_virtualJoystick;
|
VirtualJoystick *m_virtualJoystick;
|
||||||
|
|
||||||
QList<QJoystickDevice *> m_devices;
|
QList<QJoystickDevice *> m_devices;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
#include "auxitem.h"
|
#include "auxitem.h"
|
||||||
|
|
||||||
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value,
|
||||||
|
QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuxItem::setValue(uint8_t value)
|
void AuxItem::setValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
Item::setValue(value);
|
||||||
micro_->setAuxPwm(value);
|
micro_->setAuxPwm(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuxItem::store(QJsonObject &json)
|
void AuxItem::store(QJsonObject &json)
|
||||||
{
|
{
|
||||||
json["Type"] = "Aux";
|
json["Type"] = "Aux";
|
||||||
Item::store(json);
|
Item::store(json);
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,17 @@
|
|||||||
|
|
||||||
class AuxItem: public Item
|
class AuxItem: public Item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Microcontroller* micro_;
|
Microcontroller* micro_;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
virtual void setValue(uint8_t value);
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||||
|
uint8_t value = 0, QObject* parent = nullptr);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
#include "auxitem.h"
|
#include "auxitem.h"
|
||||||
|
|
||||||
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value,
|
||||||
|
QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuxItem::setValue(uint8_t value)
|
void AuxItem::setValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
Item::setValue(value);
|
||||||
micro_->setAuxPwm(value);
|
micro_->setAuxPwm(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuxItem::store(QJsonObject &json)
|
void AuxItem::store(QJsonObject &json)
|
||||||
{
|
{
|
||||||
json["Type"] = "Aux";
|
json["Type"] = "Aux";
|
||||||
Item::store(json);
|
Item::store(json);
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,17 @@
|
|||||||
|
|
||||||
class AuxItem: public Item
|
class AuxItem: public Item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Microcontroller* micro_;
|
Microcontroller* micro_;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
virtual void setValue(uint8_t value);
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||||
|
uint8_t value = 0, QObject* parent = nullptr);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
@ -10,28 +10,29 @@ ItemData::ItemData(uint32_t itemIdIn, QString name, int8_t value): name_(name),
|
|||||||
|
|
||||||
QString ItemData::getName() const
|
QString ItemData::getName() const
|
||||||
{
|
{
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemData::setName(QString name)
|
void ItemData::setName(QString name)
|
||||||
{
|
{
|
||||||
name_ = name;
|
name_ = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t ItemData::getValue() const
|
int8_t ItemData::getValue() const
|
||||||
{
|
{
|
||||||
return value_;
|
return value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ItemData::id() const
|
uint32_t ItemData::id() const
|
||||||
{
|
{
|
||||||
return itemId_;
|
return itemId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//item
|
//item
|
||||||
|
|
||||||
Item::Item(uint32_t itemIdIn, QString name, int8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name, value)
|
Item::Item(uint32_t itemIdIn, QString name, int8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
||||||
|
value)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -47,16 +48,16 @@ Item::~Item()
|
|||||||
|
|
||||||
void Item::setFunction(uint8_t function, bool on)
|
void Item::setFunction(uint8_t function, bool on)
|
||||||
{
|
{
|
||||||
functionChanged(function, on);
|
functionChanged(function, on);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::setValue(int8_t value)
|
void Item::setValue(int8_t value)
|
||||||
{
|
{
|
||||||
value_ = value;
|
value_ = value;
|
||||||
valueChanged(value_);
|
valueChanged(value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::informValue(int8_t value)
|
void Item::informValue(int8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
Item::setValue(value);
|
||||||
}
|
}
|
||||||
|
@ -11,28 +11,34 @@ class Actor;
|
|||||||
class ItemData
|
class ItemData
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
QString name_;
|
QString name_;
|
||||||
int8_t value_;
|
int8_t value_;
|
||||||
uint32_t itemId_;
|
uint32_t itemId_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", int8_t value = 0);
|
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", int8_t value = 0);
|
||||||
|
|
||||||
inline bool operator==(const ItemData& in) const{ return itemId_==in.itemId_; }
|
inline bool operator==(const ItemData& in) const
|
||||||
inline bool operator!=(const ItemData& in) const{ return itemId_!=in.itemId_; }
|
{
|
||||||
|
return itemId_==in.itemId_;
|
||||||
|
}
|
||||||
|
inline bool operator!=(const ItemData& in) const
|
||||||
|
{
|
||||||
|
return itemId_!=in.itemId_;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t id() const;
|
uint32_t id() const;
|
||||||
|
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
int8_t getValue() const;
|
int8_t getValue() const;
|
||||||
virtual QString getName() const;
|
virtual QString getName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Item: public QObject, public ItemData
|
class Item: public QObject, public ItemData
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -43,14 +49,15 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
virtual void setValue(int8_t value);
|
virtual void setValue(int8_t value);
|
||||||
virtual void setFunction(uint8_t funciton, bool value);
|
virtual void setFunction(uint8_t funciton, bool value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", int8_t value = 0, QObject *parent = nullptr);
|
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", int8_t value = 0,
|
||||||
Item(const ItemData& itemData, QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
Item(const ItemData& itemData, QObject *parent = nullptr);
|
||||||
|
|
||||||
virtual ~Item();
|
virtual ~Item();
|
||||||
|
|
||||||
void informValue(int8_t value);
|
void informValue(int8_t value);
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@ void ItemStore::addItem(std::shared_ptr<Item> item)
|
|||||||
qWarning()<<"invalid item";
|
qWarning()<<"invalid item";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool mached = false;
|
bool mached = false;
|
||||||
for(unsigned i = 0; i < items_.size(); i++ )
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
if(*items_[i] == *item) mached = true;
|
if(*items_[i] == *item) mached = true;
|
||||||
if(!mached)
|
if(!mached)
|
||||||
{
|
{
|
||||||
items_.push_back(std::shared_ptr<Item>(item));
|
items_.push_back(std::shared_ptr<Item>(item));
|
||||||
|
|
||||||
if(dynamic_cast<Train*>(item.get()))
|
if(dynamic_cast<Train*>(item.get()))
|
||||||
{
|
{
|
||||||
@ -36,9 +36,9 @@ void ItemStore::addItem(std::shared_ptr<Item> item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||||
}
|
}
|
||||||
qDebug()<<"Got item: "<<item->id()<<" matched: "<<mached;
|
qDebug()<<"Got item: "<<item->id()<<" matched: "<<mached;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::jsReqNewItem()
|
void ItemStore::jsReqNewItem()
|
||||||
@ -69,43 +69,43 @@ void ItemStore::jsReqNewItem()
|
|||||||
|
|
||||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
||||||
{
|
{
|
||||||
for(unsigned j = 0; j < itemIn.size(); j++)
|
for(unsigned j = 0; j < itemIn.size(); j++)
|
||||||
addItem(itemIn[j]);
|
addItem(itemIn[j]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::removeItem(const ItemData& item)
|
void ItemStore::removeItem(const ItemData& item)
|
||||||
{
|
{
|
||||||
for(unsigned j = 0; j < items_.size(); j++)
|
for(unsigned j = 0; j < items_.size(); j++)
|
||||||
{
|
{
|
||||||
if(item == *items_[j])
|
if(item == *items_[j])
|
||||||
{
|
{
|
||||||
items_.erase(items_.begin()+j);
|
items_.erase(items_.begin()+j);
|
||||||
--j;
|
--j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ItemStore::clear()
|
void ItemStore::clear()
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]);
|
for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]);
|
||||||
items_.clear();
|
items_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ItemStore::itemStateChanged(const ItemData& item)
|
void ItemStore::itemStateChanged(const ItemData& item)
|
||||||
{
|
{
|
||||||
|
|
||||||
for(unsigned i = 0; i < items_.size(); i++ )
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
{
|
{
|
||||||
if(items_[i]->operator==(item))
|
if(items_[i]->operator==(item))
|
||||||
{
|
{
|
||||||
|
|
||||||
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,18 +7,21 @@
|
|||||||
|
|
||||||
class ItemStore: public QObject
|
class ItemStore: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
std::vector< std::shared_ptr<Item> > items_;
|
std::vector< std::shared_ptr<Item> > items_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ItemStore(QObject *parent = nullptr);
|
ItemStore(QObject *parent = nullptr);
|
||||||
virtual ~ItemStore(){}
|
virtual ~ItemStore() {}
|
||||||
|
|
||||||
inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
|
inline std::vector< std::shared_ptr<Item> >* getItems()
|
||||||
|
{
|
||||||
|
return &items_;
|
||||||
|
}
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
@ -26,13 +29,13 @@ private slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void itemDeleted(ItemData item);
|
void itemDeleted(ItemData item);
|
||||||
void itemAdded(std::weak_ptr<Item> Item);
|
void itemAdded(std::weak_ptr<Item> Item);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void removeItem(const ItemData& item);
|
void removeItem(const ItemData& item);
|
||||||
void addItem(std::shared_ptr<Item> item);
|
void addItem(std::shared_ptr<Item> item);
|
||||||
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
|
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
|
||||||
void itemStateChanged(const ItemData& item);
|
void itemStateChanged(const ItemData& item);
|
||||||
};
|
};
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
Train::Train(uint8_t id, uint8_t address, uint8_t functionMask, int8_t initalValue):
|
Train::Train(uint8_t id, uint8_t address, uint8_t functionMask, int8_t initalValue):
|
||||||
Item(address, QString("Train ")+QString::number(id), initalValue),
|
Item(address, QString("Train ")+QString::number(id), initalValue),
|
||||||
functionMask_(functionMask),
|
functionMask_(functionMask),
|
||||||
train_id_(id)
|
train_id_(id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11,21 +11,21 @@ Microcontroller *Train::micro = nullptr;
|
|||||||
|
|
||||||
void Train::setFunction(uint8_t funciton, bool value)
|
void Train::setFunction(uint8_t funciton, bool value)
|
||||||
{
|
{
|
||||||
Item::setFunction(funciton, value);
|
Item::setFunction(funciton, value);
|
||||||
if(micro)
|
if(micro)
|
||||||
micro->trainSetFunction(train_id_, funciton, value);
|
micro->trainSetFunction(train_id_, funciton, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Train::setValue(int8_t value)
|
void Train::setValue(int8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
Item::setValue(value);
|
||||||
if(micro)
|
if(micro)
|
||||||
micro->trainSetSpeed(train_id_, value);
|
micro->trainSetSpeed(train_id_, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Train::reverse()
|
void Train::reverse()
|
||||||
{
|
{
|
||||||
if(micro)
|
if(micro)
|
||||||
micro->trainReverse(train_id_);
|
micro->trainReverse(train_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,21 +6,27 @@
|
|||||||
|
|
||||||
class Train : public Item
|
class Train : public Item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
uint8_t functionMask_;
|
uint8_t functionMask_;
|
||||||
uint8_t train_id_;
|
uint8_t train_id_;
|
||||||
public:
|
public:
|
||||||
static Microcontroller *micro;
|
static Microcontroller *micro;
|
||||||
|
|
||||||
Train(uint8_t id = 0, uint8_t address = 0, uint8_t functionMask = 0, int8_t initalValue = 0);
|
Train(uint8_t id = 0, uint8_t address = 0, uint8_t functionMask = 0, int8_t initalValue = 0);
|
||||||
|
|
||||||
uint8_t getFunctionMask() {return functionMask_;}
|
uint8_t getFunctionMask()
|
||||||
|
{
|
||||||
|
return functionMask_;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void reverse();
|
void reverse();
|
||||||
virtual void setFunction(uint8_t function, bool on);
|
virtual void setFunction(uint8_t function, bool on);
|
||||||
virtual void setValue(int8_t value);
|
virtual void setValue(int8_t value);
|
||||||
uint8_t getTrainId(){return train_id_;}
|
uint8_t getTrainId()
|
||||||
|
{
|
||||||
|
return train_id_;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRAIN_H
|
#endif // TRAIN_H
|
||||||
|
@ -6,13 +6,13 @@ Turnout::Turnout(uint8_t id, uint8_t address, uint8_t subaddress, int8_t initalV
|
|||||||
: Item(address | (subaddress << 8), QString("Turnout ")+QString::number(id), initalValue),
|
: Item(address | (subaddress << 8), QString("Turnout ")+QString::number(id), initalValue),
|
||||||
subaddress_(subaddress), turnoutId_(id)
|
subaddress_(subaddress), turnoutId_(id)
|
||||||
{
|
{
|
||||||
itemId_ = address | (subaddress << 8);
|
itemId_ = address | (subaddress << 8);
|
||||||
name_ = QString("Turnout ")+QString::number(id);
|
name_ = QString("Turnout ")+QString::number(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Turnout::setValue(int8_t value)
|
void Turnout::setValue(int8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
Item::setValue(value);
|
||||||
if(micro)
|
if(micro)
|
||||||
micro->tunoutSetDirection(turnoutId_, value > 0);
|
micro->tunoutSetDirection(turnoutId_, value > 0);
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,17 @@
|
|||||||
|
|
||||||
class Turnout : public Item
|
class Turnout : public Item
|
||||||
{
|
{
|
||||||
uint8_t subaddress_;
|
uint8_t subaddress_;
|
||||||
uint8_t turnoutId_;
|
uint8_t turnoutId_;
|
||||||
public:
|
public:
|
||||||
static Microcontroller *micro;
|
static Microcontroller *micro;
|
||||||
|
|
||||||
explicit Turnout(uint8_t id = 0, uint8_t address = 0, uint8_t subaddress = 0, int8_t initalValue = 0);
|
explicit Turnout(uint8_t id = 0, uint8_t address = 0, uint8_t subaddress = 0, int8_t initalValue = 0);
|
||||||
virtual void setValue(int8_t value);
|
virtual void setValue(int8_t value);
|
||||||
uint8_t getTurnoutId(){return turnoutId_;}
|
uint8_t getTurnoutId()
|
||||||
|
{
|
||||||
|
return turnoutId_;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TURNOUT_H
|
#endif // TURNOUT_H
|
||||||
|
145
src/main.cpp
145
src/main.cpp
@ -18,94 +18,97 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
//set info
|
//set info
|
||||||
QCoreApplication::setOrganizationName("UVOS");
|
QCoreApplication::setOrganizationName("UVOS");
|
||||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||||
QCoreApplication::setApplicationName("traincontrollerui");
|
QCoreApplication::setApplicationName("traincontrollerui");
|
||||||
QCoreApplication::setApplicationVersion("0.1");
|
QCoreApplication::setApplicationVersion("0.1");
|
||||||
|
|
||||||
QDir::setCurrent(a.applicationDirPath());
|
QDir::setCurrent(a.applicationDirPath());
|
||||||
|
|
||||||
//parse comand line
|
//parse comand line
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("Smart Home Interface");
|
parser.setApplicationDescription("Smart Home Interface");
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
|
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
|
||||||
parser.addOption(tcpOption);
|
parser.addOption(tcpOption);
|
||||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "adress");
|
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main",
|
||||||
parser.addOption(hostOption);
|
"Set server host ip addres"), "adress");
|
||||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port in TCP mode or Serial port in serial mode"), "port");
|
parser.addOption(hostOption);
|
||||||
parser.addOption(portOption);
|
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main",
|
||||||
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main", "Use serial connection"));
|
"Set server Port in TCP mode or Serial port in serial mode"), "port");
|
||||||
parser.addOption(serialOption);
|
parser.addOption(portOption);
|
||||||
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
|
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main",
|
||||||
parser.addOption(baudOption);
|
"Use serial connection"));
|
||||||
parser.process(a);
|
parser.addOption(serialOption);
|
||||||
|
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
|
||||||
|
parser.addOption(baudOption);
|
||||||
|
parser.process(a);
|
||||||
|
|
||||||
QIODevice* masterIODevice = nullptr;
|
QIODevice* masterIODevice = nullptr;
|
||||||
|
|
||||||
if(parser.isSet(tcpOption))
|
if(parser.isSet(tcpOption))
|
||||||
{
|
{
|
||||||
QTcpSocket* microSocket = new QTcpSocket;
|
QTcpSocket* microSocket = new QTcpSocket;
|
||||||
|
|
||||||
int port = 6856;
|
int port = 6856;
|
||||||
if(parser.isSet(portOption)) port = parser.value(portOption).toInt();
|
if(parser.isSet(portOption)) port = parser.value(portOption).toInt();
|
||||||
|
|
||||||
QString host("127.0.0.1");
|
QString host("127.0.0.1");
|
||||||
if(parser.isSet(hostOption)) host = parser.value(hostOption);
|
if(parser.isSet(hostOption)) host = parser.value(hostOption);
|
||||||
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
|
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
|
||||||
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
||||||
if(!microSocket->waitForConnected(3000))
|
if(!microSocket->waitForConnected(3000))
|
||||||
{
|
{
|
||||||
std::cout<<"Can not connect to to Server.\n";
|
std::cout<<"Can not connect to to Server.\n";
|
||||||
QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
|
QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
masterIODevice = microSocket;
|
masterIODevice = microSocket;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QSerialPort* microPort = new QSerialPort;
|
QSerialPort* microPort = new QSerialPort;
|
||||||
if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
|
if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
|
||||||
else microPort->setPortName("ttyUSB0");
|
else microPort->setPortName("ttyUSB0");
|
||||||
|
|
||||||
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
|
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
|
||||||
else microPort->setBaudRate(BAUD);
|
else microPort->setBaudRate(BAUD);
|
||||||
|
|
||||||
if(!microPort->open(QIODevice::ReadWrite))
|
if(!microPort->open(QIODevice::ReadWrite))
|
||||||
{
|
{
|
||||||
QMessageBox::critical(nullptr, "Error", QString("Can not open serial port ")+microPort->portName());
|
QMessageBox::critical(nullptr, "Error", QString("Can not open serial port ")+microPort->portName());
|
||||||
std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
|
std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
masterIODevice = microPort;
|
masterIODevice = microPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
Microcontroller micro(masterIODevice);
|
Microcontroller micro(masterIODevice);
|
||||||
micro.setPower(true);
|
micro.setPower(true);
|
||||||
|
|
||||||
TrainJs::init();
|
TrainJs::init();
|
||||||
|
|
||||||
Train::micro = µ
|
Train::micro = µ
|
||||||
Turnout::micro = µ
|
Turnout::micro = µ
|
||||||
ItemStore items;
|
ItemStore items;
|
||||||
|
|
||||||
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
||||||
QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
|
QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
|
||||||
|
|
||||||
//mainwindow
|
//mainwindow
|
||||||
MainWindow w(µ, &items);
|
MainWindow w(µ, &items);
|
||||||
|
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
int retVal = a.exec();
|
int retVal = a.exec();
|
||||||
micro.setPower(false);
|
micro.setPower(false);
|
||||||
|
|
||||||
if(masterIODevice)
|
if(masterIODevice)
|
||||||
delete masterIODevice;
|
delete masterIODevice;
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include "mainobject.h"
|
#include "mainobject.h"
|
||||||
|
|
||||||
MainObject::MainObject(QIODevice* ioDevice) :
|
MainObject::MainObject(QIODevice* ioDevice) :
|
||||||
masterIODevice(ioDevice),
|
masterIODevice(ioDevice),
|
||||||
micro(masterIODevice)
|
micro(masterIODevice)
|
||||||
{
|
{
|
||||||
//connect item store
|
//connect item store
|
||||||
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainObject::~MainObject()
|
MainObject::~MainObject()
|
||||||
|
@ -26,22 +26,22 @@
|
|||||||
|
|
||||||
class MainObject : public QObject
|
class MainObject : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//io
|
//io
|
||||||
QIODevice * const masterIODevice = nullptr;
|
QIODevice * const masterIODevice = nullptr;
|
||||||
|
|
||||||
Microcontroller micro;
|
Microcontroller micro;
|
||||||
|
|
||||||
const QString settingsPath;
|
const QString settingsPath;
|
||||||
|
|
||||||
//items
|
//items
|
||||||
ItemStore items;
|
ItemStore items;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainObject(QIODevice* ioDevice);
|
explicit MainObject(QIODevice* ioDevice);
|
||||||
~MainObject();
|
~MainObject();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINOBJECT_H
|
#endif // MAINOBJECT_H
|
||||||
|
@ -7,83 +7,83 @@
|
|||||||
|
|
||||||
void Microcontroller::trainSetSpeed(uint8_t id, int8_t speed)
|
void Microcontroller::trainSetSpeed(uint8_t id, int8_t speed)
|
||||||
{
|
{
|
||||||
qDebug()<<__func__;
|
qDebug()<<__func__;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<"train "<<(unsigned)id<<" speed "<<(int)speed<<'\n';
|
ss<<"train "<<(unsigned)id<<" speed "<<(int)speed<<'\n';
|
||||||
write(ss.str().c_str());
|
write(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::trainReverse(uint8_t id)
|
void Microcontroller::trainReverse(uint8_t id)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<"train "<<(unsigned)id<<" reverse\n";
|
ss<<"train "<<(unsigned)id<<" reverse\n";
|
||||||
write(ss.str().c_str());
|
write(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::trainSetFunction(uint8_t id, uint8_t function, bool on)
|
void Microcontroller::trainSetFunction(uint8_t id, uint8_t function, bool on)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<"train "<<(unsigned)id<<" function "<<(unsigned)function<<' '<<(on ? "on" : "off")<<'\n';
|
ss<<"train "<<(unsigned)id<<" function "<<(unsigned)function<<' '<<(on ? "on" : "off")<<'\n';
|
||||||
write(ss.str().c_str());
|
write(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::tunoutSetDirection(uint8_t id, bool direction)
|
void Microcontroller::tunoutSetDirection(uint8_t id, bool direction)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<"turnout "<<(unsigned)id<<" set "<<(!direction ? "left" : "right")<<'\n';
|
ss<<"turnout "<<(unsigned)id<<" set "<<(!direction ? "left" : "right")<<'\n';
|
||||||
write(ss.str().c_str());
|
write(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::setPower(bool on)
|
void Microcontroller::setPower(bool on)
|
||||||
{
|
{
|
||||||
write(on ? "power on\n" : "power off\n");
|
write(on ? "power on\n" : "power off\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::estop()
|
void Microcontroller::estop()
|
||||||
{
|
{
|
||||||
write("stop\n");
|
write("stop\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::write(const QByteArray& buffer)
|
void Microcontroller::write(const QByteArray& buffer)
|
||||||
{
|
{
|
||||||
qDebug()<<buffer;
|
qDebug()<<buffer;
|
||||||
if(_port != nullptr)
|
if(_port != nullptr)
|
||||||
{
|
{
|
||||||
_port->write(buffer);
|
_port->write(buffer);
|
||||||
_port->waitForBytesWritten(1000);
|
_port->waitForBytesWritten(1000);
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::write(char* buffer, const size_t length)
|
void Microcontroller::write(char* buffer, const size_t length)
|
||||||
{
|
{
|
||||||
qDebug()<<buffer;
|
qDebug()<<buffer;
|
||||||
if(_port != nullptr)
|
if(_port != nullptr)
|
||||||
{
|
{
|
||||||
_port->write(buffer, length);
|
_port->write(buffer, length);
|
||||||
//_port->waitForBytesWritten(1000);
|
//_port->waitForBytesWritten(1000);
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Microcontroller::connected()
|
bool Microcontroller::connected()
|
||||||
{
|
{
|
||||||
if(_port != nullptr)
|
if(_port != nullptr)
|
||||||
return _port->isOpen();
|
return _port->isOpen();
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::requestState()
|
void Microcontroller::requestState()
|
||||||
{
|
{
|
||||||
write("train list\n");
|
write("train list\n");
|
||||||
write("turnout list\n");
|
write("turnout list\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//housekeeping
|
//housekeeping
|
||||||
|
|
||||||
Microcontroller::Microcontroller(QIODevice* port)
|
Microcontroller::Microcontroller(QIODevice* port)
|
||||||
{
|
{
|
||||||
setIODevice(port);
|
setIODevice(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
Microcontroller::Microcontroller()
|
Microcontroller::Microcontroller()
|
||||||
@ -96,54 +96,56 @@ Microcontroller::~Microcontroller()
|
|||||||
|
|
||||||
void Microcontroller::setIODevice(QIODevice *port)
|
void Microcontroller::setIODevice(QIODevice *port)
|
||||||
{
|
{
|
||||||
_port = port;
|
_port = port;
|
||||||
QObject::connect(_port, &QIODevice::readyRead, this, &Microcontroller::isReadyRead);
|
QObject::connect(_port, &QIODevice::readyRead, this, &Microcontroller::isReadyRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Item> Microcontroller::processTrainLine(const QString& buffer)
|
std::shared_ptr<Item> Microcontroller::processTrainLine(const QString& buffer)
|
||||||
{
|
{
|
||||||
QStringList bufferList = buffer.split(' ');
|
QStringList bufferList = buffer.split(' ');
|
||||||
if(bufferList.size() >= 14 && buffer.startsWith("TRAIN NUMBER:"))
|
if(bufferList.size() >= 14 && buffer.startsWith("TRAIN NUMBER:"))
|
||||||
{
|
{
|
||||||
return std::shared_ptr<Item>(new Train(bufferList[2].toInt(), bufferList[4].toInt(), bufferList[13].toInt(nullptr, 2), bufferList[9].toInt()));
|
return std::shared_ptr<Item>(new Train(bufferList[2].toInt(), bufferList[4].toInt(), bufferList[13].toInt(nullptr, 2),
|
||||||
}
|
bufferList[9].toInt()));
|
||||||
return nullptr;
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Item> Microcontroller::processTurnoutLine(const QString& buffer)
|
std::shared_ptr<Item> Microcontroller::processTurnoutLine(const QString& buffer)
|
||||||
{
|
{
|
||||||
QStringList bufferList = buffer.split(' ');
|
QStringList bufferList = buffer.split(' ');
|
||||||
if(bufferList.size() >= 11 && buffer.startsWith("TURNOUT NUMBER:"))
|
if(bufferList.size() >= 11 && buffer.startsWith("TURNOUT NUMBER:"))
|
||||||
{
|
{
|
||||||
return std::shared_ptr<Item>(new Turnout(bufferList[2].toInt(), bufferList[4].toInt(), bufferList[6].toInt(), bufferList[11].toInt()));
|
return std::shared_ptr<Item>(new Turnout(bufferList[2].toInt(), bufferList[4].toInt(), bufferList[6].toInt(),
|
||||||
}
|
bufferList[11].toInt()));
|
||||||
return nullptr;
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::processList(const QString& buffer)
|
void Microcontroller::processList(const QString& buffer)
|
||||||
{
|
{
|
||||||
QStringList bufferList = buffer.split(' ');
|
QStringList bufferList = buffer.split(' ');
|
||||||
qDebug()<<__func__<<" :"<<buffer<<" list mode: "<<listMode;
|
qDebug()<<__func__<<" :"<<buffer<<" list mode: "<<listMode;
|
||||||
if(bufferList.size() >= 10 && buffer.contains("NUMBER:"))
|
if(bufferList.size() >= 10 && buffer.contains("NUMBER:"))
|
||||||
{
|
{
|
||||||
std::shared_ptr<Item> item;
|
std::shared_ptr<Item> item;
|
||||||
if(listMode == TRAIN_LIST)
|
if(listMode == TRAIN_LIST)
|
||||||
item = processTrainLine(buffer);
|
item = processTrainLine(buffer);
|
||||||
else if(listMode == TURNOUT_LIST)
|
else if(listMode == TURNOUT_LIST)
|
||||||
item = processTurnoutLine(buffer);
|
item = processTurnoutLine(buffer);
|
||||||
if(item)
|
if(item)
|
||||||
itemList.push_back(item);
|
itemList.push_back(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
listMode = false;
|
listMode = false;
|
||||||
if(!itemList.empty())
|
if(!itemList.empty())
|
||||||
{
|
{
|
||||||
qDebug()<<"got item list " << itemList.size();
|
qDebug()<<"got item list " << itemList.size();
|
||||||
gotItemList(itemList);
|
gotItemList(itemList);
|
||||||
itemList.clear();
|
itemList.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::processItemState(const QString& buffer)
|
void Microcontroller::processItemState(const QString& buffer)
|
||||||
@ -157,43 +159,43 @@ void Microcontroller::processItemState(const QString& buffer)
|
|||||||
|
|
||||||
void Microcontroller::processMicroReturn()
|
void Microcontroller::processMicroReturn()
|
||||||
{
|
{
|
||||||
if(listMode)
|
if(listMode)
|
||||||
processList(_buffer);
|
processList(_buffer);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(_buffer.startsWith("Trains:"))
|
if(_buffer.startsWith("Trains:"))
|
||||||
{
|
{
|
||||||
listMode = TRAIN_LIST;
|
listMode = TRAIN_LIST;
|
||||||
itemList.clear();
|
itemList.clear();
|
||||||
}
|
|
||||||
else if(_buffer.startsWith("Turnouts:"))
|
|
||||||
{
|
|
||||||
listMode = TURNOUT_LIST;
|
|
||||||
}
|
|
||||||
else if(_buffer.startsWith("TRAIN NUMBER:") || _buffer.startsWith("TURNOUT NUMBER:"))
|
|
||||||
{
|
|
||||||
processItemState(_buffer);
|
|
||||||
}
|
}
|
||||||
else if(_buffer.startsWith("TrainController"))
|
else if(_buffer.startsWith("Turnouts:"))
|
||||||
{
|
{
|
||||||
requestState();
|
listMode = TURNOUT_LIST;
|
||||||
}
|
}
|
||||||
}
|
else if(_buffer.startsWith("TRAIN NUMBER:") || _buffer.startsWith("TURNOUT NUMBER:"))
|
||||||
|
{
|
||||||
|
processItemState(_buffer);
|
||||||
|
}
|
||||||
|
else if(_buffer.startsWith("TrainController"))
|
||||||
|
{
|
||||||
|
requestState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::isReadyRead()
|
void Microcontroller::isReadyRead()
|
||||||
{
|
{
|
||||||
char charBuf;
|
char charBuf;
|
||||||
while(_port->getChar(&charBuf))
|
while(_port->getChar(&charBuf))
|
||||||
{
|
{
|
||||||
_buffer.push_back(charBuf);
|
_buffer.push_back(charBuf);
|
||||||
if( _buffer.endsWith('\n') )
|
if( _buffer.endsWith('\n') )
|
||||||
{
|
{
|
||||||
_buffer.remove('\n');
|
_buffer.remove('\n');
|
||||||
processMicroReturn();
|
processMicroReturn();
|
||||||
textRecived(_buffer);
|
textRecived(_buffer);
|
||||||
_buffer.clear();
|
_buffer.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,64 +20,64 @@
|
|||||||
class Microcontroller : public QObject
|
class Microcontroller : public QObject
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static constexpr char AMP_RELAY = 0;
|
static constexpr char AMP_RELAY = 0;
|
||||||
static constexpr char SENSOR_TEMPERATURE = 1;
|
static constexpr char SENSOR_TEMPERATURE = 1;
|
||||||
static constexpr char SENSOR_DOOR = 0 ;
|
static constexpr char SENSOR_DOOR = 0 ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static constexpr int TRAIN_LIST = 1;
|
static constexpr int TRAIN_LIST = 1;
|
||||||
static constexpr int TURNOUT_LIST = 2;
|
static constexpr int TURNOUT_LIST = 2;
|
||||||
|
|
||||||
int listMode = 0;
|
int listMode = 0;
|
||||||
|
|
||||||
//uint8_t _auxState = 0;
|
//uint8_t _auxState = 0;
|
||||||
|
|
||||||
QIODevice* _port = nullptr;
|
QIODevice* _port = nullptr;
|
||||||
|
|
||||||
std::vector< std::shared_ptr<Item> > itemList;
|
std::vector< std::shared_ptr<Item> > itemList;
|
||||||
|
|
||||||
QScopedPointer<QEventLoop> loop;
|
QScopedPointer<QEventLoop> loop;
|
||||||
QString _buffer;
|
QString _buffer;
|
||||||
|
|
||||||
void processMicroReturn();
|
void processMicroReturn();
|
||||||
void processList(const QString& buffer);
|
void processList(const QString& buffer);
|
||||||
void processItemState(const QString& buffer);
|
void processItemState(const QString& buffer);
|
||||||
std::shared_ptr<Item> processTrainLine(const QString& buffer);
|
std::shared_ptr<Item> processTrainLine(const QString& buffer);
|
||||||
std::shared_ptr<Item> processTurnoutLine(const QString& buffer);
|
std::shared_ptr<Item> processTurnoutLine(const QString& buffer);
|
||||||
|
|
||||||
void write(char *buffer, const size_t length);
|
void write(char *buffer, const size_t length);
|
||||||
void write(const QByteArray& buffer);
|
void write(const QByteArray& buffer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Microcontroller(QIODevice* port);
|
Microcontroller(QIODevice* port);
|
||||||
Microcontroller();
|
Microcontroller();
|
||||||
~Microcontroller();
|
~Microcontroller();
|
||||||
bool connected();
|
bool connected();
|
||||||
void setIODevice(QIODevice* port);
|
void setIODevice(QIODevice* port);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void requestState();
|
void requestState();
|
||||||
|
|
||||||
void trainSetSpeed(uint8_t id, int8_t speed);
|
void trainSetSpeed(uint8_t id, int8_t speed);
|
||||||
void trainReverse(uint8_t id);
|
void trainReverse(uint8_t id);
|
||||||
void trainSetFunction(uint8_t id, uint8_t function, bool on);
|
void trainSetFunction(uint8_t id, uint8_t function, bool on);
|
||||||
void tunoutSetDirection(uint8_t id, bool direction);
|
void tunoutSetDirection(uint8_t id, bool direction);
|
||||||
void estop();
|
void estop();
|
||||||
void setPower(bool on);
|
void setPower(bool on);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void isReadyRead();
|
void isReadyRead();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void textRecived(const QString string);
|
void textRecived(const QString string);
|
||||||
void itemChanged(ItemData relay);
|
void itemChanged(ItemData relay);
|
||||||
void auxStateChanged(int value);
|
void auxStateChanged(int value);
|
||||||
void gotItemList(std::vector< std::shared_ptr<Item> >&);
|
void gotItemList(std::vector< std::shared_ptr<Item> >&);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROCONTROLLER_H
|
#endif // MICROCONTROLLER_H
|
||||||
|
@ -41,7 +41,10 @@ public:
|
|||||||
std::weak_ptr<Item> getItem();
|
std::weak_ptr<Item> getItem();
|
||||||
void setItem(std::weak_ptr<Item>);
|
void setItem(std::weak_ptr<Item>);
|
||||||
bool itemIsSet();
|
bool itemIsSet();
|
||||||
bool getWantsNewItem() {return wantsNewItem;}
|
bool getWantsNewItem()
|
||||||
|
{
|
||||||
|
return wantsNewItem;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRAINJS_H
|
#endif // TRAINJS_H
|
||||||
|
@ -2,29 +2,29 @@
|
|||||||
#include "ui_itemcreationdialog.h"
|
#include "ui_itemcreationdialog.h"
|
||||||
|
|
||||||
ItemCreationDialog::ItemCreationDialog(QWidget *parent) :
|
ItemCreationDialog::ItemCreationDialog(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ItemCreationDialog)
|
ui(new Ui::ItemCreationDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ItemCreationDialog::itemTypeChanged);
|
connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ItemCreationDialog::itemTypeChanged);
|
||||||
connect(ui->lineEdit, &QLineEdit::textChanged, this, &ItemCreationDialog::itemNameChanged);
|
connect(ui->lineEdit, &QLineEdit::textChanged, this, &ItemCreationDialog::itemNameChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemCreationDialog::~ItemCreationDialog()
|
ItemCreationDialog::~ItemCreationDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemCreationDialog::itemTypeChanged(const QString& type)
|
void ItemCreationDialog::itemTypeChanged(const QString& type)
|
||||||
{
|
{
|
||||||
ui->verticalLayout->removeWidget(widget);
|
ui->verticalLayout->removeWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemCreationDialog::itemNameChanged(const QString& name)
|
void ItemCreationDialog::itemNameChanged(const QString& name)
|
||||||
{
|
{
|
||||||
if(item)
|
if(item)
|
||||||
{
|
{
|
||||||
item->setName(name);
|
item->setName(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,29 +5,30 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "../items/item.h"
|
#include "../items/item.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class ItemCreationDialog;
|
class ItemCreationDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemCreationDialog : public QDialog
|
class ItemCreationDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
QWidget* widget;
|
QWidget* widget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ItemCreationDialog(QWidget *parent = nullptr);
|
explicit ItemCreationDialog(QWidget *parent = nullptr);
|
||||||
~ItemCreationDialog();
|
~ItemCreationDialog();
|
||||||
|
|
||||||
std::shared_ptr<Item> item;
|
std::shared_ptr<Item> item;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void itemTypeChanged(const QString& type);
|
void itemTypeChanged(const QString& type);
|
||||||
void itemNameChanged(const QString& name);
|
void itemNameChanged(const QString& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ItemCreationDialog *ui;
|
Ui::ItemCreationDialog *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ITEMCREATIONDIALOG_H
|
#endif // ITEMCREATIONDIALOG_H
|
||||||
|
@ -6,79 +6,79 @@
|
|||||||
#include "../trainjs.h"
|
#include "../trainjs.h"
|
||||||
|
|
||||||
ItemScrollBox::ItemScrollBox(QWidget *parent) :
|
ItemScrollBox::ItemScrollBox(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::RelayScrollBox)
|
ui(new Ui::RelayScrollBox)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture);
|
QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture);
|
||||||
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
|
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemScrollBox::~ItemScrollBox()
|
ItemScrollBox::~ItemScrollBox()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
||||||
{
|
{
|
||||||
if(auto workItem = item.lock())
|
if(auto workItem = item.lock())
|
||||||
{
|
{
|
||||||
widgets_.push_back(new ItemWidget(item, this));
|
widgets_.push_back(new ItemWidget(item, this));
|
||||||
Train* train = dynamic_cast<Train*>(workItem.get());
|
Train* train = dynamic_cast<Train*>(workItem.get());
|
||||||
Turnout* turnout = dynamic_cast<Turnout*>(workItem.get());
|
Turnout* turnout = dynamic_cast<Turnout*>(workItem.get());
|
||||||
if(train)
|
if(train)
|
||||||
{
|
{
|
||||||
if(train->getTrainId() == 0)
|
if(train->getTrainId() == 0)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_Q), QKeySequence(Qt::Key_A), QKeySequence(Qt::Key_Z));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_Q), QKeySequence(Qt::Key_A), QKeySequence(Qt::Key_Z));
|
||||||
else if(train->getTrainId() == 1)
|
else if(train->getTrainId() == 1)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_W), QKeySequence(Qt::Key_S), QKeySequence(Qt::Key_X));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_W), QKeySequence(Qt::Key_S), QKeySequence(Qt::Key_X));
|
||||||
else if(train->getTrainId() == 2)
|
else if(train->getTrainId() == 2)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_E), QKeySequence(Qt::Key_D), QKeySequence(Qt::Key_C));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_E), QKeySequence(Qt::Key_D), QKeySequence(Qt::Key_C));
|
||||||
else if(train->getTrainId() == 3)
|
else if(train->getTrainId() == 3)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_R), QKeySequence(Qt::Key_F), QKeySequence(Qt::Key_V));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_R), QKeySequence(Qt::Key_F), QKeySequence(Qt::Key_V));
|
||||||
else if(train->getTrainId() == 4)
|
else if(train->getTrainId() == 4)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_T), QKeySequence(Qt::Key_G), QKeySequence(Qt::Key_B));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_T), QKeySequence(Qt::Key_G), QKeySequence(Qt::Key_B));
|
||||||
}
|
}
|
||||||
else if(turnout)
|
else if(turnout)
|
||||||
{
|
{
|
||||||
if(turnout->getTurnoutId() == 0)
|
if(turnout->getTurnoutId() == 0)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_1));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_1));
|
||||||
else if(turnout->getTurnoutId() == 1)
|
else if(turnout->getTurnoutId() == 1)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_2));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_2));
|
||||||
else if(turnout->getTurnoutId() == 2)
|
else if(turnout->getTurnoutId() == 2)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_3));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_3));
|
||||||
else if(turnout->getTurnoutId() == 3)
|
else if(turnout->getTurnoutId() == 3)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_4));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_4));
|
||||||
else if(turnout->getTurnoutId() == 4)
|
else if(turnout->getTurnoutId() == 4)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_5));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_5));
|
||||||
else if(turnout->getTurnoutId() == 5)
|
else if(turnout->getTurnoutId() == 5)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_6));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_6));
|
||||||
else if(turnout->getTurnoutId() == 6)
|
else if(turnout->getTurnoutId() == 6)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_7));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_7));
|
||||||
else if(turnout->getTurnoutId() == 7)
|
else if(turnout->getTurnoutId() == 7)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_8));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_8));
|
||||||
else if(turnout->getTurnoutId() == 8)
|
else if(turnout->getTurnoutId() == 8)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_9));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_9));
|
||||||
else if(turnout->getTurnoutId() == 9)
|
else if(turnout->getTurnoutId() == 9)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_0));
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_0));
|
||||||
}
|
}
|
||||||
ui->relayWidgetVbox->addWidget(widgets_.back());
|
ui->relayWidgetVbox->addWidget(widgets_.back());
|
||||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
||||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemScrollBox::removeItem(const ItemData& item)
|
void ItemScrollBox::removeItem(const ItemData& item)
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < widgets_.size(); i++)
|
for(unsigned i = 0; i < widgets_.size(); i++)
|
||||||
{
|
{
|
||||||
if(widgets_[i]->controles(item))
|
if(widgets_[i]->controles(item))
|
||||||
{
|
{
|
||||||
ui->relayWidgetVbox->removeWidget(widgets_[i]);
|
ui->relayWidgetVbox->removeWidget(widgets_[i]);
|
||||||
delete widgets_[i];
|
delete widgets_[i];
|
||||||
widgets_.erase(widgets_.begin()+i);
|
widgets_.erase(widgets_.begin()+i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,32 +10,33 @@
|
|||||||
#include "../items/itemstore.h"
|
#include "../items/itemstore.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class RelayScrollBox;
|
class RelayScrollBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemScrollBox : public QWidget
|
class ItemScrollBox : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
std::vector< ItemWidget* > widgets_;
|
std::vector< ItemWidget* > widgets_;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deleteRequest(const ItemData& item);
|
void deleteRequest(const ItemData& item);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ItemScrollBox(QWidget *parent = nullptr);
|
explicit ItemScrollBox(QWidget *parent = nullptr);
|
||||||
~ItemScrollBox();
|
~ItemScrollBox();
|
||||||
|
|
||||||
void setItemStore(ItemStore* itemStore);
|
void setItemStore(ItemStore* itemStore);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void addItem(std::weak_ptr<Item> item);
|
void addItem(std::weak_ptr<Item> item);
|
||||||
void removeItem(const ItemData& item);
|
void removeItem(const ItemData& item);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::RelayScrollBox *ui;
|
Ui::RelayScrollBox *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RELAYSCROLLBOX_H
|
#endif // RELAYSCROLLBOX_H
|
||||||
|
@ -1,176 +1,176 @@
|
|||||||
#include "itemsettingsdialog.h"
|
#include "itemsettingsdialog.h"
|
||||||
#include "ui_itemsettingsdialog.h"
|
#include "ui_itemsettingsdialog.h"
|
||||||
#include<memory>
|
#include<memory>
|
||||||
|
|
||||||
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
|
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
item_(item),
|
item_(item),
|
||||||
ui(new Ui::ItemSettingsDialog)
|
ui(new Ui::ItemSettingsDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setModal(false);
|
setModal(false);
|
||||||
|
|
||||||
ui->label_name->setText(item_->getName());
|
ui->label_name->setText(item_->getName());
|
||||||
ui->checkBox_Override->setChecked(item_->getOverride());
|
ui->checkBox_Override->setChecked(item_->getOverride());
|
||||||
|
|
||||||
|
|
||||||
if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
|
if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
|
||||||
{
|
{
|
||||||
itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
|
itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
|
||||||
}
|
}
|
||||||
else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
|
else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
|
||||||
{
|
{
|
||||||
itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem);
|
itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem);
|
||||||
}
|
}
|
||||||
else if(std::shared_ptr<SystemItem> sysItem = std::dynamic_pointer_cast<SystemItem>(item_))
|
else if(std::shared_ptr<SystemItem> sysItem = std::dynamic_pointer_cast<SystemItem>(item_))
|
||||||
{
|
{
|
||||||
itemSpecificWidget_ = new SystemItemSettingsWidget(sysItem);
|
itemSpecificWidget_ = new SystemItemSettingsWidget(sysItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(itemSpecificWidget_)
|
if(itemSpecificWidget_)
|
||||||
{
|
{
|
||||||
ui->verticalLayout_2->addWidget(itemSpecificWidget_);
|
ui->verticalLayout_2->addWidget(itemSpecificWidget_);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui->pushButton_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor);
|
connect(ui->pushButton_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor);
|
||||||
connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
|
connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
|
||||||
connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
|
connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
|
||||||
connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride);
|
connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride);
|
||||||
|
|
||||||
|
|
||||||
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
|
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
|
||||||
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
|
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
|
||||||
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
|
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
|
||||||
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||||
ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
|
ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
|
||||||
ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
|
ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
|
||||||
loadActorList();
|
loadActorList();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemSettingsDialog::~ItemSettingsDialog()
|
ItemSettingsDialog::~ItemSettingsDialog()
|
||||||
{
|
{
|
||||||
if(itemSpecificWidget_) delete itemSpecificWidget_;
|
if(itemSpecificWidget_) delete itemSpecificWidget_;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemSettingsDialog::changeOverride()
|
void ItemSettingsDialog::changeOverride()
|
||||||
{
|
{
|
||||||
item_->setOverride(ui->checkBox_Override->isChecked());
|
item_->setOverride(ui->checkBox_Override->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemSettingsDialog::loadActorList()
|
void ItemSettingsDialog::loadActorList()
|
||||||
{
|
{
|
||||||
//ui->listWidget->clear();
|
//ui->listWidget->clear();
|
||||||
ui->tableWidget->setRowCount(item_->getActors().size());
|
ui->tableWidget->setRowCount(item_->getActors().size());
|
||||||
|
|
||||||
for(unsigned i = 0; i < item_->getActors().size(); i++)
|
for(unsigned i = 0; i < item_->getActors().size(); i++)
|
||||||
{
|
{
|
||||||
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName()));
|
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName()));
|
||||||
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(item_->getActors()[i]->actionName()));
|
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(item_->getActors()[i]->actionName()));
|
||||||
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
|
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemSettingsDialog::addActor()
|
void ItemSettingsDialog::addActor()
|
||||||
{
|
{
|
||||||
ActorSettingsDialog* dialog = nullptr;
|
ActorSettingsDialog* dialog = nullptr;
|
||||||
std::shared_ptr<Actor> actor = nullptr;
|
std::shared_ptr<Actor> actor = nullptr;
|
||||||
|
|
||||||
if(ui->comboBox->currentText() == "Alarm")
|
if(ui->comboBox->currentText() == "Alarm")
|
||||||
{
|
{
|
||||||
std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
|
std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
|
||||||
actor = alarm;
|
actor = alarm;
|
||||||
dialog = new ActorSettingsDialog(alarm, this);
|
dialog = new ActorSettingsDialog(alarm, this);
|
||||||
}
|
}
|
||||||
else if(ui->comboBox->currentText() == "Sensor")
|
else if(ui->comboBox->currentText() == "Sensor")
|
||||||
{
|
{
|
||||||
std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
|
std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
|
||||||
actor = sensorActor;
|
actor = sensorActor;
|
||||||
dialog = new ActorSettingsDialog(sensorActor, this);
|
dialog = new ActorSettingsDialog(sensorActor, this);
|
||||||
}
|
}
|
||||||
else if(ui->comboBox->currentText() == "Timer" )
|
else if(ui->comboBox->currentText() == "Timer" )
|
||||||
{
|
{
|
||||||
std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
|
std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
|
||||||
actor = timerActor;
|
actor = timerActor;
|
||||||
dialog = new ActorSettingsDialog(timerActor, this);
|
dialog = new ActorSettingsDialog(timerActor, this);
|
||||||
}
|
}
|
||||||
else if(ui->comboBox->currentText() == "Regulator")
|
else if(ui->comboBox->currentText() == "Regulator")
|
||||||
{
|
{
|
||||||
std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator);
|
std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator);
|
||||||
actor = regulator;
|
actor = regulator;
|
||||||
dialog = new ActorSettingsDialog(regulator, this);
|
dialog = new ActorSettingsDialog(regulator, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(ui->comboBox->currentText() == "Polynomal")
|
else if(ui->comboBox->currentText() == "Polynomal")
|
||||||
{
|
{
|
||||||
std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor);
|
std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor);
|
||||||
actor = polynomalActor;
|
actor = polynomalActor;
|
||||||
dialog = new ActorSettingsDialog(polynomalActor, this);
|
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(ui->comboBox->currentText() == "Multi Factor")
|
else if(ui->comboBox->currentText() == "Multi Factor")
|
||||||
{
|
{
|
||||||
std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(new MultiFactorActor);
|
std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(new MultiFactorActor);
|
||||||
actor = polynomalActor;
|
actor = polynomalActor;
|
||||||
dialog = new ActorSettingsDialog(polynomalActor, this);
|
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(dialog != nullptr)
|
if(dialog != nullptr)
|
||||||
{
|
{
|
||||||
dialog->setParent(this);
|
dialog->setParent(this);
|
||||||
dialog->show();
|
dialog->show();
|
||||||
if(dialog->exec() == QDialog::Accepted)
|
if(dialog->exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
item_->addActor(actor);
|
item_->addActor(actor);
|
||||||
loadActorList();
|
loadActorList();
|
||||||
}
|
}
|
||||||
delete dialog;
|
delete dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemSettingsDialog::removeActor()
|
void ItemSettingsDialog::removeActor()
|
||||||
{
|
{
|
||||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||||
{
|
{
|
||||||
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
||||||
loadActorList();
|
loadActorList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemSettingsDialog::editActor()
|
void ItemSettingsDialog::editActor()
|
||||||
{
|
{
|
||||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||||
{
|
{
|
||||||
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
||||||
|
|
||||||
std::shared_ptr<AlarmTime> alarmTime = std::dynamic_pointer_cast<AlarmTime>(actor);
|
std::shared_ptr<AlarmTime> alarmTime = std::dynamic_pointer_cast<AlarmTime>(actor);
|
||||||
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
|
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
|
||||||
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
||||||
std::shared_ptr<TimerActor> timerActor = std::dynamic_pointer_cast<TimerActor>(actor);
|
std::shared_ptr<TimerActor> timerActor = std::dynamic_pointer_cast<TimerActor>(actor);
|
||||||
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
||||||
std::shared_ptr<MultiFactorActor> factorActor = std::dynamic_pointer_cast<MultiFactorActor>(actor);
|
std::shared_ptr<MultiFactorActor> factorActor = std::dynamic_pointer_cast<MultiFactorActor>(actor);
|
||||||
|
|
||||||
ActorSettingsDialog* dialog;
|
ActorSettingsDialog* dialog;
|
||||||
|
|
||||||
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
|
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
|
||||||
else if(regulator) dialog = new ActorSettingsDialog(regulator, this);
|
else if(regulator) dialog = new ActorSettingsDialog(regulator, this);
|
||||||
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this);
|
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this);
|
||||||
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
|
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
|
||||||
else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this);
|
else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||||
else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this);
|
else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this);
|
||||||
else dialog = new ActorSettingsDialog(actor, this);
|
else dialog = new ActorSettingsDialog(actor, this);
|
||||||
dialog->setParent(this);
|
dialog->setParent(this);
|
||||||
dialog->show();
|
dialog->show();
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
|
||||||
for(int i = 0; i < ui->tableWidget->rowCount() && i < item_->getActors().size(); ++i)
|
for(int i = 0; i < ui->tableWidget->rowCount() && i < item_->getActors().size(); ++i)
|
||||||
{
|
{
|
||||||
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
||||||
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
||||||
ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
|
ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,32 +6,33 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "../items/item.h"
|
#include "../items/item.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class ItemSettingsDialog;
|
class ItemSettingsDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemSettingsDialog : public QDialog
|
class ItemSettingsDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
std::shared_ptr<Item> item_;
|
std::shared_ptr<Item> item_;
|
||||||
QWidget* itemSpecificWidget_ = nullptr;
|
QWidget* itemSpecificWidget_ = nullptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadActorList();
|
void loadActorList();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr);
|
explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr);
|
||||||
~ItemSettingsDialog();
|
~ItemSettingsDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void removeActor();
|
void removeActor();
|
||||||
void addActor();
|
void addActor();
|
||||||
void editActor();
|
void editActor();
|
||||||
void changeOverride();
|
void changeOverride();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ItemSettingsDialog *ui;
|
Ui::ItemSettingsDialog *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RELAYSETTINGSDIALOG_H
|
#endif // RELAYSETTINGSDIALOG_H
|
||||||
|
@ -8,68 +8,74 @@
|
|||||||
#include "../items/turnout.h"
|
#include "../items/turnout.h"
|
||||||
|
|
||||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
item_(item),
|
item_(item),
|
||||||
ui(new Ui::ItemWidget)
|
ui(new Ui::ItemWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
{
|
{
|
||||||
ui->label->setText(workingItem->getName());
|
ui->label->setText(workingItem->getName());
|
||||||
|
|
||||||
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::setValue);
|
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::setValue);
|
||||||
connect(ui->checkBox_f1, &QCheckBox::stateChanged, this, &ItemWidget::f1);
|
connect(ui->checkBox_f1, &QCheckBox::stateChanged, this, &ItemWidget::f1);
|
||||||
connect(ui->checkBox_f2, &QCheckBox::stateChanged, this, &ItemWidget::f2);
|
connect(ui->checkBox_f2, &QCheckBox::stateChanged, this, &ItemWidget::f2);
|
||||||
connect(ui->checkBox_f3, &QCheckBox::stateChanged, this, &ItemWidget::f3);
|
connect(ui->checkBox_f3, &QCheckBox::stateChanged, this, &ItemWidget::f3);
|
||||||
connect(ui->checkBox_f4, &QCheckBox::stateChanged, this, &ItemWidget::f4);
|
connect(ui->checkBox_f4, &QCheckBox::stateChanged, this, &ItemWidget::f4);
|
||||||
connect(ui->pushButton_reverse, &QPushButton::clicked, this, &ItemWidget::reverse);
|
connect(ui->pushButton_reverse, &QPushButton::clicked, this, &ItemWidget::reverse);
|
||||||
connect(ui->radioButton_left, &QRadioButton::clicked, this, [this](){setValue(0);});
|
connect(ui->radioButton_left, &QRadioButton::clicked, this, [this]()
|
||||||
connect(ui->radioButton_right, &QRadioButton::clicked, this, [this](){setValue(1);});
|
{
|
||||||
|
setValue(0);
|
||||||
|
});
|
||||||
|
connect(ui->radioButton_right, &QRadioButton::clicked, this, [this]()
|
||||||
|
{
|
||||||
|
setValue(1);
|
||||||
|
});
|
||||||
|
|
||||||
connect(workingItem.get(), &Item::valueChanged, this, &ItemWidget::moveToValue);
|
connect(workingItem.get(), &Item::valueChanged, this, &ItemWidget::moveToValue);
|
||||||
|
|
||||||
Train* train = dynamic_cast<Train*>(workingItem.get());
|
Train* train = dynamic_cast<Train*>(workingItem.get());
|
||||||
Turnout* turnout = dynamic_cast<Turnout*>(workingItem.get());
|
Turnout* turnout = dynamic_cast<Turnout*>(workingItem.get());
|
||||||
|
|
||||||
if(turnout)
|
if(turnout)
|
||||||
{
|
{
|
||||||
ui->checkBox_f1->hide();
|
ui->checkBox_f1->hide();
|
||||||
ui->checkBox_f2->hide();
|
ui->checkBox_f2->hide();
|
||||||
ui->checkBox_f3->hide();
|
ui->checkBox_f3->hide();
|
||||||
ui->checkBox_f4->hide();
|
ui->checkBox_f4->hide();
|
||||||
ui->slider->hide();
|
ui->slider->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!train)
|
if(!train)
|
||||||
{
|
{
|
||||||
ui->pushButton_reverse->hide();
|
ui->pushButton_reverse->hide();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->radioButton_left->hide();
|
ui->radioButton_left->hide();
|
||||||
ui->radioButton_right->hide();
|
ui->radioButton_right->hide();
|
||||||
uint8_t functionMask = train->getFunctionMask();
|
uint8_t functionMask = train->getFunctionMask();
|
||||||
qDebug()<<"functionMask: "<<(int)functionMask;
|
qDebug()<<"functionMask: "<<(int)functionMask;
|
||||||
if(!(functionMask & (1 << 0)))
|
if(!(functionMask & (1 << 0)))
|
||||||
ui->checkBox_f1->hide();
|
ui->checkBox_f1->hide();
|
||||||
if(!(functionMask & (1 << 1)))
|
if(!(functionMask & (1 << 1)))
|
||||||
ui->checkBox_f2->hide();
|
ui->checkBox_f2->hide();
|
||||||
if(!(functionMask & (1 << 2)))
|
if(!(functionMask & (1 << 2)))
|
||||||
ui->checkBox_f3->hide();
|
ui->checkBox_f3->hide();
|
||||||
if(!(functionMask & (1 << 3)))
|
if(!(functionMask & (1 << 3)))
|
||||||
ui->checkBox_f4->hide();
|
ui->checkBox_f4->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::deleteItem()
|
void ItemWidget::deleteItem()
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
{
|
{
|
||||||
deleteRequest(*workingItem);
|
deleteRequest(*workingItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::setValue(int8_t value)
|
void ItemWidget::setValue(int8_t value)
|
||||||
@ -82,85 +88,85 @@ void ItemWidget::setValue(int8_t value)
|
|||||||
|
|
||||||
void ItemWidget::moveToValue(int8_t value)
|
void ItemWidget::moveToValue(int8_t value)
|
||||||
{
|
{
|
||||||
ui->slider->blockSignals(true);
|
ui->slider->blockSignals(true);
|
||||||
ui->radioButton_left->blockSignals(true);
|
ui->radioButton_left->blockSignals(true);
|
||||||
ui->radioButton_right->blockSignals(true);
|
ui->radioButton_right->blockSignals(true);
|
||||||
|
|
||||||
ui->pushButton_reverse->setText(value == 0 ? "Reverse" : "Stop");
|
ui->pushButton_reverse->setText(value == 0 ? "Reverse" : "Stop");
|
||||||
ui->slider->setValue(value);
|
ui->slider->setValue(value);
|
||||||
ui->radioButton_left->setChecked(!value);
|
ui->radioButton_left->setChecked(!value);
|
||||||
ui->radioButton_right->setChecked(value);
|
ui->radioButton_right->setChecked(value);
|
||||||
|
|
||||||
ui->slider->blockSignals(false);
|
ui->slider->blockSignals(false);
|
||||||
ui->radioButton_left->blockSignals(false);
|
ui->radioButton_left->blockSignals(false);
|
||||||
ui->radioButton_right->blockSignals(false);
|
ui->radioButton_right->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::f1(int value)
|
void ItemWidget::f1(int value)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
workingItem->setFunction(0, value == Qt::Checked);
|
workingItem->setFunction(0, value == Qt::Checked);
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::f2(int value)
|
void ItemWidget::f2(int value)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
workingItem->setFunction(1, value == Qt::Checked);
|
workingItem->setFunction(1, value == Qt::Checked);
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ItemWidget::f3(int value)
|
void ItemWidget::f3(int value)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
workingItem->setFunction(2, value == Qt::Checked);
|
workingItem->setFunction(2, value == Qt::Checked);
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::f4(int value)
|
void ItemWidget::f4(int value)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
workingItem->setFunction(3, value == Qt::Checked);
|
workingItem->setFunction(3, value == Qt::Checked);
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::reverse()
|
void ItemWidget::reverse()
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
{
|
{
|
||||||
Train* train = dynamic_cast<Train*>(workingItem.get());
|
Train* train = dynamic_cast<Train*>(workingItem.get());
|
||||||
if(train && workingItem->getValue() == 0)
|
if(train && workingItem->getValue() == 0)
|
||||||
train->reverse();
|
train->reverse();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setValue(!((bool)workingItem->getValue()));
|
setValue(!((bool)workingItem->getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::disable()
|
void ItemWidget::disable()
|
||||||
{
|
{
|
||||||
ui->checkBox_f1->setEnabled(false);
|
ui->checkBox_f1->setEnabled(false);
|
||||||
ui->checkBox_f2->setEnabled(false);
|
ui->checkBox_f2->setEnabled(false);
|
||||||
ui->checkBox_f3->setEnabled(false);
|
ui->checkBox_f3->setEnabled(false);
|
||||||
ui->checkBox_f4->setEnabled(false);
|
ui->checkBox_f4->setEnabled(false);
|
||||||
ui->label->setEnabled(false);
|
ui->label->setEnabled(false);
|
||||||
ui->slider->setEnabled(false);
|
ui->slider->setEnabled(false);
|
||||||
ui->pushButton_reverse->setEnabled(false);
|
ui->pushButton_reverse->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemWidget::controles(const ItemData& relay)
|
bool ItemWidget::controles(const ItemData& relay)
|
||||||
{
|
{
|
||||||
if(auto workingRelay = item_.lock())
|
if(auto workingRelay = item_.lock())
|
||||||
{
|
{
|
||||||
if(relay == *workingRelay)
|
if(relay == *workingRelay)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::stepUp()
|
void ItemWidget::stepUp()
|
||||||
@ -175,29 +181,29 @@ void ItemWidget::stepDown()
|
|||||||
|
|
||||||
void ItemWidget::setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev)
|
void ItemWidget::setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev)
|
||||||
{
|
{
|
||||||
shortcuts_.clear();
|
shortcuts_.clear();
|
||||||
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(up, this)));
|
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(up, this)));
|
||||||
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepUp);
|
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepUp);
|
||||||
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(down, this)));
|
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(down, this)));
|
||||||
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepDown);
|
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepDown);
|
||||||
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(rev, this)));
|
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(rev, this)));
|
||||||
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::reverse);
|
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::reverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<Item> ItemWidget::getItem()
|
std::weak_ptr<Item> ItemWidget::getItem()
|
||||||
{
|
{
|
||||||
return item_;
|
return item_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::stateChanged(int state)
|
void ItemWidget::stateChanged(int state)
|
||||||
{
|
{
|
||||||
qDebug()<<"widget got state "<<state;
|
qDebug()<<"widget got state "<<state;
|
||||||
ui->slider->blockSignals(true);
|
ui->slider->blockSignals(true);
|
||||||
ui->slider->setValue(state);
|
ui->slider->setValue(state);
|
||||||
ui->slider->blockSignals(false);
|
ui->slider->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemWidget::~ItemWidget()
|
ItemWidget::~ItemWidget()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
@ -7,51 +7,52 @@
|
|||||||
#include "itemsettingsdialog.h"
|
#include "itemsettingsdialog.h"
|
||||||
#include "../items/item.h"
|
#include "../items/item.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class ItemWidget;
|
class ItemWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemWidget : public QWidget
|
class ItemWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
std::weak_ptr<Item> item_;
|
std::weak_ptr<Item> item_;
|
||||||
|
|
||||||
std::vector< std::unique_ptr<QShortcut> > shortcuts_;
|
std::vector< std::unique_ptr<QShortcut> > shortcuts_;
|
||||||
|
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void deleteRequest(const ItemData& item);
|
void deleteRequest(const ItemData& item);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void setValue(int8_t value);
|
void setValue(int8_t value);
|
||||||
void moveToValue(int8_t value);
|
void moveToValue(int8_t value);
|
||||||
void deleteItem();
|
void deleteItem();
|
||||||
|
|
||||||
void stepUp();
|
void stepUp();
|
||||||
void stepDown();
|
void stepDown();
|
||||||
|
|
||||||
void f1(int state);
|
void f1(int state);
|
||||||
void f2(int state);
|
void f2(int state);
|
||||||
void f3(int state);
|
void f3(int state);
|
||||||
void f4(int state);
|
void f4(int state);
|
||||||
void reverse();
|
void reverse();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ItemWidget(std::weak_ptr<Item> item, QWidget *parent);
|
explicit ItemWidget(std::weak_ptr<Item> item, QWidget *parent);
|
||||||
std::weak_ptr<Item> getItem();
|
std::weak_ptr<Item> getItem();
|
||||||
bool controles(const ItemData& relay);
|
bool controles(const ItemData& relay);
|
||||||
~ItemWidget();
|
~ItemWidget();
|
||||||
void setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev);
|
void setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void stateChanged(int state);
|
void stateChanged(int state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ItemWidget *ui;
|
Ui::ItemWidget *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RELAYWIDGET_H
|
#endif // RELAYWIDGET_H
|
||||||
|
@ -5,31 +5,31 @@
|
|||||||
#include "itemcreationdialog.h"
|
#include "itemcreationdialog.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent) :
|
MainWindow::MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
stopShort(QKeySequence(Qt::Key_Space), this),
|
stopShort(QKeySequence(Qt::Key_Space), this),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
_micro(micro)
|
_micro(micro)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
connect(&stopShort, &QShortcut::activated, _micro, &Microcontroller::estop);
|
connect(&stopShort, &QShortcut::activated, _micro, &Microcontroller::estop);
|
||||||
connect(ui->pushButton_stop, &QPushButton::clicked, _micro, &Microcontroller::estop);
|
connect(ui->pushButton_stop, &QPushButton::clicked, _micro, &Microcontroller::estop);
|
||||||
connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
|
connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
|
||||||
|
|
||||||
connect(items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
connect(items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
||||||
connect(items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
connect(items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
||||||
|
|
||||||
for(size_t i = 0; i < items->getItems()->size(); ++i)
|
for(size_t i = 0; i < items->getItems()->size(); ++i)
|
||||||
{
|
{
|
||||||
ui->relayList->addItem(items->getItems()->at(i));
|
ui->relayList->addItem(items->getItems()->at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui->relayList, &ItemScrollBox::deleteRequest, items, &ItemStore::removeItem);
|
connect(ui->relayList, &ItemScrollBox::deleteRequest, items, &ItemStore::removeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -20,25 +20,25 @@ class MainWindow;
|
|||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QShortcut stopShort;
|
QShortcut stopShort;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent = nullptr);
|
explicit MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
Microcontroller *_micro;
|
Microcontroller *_micro;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void createdItem(std::shared_ptr<Item> item);
|
void createdItem(std::shared_ptr<Item> item);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
//void showItemCreationDialog();
|
//void showItemCreationDialog();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user