git-svn-id: svn://db.shs.com.ru/libs@117 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -15,10 +15,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||||
endif ()
|
endif ()
|
||||||
file(GLOB HDRS_UTILS "*.h")
|
#file(GLOB HDRS_UTILS "*.h")
|
||||||
file(GLOB CPPS_UTILS "*.cpp")
|
#file(GLOB CPPS_UTILS "*.cpp")
|
||||||
#set(CPPS_UTILS "cdutils_core.cpp" "cdutils_k_types.cpp" "cdutils_k_parser.cpp" "cdutils_k.cpp")
|
set(CPPS_UTILS "cdutils_core.cpp" "cdutils_types.cpp" "cdutils_parser.cpp" "cdutils_k.cpp")
|
||||||
#set(HDRS_UTILS "cdutils_core.h" "cdutils_k_types.h" "cdutils_k_parser.h" "cdutils_k.h")
|
set(HDRS_UTILS "cdutils_core.h" "cdutils_types.h" "cdutils_parser.h" "cdutils_k.h" "cdutils_protocol.h")
|
||||||
if (DEFINED ENV{QNX_HOST})
|
if (DEFINED ENV{QNX_HOST})
|
||||||
add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS} ${HDRS_UTILS})
|
add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS} ${HDRS_UTILS})
|
||||||
else ()
|
else ()
|
||||||
@@ -26,7 +26,7 @@ else ()
|
|||||||
endif ()
|
endif ()
|
||||||
target_link_libraries(${PROJECT_NAME} ${PIP_LIBRARY})
|
target_link_libraries(${PROJECT_NAME} ${PIP_LIBRARY})
|
||||||
|
|
||||||
add_executable(cdutilstest "cdutilstest.cpp")
|
add_executable(cdutilstest "cdutilstest.cpp" "cdtest.h")
|
||||||
target_link_libraries(cdutilstest ${PIP_LIBRARY} ${PROJECT_NAME})
|
target_link_libraries(cdutilstest ${PIP_LIBRARY} ${PROJECT_NAME})
|
||||||
|
|
||||||
if (NOT DEFINED ENV{QNX_HOST})
|
if (NOT DEFINED ENV{QNX_HOST})
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v
|
|||||||
value_i = v.toInt();
|
value_i = v.toInt();
|
||||||
value_b = v.toBool();
|
value_b = v.toBool();
|
||||||
cd_type_ = cd_t;
|
cd_type_ = cd_t;
|
||||||
|
if (type_ == "e") {
|
||||||
|
enum_values << comment_.inBrackets('{', '}').split(",");
|
||||||
|
piForeach(PIString &s, enum_values) s.trim();
|
||||||
|
// piCout << enum_values.size() << enum_values;
|
||||||
|
}
|
||||||
// piCout << type_.size() << type_.toUTF8();
|
// piCout << type_.size() << type_.toUTF8();
|
||||||
// piCout << formula_.size() << formula_.toUTF8();
|
// piCout << formula_.size() << formula_.toUTF8();
|
||||||
// piCout << comment_.size() << comment_.toUTF8();
|
// piCout << comment_.size() << comment_.toUTF8();
|
||||||
@@ -47,8 +52,22 @@ PIString CDType::type() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString CDType::value() const {
|
||||||
|
return PIString::fromBool(value_b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CDType::setFormula(const PIString &f) {
|
void CDType::setFormula(const PIString &f) {
|
||||||
formula_ = f;
|
formula_ = f;
|
||||||
|
calculate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CDType::calculate() {
|
||||||
|
value_s = formula_.trimmed();
|
||||||
|
value_d = formula_.toDouble();
|
||||||
|
value_i = formula_.toInt();
|
||||||
|
value_b = formula_.toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,19 +15,14 @@ class CDSection;
|
|||||||
|
|
||||||
class CDType {
|
class CDType {
|
||||||
friend class CDSection;
|
friend class CDSection;
|
||||||
friend class ::CD_Pult;
|
|
||||||
//friend class ::CDKItem;
|
|
||||||
public:
|
public:
|
||||||
enum cdT {cdNull, cdK, cdX, cdC};
|
enum cdT {cdNull, cdK, cdX, cdC};
|
||||||
CDType();
|
CDType();
|
||||||
CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t);
|
CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t);
|
||||||
// CDType(const CDType & cdt);
|
|
||||||
// CDType & operator =(const CDType & cdt);
|
|
||||||
// ~CDType();
|
|
||||||
int index() const {return index_;}
|
int index() const {return index_;}
|
||||||
PIString name() const {return name_;}
|
PIString name() const {return name_;}
|
||||||
PIString type() const;
|
PIString type() const;
|
||||||
PIString value() const {return value_s;}
|
PIString value() const;
|
||||||
PIString formula() const {return formula_;}
|
PIString formula() const {return formula_;}
|
||||||
PIString comment() const {return comment_;}
|
PIString comment() const {return comment_;}
|
||||||
double toDouble() const {return value_d;}
|
double toDouble() const {return value_d;}
|
||||||
@@ -35,19 +30,19 @@ public:
|
|||||||
bool toBool() const {return value_b;}
|
bool toBool() const {return value_b;}
|
||||||
cdT cd_type() const {return cd_type_;}
|
cdT cd_type() const {return cd_type_;}
|
||||||
void setFormula(const PIString & formula);
|
void setFormula(const PIString & formula);
|
||||||
|
void calculate();
|
||||||
operator double() const {return value_d;}
|
operator double() const {return value_d;}
|
||||||
|
const PIStringList & enumValues() const {return enum_values;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cdT cd_type_;
|
cdT cd_type_;
|
||||||
int index_;
|
int index_;
|
||||||
PIString name_, type_;
|
PIString name_, type_;
|
||||||
PIString value_s, formula_, comment_;
|
PIString value_s, formula_, comment_;
|
||||||
|
PIStringList enum_values;
|
||||||
double value_d;
|
double value_d;
|
||||||
int value_i;
|
int value_i;
|
||||||
bool value_b;
|
bool value_b;
|
||||||
// int debug_cnt;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "piethernet.h"
|
#include "piethernet.h"
|
||||||
#include "piiostring.h"
|
#include "piiostring.h"
|
||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
|
#include "pievaluator.h"
|
||||||
#include "cdtest.h"
|
#include "cdtest.h"
|
||||||
|
|
||||||
using namespace CDUtils;
|
using namespace CDUtils;
|
||||||
@@ -60,38 +61,54 @@ private:
|
|||||||
|
|
||||||
#include "piscreen.h"
|
#include "piscreen.h"
|
||||||
#include "piscreentiles.h"
|
#include "piscreentiles.h"
|
||||||
PIScreen screen(false);
|
//PIScreen screen;
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
PIString s;
|
PIString s;
|
||||||
int i = 0;
|
s = "df a)))(a(ttt){a(b(c)})d)e( d dws ) sds(()fads(fdas()))fda))))fdasf((((jhvw";
|
||||||
piCout << i++ << "!" << s << "!";
|
piCout << s;
|
||||||
piCout << i << "!" << s.trimmed() << "!";
|
piCout << s.inBrackets('(', ')');
|
||||||
piCout << i << "!" << s.trim() << "!";
|
piCout << s.cutLeft(s.find('(')).takeRange('(', ')');
|
||||||
s = "";
|
piCout << s;
|
||||||
piCout << i++ << "!" << s << "!";
|
piCout << "exit";
|
||||||
piCout << i << "!" << s.trimmed() << "!";
|
s = "test";
|
||||||
piCout << i << "!" << s.trim() << "!";
|
PIByteArray ba = s.toByteArray();
|
||||||
s = " ";
|
piCout << PIString(ba);
|
||||||
piCout << i++ << "!" << s << "!";
|
piCout << PIString(ba.convertToBase64());
|
||||||
piCout << i << "!" << s.trimmed() << "!";
|
piCout << PIString(ba.convertFromBase64());
|
||||||
piCout << i << "!" << s.trim() << "!";
|
s = "dGVzdA==";
|
||||||
s = " ";
|
ba = s.toByteArray();
|
||||||
piCout << i++ << "!" << s << "!";
|
piCout << PIString(ba);
|
||||||
piCout << i << "!" << s.trimmed() << "!";
|
piCout << PIString(ba.convertFromBase64());
|
||||||
piCout << i << "!" << s.trim() << "!";
|
|
||||||
s = " s ";
|
|
||||||
piCout << i++ << "!" << s << "!";
|
|
||||||
piCout << i << "!" << s.trimmed() << "!";
|
|
||||||
piCout << i << "!" << s.trim() << "!";
|
|
||||||
s = "f s ";
|
|
||||||
piCout << i++ << "!" << s << "!";
|
|
||||||
piCout << i << "!" << s.trimmed() << "!";
|
|
||||||
piCout << i << "!" << s.trim() << "!";
|
|
||||||
s = " kjdfsnfv;kjsfd ";
|
|
||||||
piCout << i++ << "!" << s << "!";
|
|
||||||
piCout << i << "!" << s.trimmed() << "!";
|
|
||||||
piCout << i << "!" << s.trim() << "!";
|
|
||||||
return 0;
|
return 0;
|
||||||
|
// int i = 0;
|
||||||
|
// piCout << i++ << "!" << s << "!";
|
||||||
|
// piCout << i << "!" << s.trimmed() << "!";
|
||||||
|
// piCout << i << "!" << s.trim() << "!";
|
||||||
|
// s = "";
|
||||||
|
// piCout << i++ << "!" << s << "!";
|
||||||
|
// piCout << i << "!" << s.trimmed() << "!";
|
||||||
|
// piCout << i << "!" << s.trim() << "!";
|
||||||
|
// s = " ";
|
||||||
|
// piCout << i++ << "!" << s << "!";
|
||||||
|
// piCout << i << "!" << s.trimmed() << "!";
|
||||||
|
// piCout << i << "!" << s.trim() << "!";
|
||||||
|
// s = " ";
|
||||||
|
// piCout << i++ << "!" << s << "!";
|
||||||
|
// piCout << i << "!" << s.trimmed() << "!";
|
||||||
|
// piCout << i << "!" << s.trim() << "!";
|
||||||
|
// s = " s ";
|
||||||
|
// piCout << i++ << "!" << s << "!";
|
||||||
|
// piCout << i << "!" << s.trimmed() << "!";
|
||||||
|
// piCout << i << "!" << s.trim() << "!";
|
||||||
|
// s = "f s ";
|
||||||
|
// piCout << i++ << "!" << s << "!";
|
||||||
|
// piCout << i << "!" << s.trimmed() << "!";
|
||||||
|
// piCout << i << "!" << s.trim() << "!";
|
||||||
|
// s = " kjdfsnfv;kjsfd ";
|
||||||
|
// piCout << i++ << "!" << s << "!";
|
||||||
|
// piCout << i << "!" << s.trimmed() << "!";
|
||||||
|
// piCout << i << "!" << s.trim() << "!";
|
||||||
|
// return 0;
|
||||||
// PIEthernet eth;
|
// PIEthernet eth;
|
||||||
// eth.send("127.0.0.1:16102", PIByteArray("data\n", 5));
|
// eth.send("127.0.0.1:16102", PIByteArray("data\n", 5));
|
||||||
// eth.send("127.0.0.1:26102", PIByteArray("data\n", 5));
|
// eth.send("127.0.0.1:26102", PIByteArray("data\n", 5));
|
||||||
@@ -141,7 +158,7 @@ int main(int argc, char *argv[]) {
|
|||||||
//return 0;
|
//return 0;
|
||||||
// piCout << "init";
|
// piCout << "init";
|
||||||
// screen.rootTile()->addTile(new TilePICout());
|
// screen.rootTile()->addTile(new TilePICout());
|
||||||
screen.enableExitCapture('q');
|
// screen.enableExitCapture('q');
|
||||||
// screen.start();
|
// screen.start();
|
||||||
piCout << "start";
|
piCout << "start";
|
||||||
Core core;
|
Core core;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include "qvariantedit.h"
|
||||||
|
|
||||||
using namespace CDUtils;
|
using namespace CDUtils;
|
||||||
|
|
||||||
@@ -74,12 +75,29 @@ Qt::ItemFlags CDKItemModel::flags(const QModelIndex &index) const {
|
|||||||
if (!index.isValid()) return 0;
|
if (!index.isValid()) return 0;
|
||||||
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
CDKItem * item = getItem(index);
|
CDKItem * item = getItem(index);
|
||||||
if (index.column() == 3 && item->type_ == CDKItem::ItemCDType) f |= Qt::ItemIsEditable;
|
if ((index.column() == 3 || index.column() == 4) && item->type_ == CDKItem::ItemCDType) f |= Qt::ItemIsEditable;
|
||||||
|
if (item->type_ == CDKItem::ItemCDType && index.column() == 4) {
|
||||||
|
CDType t = K.section(item->buildPath())[item->index_];
|
||||||
|
if (t.type() == "b") {
|
||||||
|
f |= Qt::ItemIsUserCheckable;
|
||||||
|
// piCout << "ItemIsUserCheckable";
|
||||||
|
}
|
||||||
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CDKItemModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
bool CDKItemModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
||||||
|
if (role == Qt::CheckStateRole && index.column() == 4) {
|
||||||
|
CDKItem * item = getItem(index);
|
||||||
|
if (item->type_ == CDKItem::ItemCDType) {
|
||||||
|
CDType t = K.section(item->buildPath())[item->index_];
|
||||||
|
if (t.type() == "b") {
|
||||||
|
bool result = item->setData(index.column(), PI2QString(PIString::fromBool(value.toBool())));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (role != Qt::EditRole) return false;
|
if (role != Qt::EditRole) return false;
|
||||||
CDKItem * item = getItem(index);
|
CDKItem * item = getItem(index);
|
||||||
bool result = item->setData(index.column(), value);
|
bool result = item->setData(index.column(), value);
|
||||||
@@ -127,6 +145,8 @@ CDKItem * CDKItemModel::getItem(const QModelIndex &index) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CDKItem
|
||||||
|
|
||||||
CDKItem::CDKItem(int index, CDKItem::CDKItemType type, CDKItem *parent) {
|
CDKItem::CDKItem(int index, CDKItem::CDKItemType type, CDKItem *parent) {
|
||||||
index_ = index;
|
index_ = index;
|
||||||
parent_ = parent;
|
parent_ = parent;
|
||||||
@@ -143,9 +163,14 @@ QVariant CDKItem::data(int column, int role) const {
|
|||||||
if (role == Qt::BackgroundRole) {
|
if (role == Qt::BackgroundRole) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case ItemCDType: return QBrush(QColor(255, 250, 230));
|
case ItemCDType: return QBrush(QColor(255, 250, 230));
|
||||||
case ItemCDSection: return QBrush(QColor(220, 220, 250));
|
case ItemCDSection: return QBrush(QColor(230, 250, 230));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (role == Qt::CheckStateRole && type_ == ItemCDType && column == 4) {
|
||||||
|
CDType & t = K.section(buildPath())[index_];
|
||||||
|
if (t.type() == "b") return t.toBool() ? Qt::Checked : Qt::Unchecked;
|
||||||
|
else QVariant();
|
||||||
|
}
|
||||||
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
|
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
|
||||||
PIDeque<int> path = buildPath();
|
PIDeque<int> path = buildPath();
|
||||||
CDSection & rs = K.section(path);
|
CDSection & rs = K.section(path);
|
||||||
@@ -157,7 +182,7 @@ QVariant CDKItem::data(int column, int role) const {
|
|||||||
case 1: return PI2QString(rs[index_].name());
|
case 1: return PI2QString(rs[index_].name());
|
||||||
case 2: return stringType(rs[index_].type());
|
case 2: return stringType(rs[index_].type());
|
||||||
case 3: return PI2QString(rs[index_].formula());
|
case 3: return PI2QString(rs[index_].formula());
|
||||||
case 4: return PI2QString(rs[index_].value());
|
case 4: return value(rs[index_], role);
|
||||||
case 5: return PI2QString(rs[index_].comment());
|
case 5: return PI2QString(rs[index_].comment());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -179,8 +204,23 @@ QVariant CDKItem::data(int column, int role) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant CDKItem::value(CDType t, int role) const {
|
||||||
|
if (t.type() == "f") return t.toDouble();
|
||||||
|
if (t.type() == "n") return t.toInt();
|
||||||
|
if (t.type() == "b") return t.toBool();
|
||||||
|
if (t.type() == "e") {
|
||||||
|
QVariantEdit::EnumType et;
|
||||||
|
et.enum_list = PI2QStringList(t.enumValues());
|
||||||
|
et.value = et.enum_list.at(t.toInt());//et.enum_list.indexOf("");
|
||||||
|
if (role == Qt::EditRole)return QVariant::fromValue<QVariantEdit::EnumType>(et);
|
||||||
|
else return et.value;
|
||||||
|
}
|
||||||
|
return PI2QString(t.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CDKItem::setData(int column, const QVariant &value) {
|
bool CDKItem::setData(int column, const QVariant &value) {
|
||||||
if (column == 3 && type_ == ItemCDType) {
|
if ((column == 3 || column == 4) && type_ == ItemCDType) {
|
||||||
K.section(buildPath())[index_].setFormula(Q2PIString(value.toString()));
|
K.section(buildPath())[index_].setFormula(Q2PIString(value.toString()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -221,3 +261,41 @@ QString CDKItem::stringType(const PIString & t) const {
|
|||||||
return QString("double");
|
return QString("double");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CDKDelegate
|
||||||
|
|
||||||
|
CDKDelegate::CDKDelegate(QObject *parent) : QStyledItemDelegate(parent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QWidget *CDKDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||||
|
return new QVariantEdit(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CDKDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
|
||||||
|
QVariantEdit *edit = static_cast<QVariantEdit*>(editor);
|
||||||
|
edit->setValue(index.model()->data(index, Qt::EditRole));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CDKDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
|
||||||
|
QVariantEdit *edit = static_cast<QVariantEdit*>(editor);
|
||||||
|
QVariant v = edit->value();
|
||||||
|
if (v.canConvert<QVariantEdit::EnumType>()) {
|
||||||
|
QVariantEdit::EnumType et = v.value<QVariantEdit::EnumType>();
|
||||||
|
model->setData(index, et.enum_list.indexOf(et.value), Qt::EditRole);
|
||||||
|
} else model->setData(index, v, Qt::EditRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CDKDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||||
|
editor->setGeometry(option.rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSize CDKDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||||
|
QSize s = QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
s.setWidth(s.width() + 20);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
//#include "cdutils_k.h"
|
//#include "cdutils_k.h"
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QItemDelegate>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
#include "pistring.h"
|
#include "pistring.h"
|
||||||
|
|
||||||
namespace CDUtils {
|
namespace CDUtils {
|
||||||
class CDSection;
|
class CDSection;
|
||||||
|
class CDType;
|
||||||
}
|
}
|
||||||
class CDKItemModel;
|
class CDKItemModel;
|
||||||
|
|
||||||
@@ -17,6 +20,7 @@ public:
|
|||||||
CDKItem(int index, CDKItemType type, CDKItem * parent);
|
CDKItem(int index, CDKItemType type, CDKItem * parent);
|
||||||
~CDKItem();
|
~CDKItem();
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
QVariant value(CDUtils::CDType t, int role) const;
|
||||||
bool setData(int column, const QVariant & value);
|
bool setData(int column, const QVariant & value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -29,6 +33,21 @@ private:
|
|||||||
QList<CDKItem *> childs;
|
QList<CDKItem *> childs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class CDKDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CDKDelegate(QObject *parent = 0);
|
||||||
|
|
||||||
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||||
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||||
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class CDKItemModel : public QAbstractItemModel {
|
class CDKItemModel : public QAbstractItemModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ config(piqt(config_), QIODevice::ReadWrite) {
|
|||||||
CONNECT(void, &coeffs, receiveSucceed, this, pip_receiveSucceed);*/
|
CONNECT(void, &coeffs, receiveSucceed, this, pip_receiveSucceed);*/
|
||||||
kmodel = new CDKItemModel();
|
kmodel = new CDKItemModel();
|
||||||
ui->treeCDK->setModel(kmodel);
|
ui->treeCDK->setModel(kmodel);
|
||||||
|
delegate = new CDKDelegate();
|
||||||
|
ui->treeCDK->setItemDelegateForColumn(4, delegate);
|
||||||
connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection);
|
connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection);
|
||||||
connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection);
|
connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection);
|
||||||
connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection);
|
connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection);
|
||||||
@@ -463,6 +465,8 @@ void CD_Pult::updateTree(bool move) {
|
|||||||
//calculate();
|
//calculate();
|
||||||
filterTree();
|
filterTree();
|
||||||
kmodel->rebuildModel();
|
kmodel->rebuildModel();
|
||||||
|
ui->treeCDK->expandAll();
|
||||||
|
for (int i=0; i<6; i++) ui->treeCDK->resizeColumnToContents(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ private:
|
|||||||
SessionManager session;
|
SessionManager session;
|
||||||
QPIConfig config;
|
QPIConfig config;
|
||||||
CDKItemModel * kmodel;
|
CDKItemModel * kmodel;
|
||||||
|
CDKDelegate * delegate;
|
||||||
//QVector<float> k, x;
|
//QVector<float> k, x;
|
||||||
int clear_target, timer;
|
int clear_target, timer;
|
||||||
bool needWrite, isPause, need_update, show_x;
|
bool needWrite, isPause, need_update, show_x;
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ EComboBox::EComboBox(QWidget * parent): QComboBox(parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSize EComboBox::sizeHint() const {
|
||||||
|
QSize s = QComboBox::sizeHint();
|
||||||
|
s.setWidth(s.width() + 16);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void EComboBox::showPopup() {
|
void EComboBox::showPopup() {
|
||||||
filterChanged(filter.text(), true);
|
filterChanged(filter.text(), true);
|
||||||
QComboBox::showPopup();
|
QComboBox::showPopup();
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class EComboBox: public QComboBox
|
|||||||
public:
|
public:
|
||||||
explicit EComboBox(QWidget * parent = 0);
|
explicit EComboBox(QWidget * parent = 0);
|
||||||
|
|
||||||
|
QSize sizeHint() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void showPopup();
|
virtual void showPopup();
|
||||||
|
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
|||||||
switch (new_value.type()) {
|
switch (new_value.type()) {
|
||||||
case QVariant::Bool:
|
case QVariant::Bool:
|
||||||
_check = new QCheckBox(this);
|
_check = new QCheckBox(this);
|
||||||
|
_check->setAutoFillBackground(true);
|
||||||
_cur_edit = _check;
|
_cur_edit = _check;
|
||||||
connect(_check, SIGNAL(toggled(bool)), this, SLOT(_changed()));
|
connect(_check, SIGNAL(toggled(bool)), this, SLOT(_changed()));
|
||||||
break;
|
break;
|
||||||
@@ -225,7 +226,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
|||||||
break;
|
break;
|
||||||
case QVariant::Double:
|
case QVariant::Double:
|
||||||
_spin = new QDoubleSpinBox(this);
|
_spin = new QDoubleSpinBox(this);
|
||||||
_spin->setDecimals(3);
|
_spin->setDecimals(5);
|
||||||
_spin->setRange(-1E+199, 1E+199);
|
_spin->setRange(-1E+199, 1E+199);
|
||||||
_cur_edit = _spin;
|
_cur_edit = _spin;
|
||||||
connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
|
connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
|
||||||
@@ -289,7 +290,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
|||||||
}
|
}
|
||||||
if (!_cur_edit) {
|
if (!_cur_edit) {
|
||||||
if (new_value.canConvert<QVariantEdit::EnumType>()) {
|
if (new_value.canConvert<QVariantEdit::EnumType>()) {
|
||||||
_enum = new QComboBox(this);
|
_enum = new EComboBox(this);
|
||||||
_setEnum(new_value.value<QVariantEdit::EnumType>());
|
_setEnum(new_value.value<QVariantEdit::EnumType>());
|
||||||
_cur_edit = _enum;
|
_cur_edit = _enum;
|
||||||
connect(_enum, SIGNAL(currentIndexChanged(int)), this, SLOT(_changed()));
|
connect(_enum, SIGNAL(currentIndexChanged(int)), this, SLOT(_changed()));
|
||||||
@@ -368,7 +369,7 @@ void QVariantEdit::setValue(const QVariant & v) {
|
|||||||
_recreate(v);
|
_recreate(v);
|
||||||
if (_cur_edit) _cur_edit->blockSignals(true);
|
if (_cur_edit) _cur_edit->blockSignals(true);
|
||||||
if (_line) {_line->setText(v.toString());}
|
if (_line) {_line->setText(v.toString());}
|
||||||
if (_check) {_check->setChecked(v.toBool());}
|
if (_check) {_check->setChecked(v.toBool()); _check->setText(v.toBool() ? "true" : "false");}
|
||||||
if (_color) {_color->setColor(v.value<QColor>());}
|
if (_color) {_color->setColor(v.value<QColor>());}
|
||||||
if (_list) {_list->setValue(v.toStringList());}
|
if (_list) {_list->setValue(v.toStringList());}
|
||||||
if (_date) {_date->setDateTime(v.toDateTime());}
|
if (_date) {_date->setDateTime(v.toDateTime());}
|
||||||
@@ -441,3 +442,8 @@ void QVariantEdit::_setDir(const DirType & v) {
|
|||||||
_path->is_abs = v.is_abs;
|
_path->is_abs = v.is_abs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QVariantEdit::_changed() {
|
||||||
|
if (_check) _check->setText(_check->isChecked() ? "true" : "false");
|
||||||
|
emit valueChanged(value());
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,12 +130,12 @@ protected:
|
|||||||
QRectEdit * _rect;
|
QRectEdit * _rect;
|
||||||
QPointEdit * _point;
|
QPointEdit * _point;
|
||||||
PathEdit * _path;
|
PathEdit * _path;
|
||||||
QComboBox * _enum;
|
EComboBox * _enum;
|
||||||
QWidget * _cur_edit;
|
QWidget * _cur_edit;
|
||||||
QVariant _value;
|
QVariant _value;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void _changed() {emit valueChanged(value());}
|
void _changed();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setValue(const QVariant & v);
|
void setValue(const QVariant & v);
|
||||||
|
|||||||
Reference in New Issue
Block a user