1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

LP-567 improve treeitem const correcteness

This commit is contained in:
Philippe Renon 2018-03-12 22:29:33 +01:00
parent 849f7845a1
commit 6ded0d0b7a
3 changed files with 38 additions and 39 deletions

View File

@ -60,16 +60,15 @@ public:
TreeItem(data, parent), m_index(index), m_field(field)
{}
bool isEditable()
bool isEditable() const
{
return true;
}
virtual QWidget *createEditor(QWidget *parent) = 0;
virtual QVariant getEditorValue(QWidget *editor) = 0;
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
virtual void apply() {}
virtual bool isKnown()
virtual QWidget *createEditor(QWidget *parent) const = 0;
virtual QVariant getEditorValue(QWidget *editor) const = 0;
virtual void setEditorValue(QWidget *editor, QVariant value) const = 0;
virtual bool isKnown() const
{
return parent()->isKnown();
}
@ -130,7 +129,7 @@ public:
}
}
QWidget *createEditor(QWidget *parent)
QWidget *createEditor(QWidget *parent) const
{
QComboBox *editor = new QComboBox(parent);
@ -142,14 +141,14 @@ public:
return editor;
}
QVariant getEditorValue(QWidget *editor)
QVariant getEditorValue(QWidget *editor) const
{
QComboBox *comboBox = static_cast<QComboBox *>(editor);
return comboBox->currentIndex();
}
void setEditorValue(QWidget *editor, QVariant value)
void setEditorValue(QWidget *editor, QVariant value) const
{
QComboBox *comboBox = static_cast<QComboBox *>(editor);
@ -208,7 +207,7 @@ public:
}
}
QWidget *createEditor(QWidget *parent)
QWidget *createEditor(QWidget *parent) const
{
QSpinBox *editor = new QSpinBox(parent);
@ -217,7 +216,7 @@ public:
return editor;
}
QVariant getEditorValue(QWidget *editor)
QVariant getEditorValue(QWidget *editor) const
{
QSpinBox *spinBox = static_cast<QSpinBox *>(editor);
@ -225,7 +224,7 @@ public:
return spinBox->value();
}
void setEditorValue(QWidget *editor, QVariant value)
void setEditorValue(QWidget *editor, QVariant value) const
{
QSpinBox *spinBox = static_cast<QSpinBox *>(editor);
@ -290,7 +289,7 @@ public:
}
}
QWidget *createEditor(QWidget *parent)
QWidget *createEditor(QWidget *parent) const
{
if (m_useScientificNotation) {
QScienceSpinBox *editor = new QScienceSpinBox(parent);
@ -307,7 +306,7 @@ public:
}
}
QVariant getEditorValue(QWidget *editor)
QVariant getEditorValue(QWidget *editor) const
{
if (m_useScientificNotation) {
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox *>(editor);
@ -320,7 +319,7 @@ public:
}
}
void setEditorValue(QWidget *editor, QVariant value)
void setEditorValue(QWidget *editor, QVariant value) const
{
if (m_useScientificNotation) {
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox *>(editor);
@ -346,7 +345,7 @@ public:
FieldTreeItem(index, data, field, parent)
{}
QWidget *createEditor(QWidget *parent)
QWidget *createEditor(QWidget *parent) const
{
QLineEdit *lineEdit = new QLineEdit(parent);
@ -355,14 +354,14 @@ public:
return lineEdit;
}
QVariant getEditorValue(QWidget *editor)
QVariant getEditorValue(QWidget *editor) const
{
QLineEdit *lineEdit = static_cast<QLineEdit *>(editor);
return lineEdit->text();
}
void setEditorValue(QWidget *editor, QVariant value)
void setEditorValue(QWidget *editor, QVariant value) const
{
QLineEdit *lineEdit = static_cast<QLineEdit *>(editor);
@ -392,7 +391,7 @@ public:
}
private:
QVariant toHexString(QVariant value)
QVariant toHexString(QVariant value) const
{
QString str;
bool ok;
@ -400,7 +399,7 @@ private:
return str.setNum(value.toUInt(&ok), 16).toUpper();
}
QVariant toUInt(QVariant str)
QVariant toUInt(QVariant str) const
{
bool ok;
@ -419,7 +418,7 @@ public:
FieldTreeItem(index, data, field, parent)
{}
QWidget *createEditor(QWidget *parent)
QWidget *createEditor(QWidget *parent) const
{
QLineEdit *lineEdit = new QLineEdit(parent);
@ -428,14 +427,14 @@ public:
return lineEdit;
}
QVariant getEditorValue(QWidget *editor)
QVariant getEditorValue(QWidget *editor) const
{
QLineEdit *lineEdit = static_cast<QLineEdit *>(editor);
return lineEdit->text();
}
void setEditorValue(QWidget *editor, QVariant value)
void setEditorValue(QWidget *editor, QVariant value) const
{
QLineEdit *lineEdit = static_cast<QLineEdit *>(editor);
@ -463,14 +462,13 @@ public:
setHighlight(true);
}
}
private:
QVariant toChar(QVariant value)
QVariant toChar(QVariant value) const
{
return value.toChar();
}
QVariant toUInt(QVariant str)
QVariant toUInt(QVariant str) const
{
return QVariant(str.toString().at(0).toLatin1());
}

View File

@ -161,7 +161,7 @@ void TreeItem::insertChild(TreeItem *child)
child->setParentTree(this);
}
TreeItem *TreeItem::getChild(int index)
TreeItem *TreeItem::getChild(int index) const
{
return m_children.value(index);
}
@ -250,7 +250,7 @@ void TreeItem::setHighlightManager(HighLightManager *mgr)
m_highlightManager = mgr;
}
QTime TreeItem::getHiglightExpires()
QTime TreeItem::getHiglightExpires() const
{
return m_highlightExpires;
}

