Added text edit control and tabs to object edit widget
Dieser Commit ist enthalten in:
Ursprung
6a7aac1634
Commit
4180adbadc
@ -22,6 +22,8 @@
|
||||
|
||||
#include "objecteditwidget.hpp"
|
||||
#include <QFormLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTabWidget>
|
||||
#include <QtWaitingSpinner/waitingspinnerwidget.h>
|
||||
#include "../network/client.hpp"
|
||||
#include "../network/object.hpp"
|
||||
@ -31,6 +33,7 @@
|
||||
#include "../widget/propertycheckbox.hpp"
|
||||
#include "../widget/propertyspinbox.hpp"
|
||||
#include "../widget/propertylineedit.hpp"
|
||||
#include "../widget/propertytextedit.hpp"
|
||||
#include "../widget/propertydirectioncontrol.hpp"
|
||||
|
||||
#include <enum/direction.hpp>
|
||||
@ -39,8 +42,6 @@ ObjectEditWidget::ObjectEditWidget(const QString& id, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
m_id{id}
|
||||
{
|
||||
setLayout(new QFormLayout());
|
||||
|
||||
auto* spinner = new WaitingSpinnerWidget(this, true, false);
|
||||
spinner->start();
|
||||
|
||||
@ -66,7 +67,7 @@ ObjectEditWidget::~ObjectEditWidget()
|
||||
|
||||
void ObjectEditWidget::buildForm()
|
||||
{
|
||||
QFormLayout* l = static_cast<QFormLayout*>(this->layout());
|
||||
QMap<QString, QWidget*> tabs;
|
||||
|
||||
for(auto item : m_object->interfaceItems())
|
||||
if(Property* property = dynamic_cast<Property*>(item))
|
||||
@ -78,7 +79,18 @@ void ObjectEditWidget::buildForm()
|
||||
else if(property->type() == PropertyType::Integer)
|
||||
w = new PropertySpinBox(*property);
|
||||
else if(property->type() == PropertyType::String)
|
||||
w = new PropertyLineEdit(*property);
|
||||
{
|
||||
if(property->name() == "notes")
|
||||
{
|
||||
PropertyTextEdit* edit = new PropertyTextEdit(*property);
|
||||
edit->setPlaceholderText(property->displayName());
|
||||
Q_ASSERT(!tabs.contains("notes"));
|
||||
tabs.insert("notes", edit);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
w = new PropertyLineEdit(*property);
|
||||
}
|
||||
else if(property->type() == PropertyType::Enum)
|
||||
{
|
||||
if(property->enumName() == EnumName<Direction>::value)
|
||||
@ -90,6 +102,34 @@ void ObjectEditWidget::buildForm()
|
||||
// w = dropdown
|
||||
}
|
||||
|
||||
l->addRow(property->displayName(), w);
|
||||
QWidget* tabWidget;
|
||||
QString tab = "general"; // TODO: get sttribute
|
||||
if(!tabs.contains(tab))
|
||||
{
|
||||
tabWidget = new QWidget();
|
||||
tabWidget->setLayout(new QFormLayout());
|
||||
tabs.insert(tab, tabWidget);
|
||||
}
|
||||
else
|
||||
tabWidget = tabs[tab];
|
||||
|
||||
static_cast<QFormLayout*>(tabWidget->layout())->addRow(property->displayName(), w);
|
||||
}
|
||||
|
||||
if(tabs.count() > 1)
|
||||
{
|
||||
QTabWidget* tabWidget = new QTabWidget();
|
||||
for(auto it = tabs.constBegin(); it != tabs.constEnd(); it++)
|
||||
tabWidget->addTab(it.value(), it.key());
|
||||
QVBoxLayout* l = new QVBoxLayout();
|
||||
l->setMargin(0);
|
||||
l->addWidget(tabWidget);
|
||||
setLayout(l);
|
||||
}
|
||||
else if(tabs.count() == 1)
|
||||
{
|
||||
QWidget* w = tabs.first();
|
||||
setLayout(w->layout());
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
|
||||
34
client/src/widget/propertytextedit.cpp
Normale Datei
34
client/src/widget/propertytextedit.cpp
Normale Datei
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* client/src/widget/propertytextedit.cpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "propertytextedit.hpp"
|
||||
#include "../network/property.hpp"
|
||||
|
||||
PropertyTextEdit::PropertyTextEdit(Property& property, QWidget* parent) :
|
||||
QTextEdit(parent),
|
||||
m_property{property}
|
||||
{
|
||||
Q_ASSERT(m_property.type() == PropertyType::String);
|
||||
setPlainText(m_property.toString());
|
||||
connect(&m_property, &Property::valueChangedString, this, &PropertyTextEdit::setPlainText);
|
||||
connect(this, &PropertyTextEdit::textChanged, [this](){ m_property.setValueString(toPlainText()); });
|
||||
}
|
||||
39
client/src/widget/propertytextedit.hpp
Normale Datei
39
client/src/widget/propertytextedit.hpp
Normale Datei
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* client/src/widget/propertytextedit.hpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef CLIENT_WIDGET_PROPERTYTEXTEDIT_HPP
|
||||
#define CLIENT_WIDGET_PROPERTYTEXTEDIT_HPP
|
||||
|
||||
#include <QTextEdit>
|
||||
|
||||
class Property;
|
||||
|
||||
class PropertyTextEdit : public QTextEdit
|
||||
{
|
||||
protected:
|
||||
Property& m_property;
|
||||
|
||||
public:
|
||||
PropertyTextEdit(Property& property, QWidget* parent = nullptr);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -42,7 +42,8 @@ SOURCES += \
|
||||
src/widget/propertycheckbox.cpp \
|
||||
src/widget/propertylineedit.cpp \
|
||||
src/widget/propertyspinbox.cpp \
|
||||
src/widget/propertydirectioncontrol.cpp
|
||||
src/widget/propertydirectioncontrol.cpp \
|
||||
src/widget/propertytextedit.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/mainwindow.hpp \
|
||||
@ -75,7 +76,8 @@ HEADERS += \
|
||||
src/network/abstractproperty.hpp \
|
||||
src/widget/propertylineedit.hpp \
|
||||
src/widget/propertyspinbox.hpp \
|
||||
src/widget/propertydirectioncontrol.hpp
|
||||
src/widget/propertydirectioncontrol.hpp \
|
||||
src/widget/propertytextedit.hpp
|
||||
|
||||
RESOURCES += \
|
||||
dark.qrc
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren