Exemplo n.º 1
0
    void FastoEditorOutput::layoutChanged()
    {
        clear();
        if(!model_){
            return;
        }

        QModelIndex index = model_->index(0, 0);
        if(!index.isValid()){
            return;
        }

        FastoCommonItem* child = common::utils_qt::item<FastoCommonItem*>(index);
        if(!child){
            return;
        }

        FastoCommonItem* root = dynamic_cast<FastoCommonItem*>(child->parent());
        if(!root){
            return;
        }

        QString result;
        for(int i = 0; i < root->childrenCount(); ++i){
            FastoCommonItem* child = dynamic_cast<FastoCommonItem*>(root->child(i));
            if(!child){
                continue;
            }

            if(viewMethod_ == JSON){
                QString json = toJson(child);
                result += common::escapedText(json);
            }
            else if(viewMethod_ == CSV){
                QString csv = toCsv(child, delemitr_);
                result += common::escapedText(csv);
            }
            else if(viewMethod_ == RAW){
                QString raw = toRaw(child);
                result += common::escapedText(raw);
            }
            else if(viewMethod_ == HEX){
                QString hex = toHex(child);
                result += common::escapedText(hex);
            }
            else if(viewMethod_ == MSGPACK){
                QString hex = fromHexMsgPack(child);
                result += common::escapedText(hex);
            }
            else if(viewMethod_ == GZIP){
                QString gzip = fromGzip(child);
                result += common::escapedText(gzip);
            }
        }

        setText(result);
    }
Exemplo n.º 2
0
 Qt::ItemFlags FastoCommonModel::flags(const QModelIndex& index) const
 {
     Qt::ItemFlags result = 0;
     if (index.isValid()) {
         result = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
         int col = index.column();
         FastoCommonItem *node = common::utils_qt::item<FastoCommonItem*>(index);
         if(node && col == FastoCommonItem::eValue && !node->isReadOnly()){
             result |= Qt::ItemIsEditable;
         }
     }
     return result;
 }
Exemplo n.º 3
0
    void FastoCommonModel::changeValue(const NDbValue& value)
    {
        QModelIndex ind = index(0, 0);
        if(!ind.isValid()){
            return;
        }

        FastoCommonItem* child = common::utils_qt::item<FastoCommonItem*>(ind);
        if(!child){
            return;
        }

        FastoCommonItem* root = dynamic_cast<FastoCommonItem*>(child->parent());
        if(!root){
            return;
        }

        const QString key = common::convertFromString<QString>(value.keyString());
        const QString val = common::convertFromString<QString>(value.valueString());

        for(int i = 0; i < root->childrenCount(); ++i){
            FastoCommonItem* child = dynamic_cast<FastoCommonItem*>(root->child(i));
            if(!child){
                continue;
            }

            if(child->key() == key){
                child->setValue(val);
                emit dataChanged(index(i, FastoCommonItem::eValue), index(i, FastoCommonItem::eType));
                break;
            }
        }
    }
Exemplo n.º 4
0
    bool FastoCommonModel::setData(const QModelIndex& index, const QVariant& value, int role)
    {
        if (index.isValid() && role == Qt::EditRole) {
            int column = index.column();
            FastoCommonItem *node = common::utils_qt::item<FastoCommonItem*>(index);

            if (!node)
                return false;

            if (column == FastoCommonItem::eKey) {

            }
            else if (column == FastoCommonItem::eValue) {
                const QString newValue = value.toString();
                if(newValue != node->value()){
                    const std::string key = common::convertToString(node->key());
                    const std::string value = common::convertToString(newValue);
                    emit changedValue(NDbValue(key, value, node->type()), node->changeCommand());
                }
            }
        }

        return false;
    }
Exemplo n.º 5
0
    QVariant FastoCommonModel::data(const QModelIndex& index, int role) const
    {
        QVariant result;

        if (!index.isValid())
            return result;

        FastoCommonItem *node = common::utils_qt::item<FastoCommonItem*>(index);

        if (!node)
            return result;

        int col = index.column();

        if(role == Qt::DecorationRole && col == FastoCommonItem::eKey ){
            return GuiFactory::instance().icon(node->type());
        }

        if(role == Qt::TextColorRole && col == FastoCommonItem::eType){
            return QColor(Qt::gray);
        }

        if (role == Qt::DisplayRole) {
            if (col == FastoCommonItem::eKey) {
                result = node->key();
            }
            else if (col == FastoCommonItem::eValue) {
                result = node->value();
            }
            else if (col == FastoCommonItem::eType) {
                result = common::convertFromString<QString>(common::Value::toString(node->type()));
            }
        }

        return result;
    }