View File

@ -99,7 +99,7 @@ public:
void appendChild(TreeItem *child);
void insertChild(TreeItem *child);
TreeItem *getChild(int index);
TreeItem *getChild(int index) const;
inline QList<TreeItem *> treeChildren() const
{
return m_children;
@ -107,12 +107,13 @@ public:
int childCount() const;
int columnCount() const;
virtual QVariant data(int column = 1) const;
QString description()
QString description() const
{
return m_description;
}
void setDescription(QString d) // Split around 40 characters
void setDescription(QString d)
{
// Split around 40 characters
int idx = d.indexOf(" ", 40);
d.insert(idx, QString("<br>"));
@ -123,7 +124,7 @@ public:
// other columns are initialized in constructor
virtual void setData(QVariant value, int column = 1);
int row() const;
TreeItem *parent()
TreeItem *parent() const
{
return m_parent;
}
@ -131,14 +132,14 @@ public:
{
m_parent = parent;
}
inline virtual bool isEditable()
inline virtual bool isEditable() const
{
return false;
}
virtual void update();
virtual void apply();
inline bool highlighted()
inline bool highlighted() const
{
return m_highlight;
}
@ -148,7 +149,7 @@ public:
m_highlightTimeMs = time;
}
inline bool changed()
inline bool changed() const
{
return m_changed;
}
@ -159,11 +160,11 @@ public:
virtual void setHighlightManager(HighLightManager *mgr);
QTime getHiglightExpires();
QTime getHiglightExpires() const;
virtual void removeHighlight();
int nameIndex(QString name)
int nameIndex(QString name) const
{
for (int i = 0; i < childCount(); ++i) {
if (name < getChild(i)->data(0).toString()) {
@ -173,7 +174,7 @@ public:
return childCount();
}
TreeItem *findChildByName(QString name)
TreeItem *findChildByName(QString name) const
{
foreach(TreeItem * child, m_children) {
if (name == child->data(0).toString()) {
@ -219,7 +220,7 @@ public:
emit updateIsKnown(this);
}
}
virtual bool isKnown()
virtual bool isKnown() const
{
return true;
}