void JsonEditorMain::refreshJsonTree()
{
    if (!ui->jsonCode->document()->isEmpty())
    {
        QByteArray ss = ui->jsonCode->toPlainText().toLocal8Bit();
        std::string json = ui->jsonCode->toPlainText().toStdString();
        Json::Reader jsonReader;
        jsonValue.clear();
        jsonReader.parse(ss.data(), jsonValue);

        QStringList headers;
        headers << treeViewColumnKey << treeViewColumnValue << treeViewColumnType;



        QAbstractItemModel *oldModel = ui->jsonTree->model();
        if (oldModel != NULL)
            oldModel->disconnect(SIGNAL(dataChanged(QModelIndex,QModelIndex)));

        JsonTreeModel *model = new JsonTreeModel(headers, jsonValue);
        QItemSelectionModel *selectionModel = ui->jsonTree->selectionModel();
        connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(treeViewDataChanged()));
        ui->jsonTree->setModel(model);
        ui->jsonTree->reset();
        delete selectionModel;
        delete oldModel;


        ui->jsonTree->expandAll();

        for (int i = 0; i < ui->jsonTree->model()->columnCount(); i++)
            ui->jsonTree->resizeColumnToContents(i);
    }
}
Пример #2
0
	// *** TreeChainsawFilter ***
	void TreeChainsawFilter::setSourceModel(QAbstractItemModel *sourceModel)
	{
		QAbstractItemModel* oldSource = this->sourceModel();
		if (oldSource)
			oldSource->disconnect(this);
		QAbstractProxyModel::setSourceModel(sourceModel);
		connect(sourceModel, SIGNAL(modelReset()), this, SLOT(resetInternalData()));
		sort(0, Qt::AscendingOrder);
	}
Пример #3
0
void BooksCoverModel::setSource(QObject* aSrc)
{
    QAbstractItemModel* oldM = sourceModel();
    if (aSrc != oldM) {
        const int oldCount = count();
        if (oldM) {
            BooksShelf* oldShelf = qobject_cast<BooksShelf*>(oldM);
            if (oldShelf) {
                const int n = oldShelf->count();
                for (int i=0; i<n; i++) {
                    onBookRemoved(oldShelf->bookAt(i));
                }
            }
            oldM->disconnect(this);
        }
        if (aSrc) {
            QAbstractItemModel* newM = qobject_cast<QAbstractItemModel*>(aSrc);
            if (newM) {
                setSourceModel(newM);
                BooksShelf* newShelf = qobject_cast<BooksShelf*>(newM);
                if (newShelf) {
                    const int n = newShelf->count();
                    for (int i=0; i<n; i++) {
                        onBookAdded(newShelf->bookAt(i));
                    }
                    connect(newShelf,
                        SIGNAL(bookAdded(BooksBook*)),
                        SLOT(onBookAdded(BooksBook*)));
                    connect(newShelf,
                        SIGNAL(bookRemoved(BooksBook*)),
                        SLOT(onBookRemoved(BooksBook*)));
                }
                connect(newM,
                    SIGNAL(rowsInserted(QModelIndex,int,int)),
                    SIGNAL(countChanged()));
                connect(newM,
                    SIGNAL(rowsRemoved(QModelIndex,int,int)),
                    SIGNAL(countChanged()));
                connect(newM,
                    SIGNAL(modelReset()),
                    SIGNAL(countChanged()));
            } else {
                HDEBUG("unexpected source" << aSrc);
                setSourceModel(NULL);
            }
        } else {
            setSourceModel(NULL);
        }
        if (oldCount != count()) {
            Q_EMIT countChanged();
        }
    }
}
Пример #4
0
/**
 * @brief MainWindow::setDocumentModel
 *
 * Will be called whe a new q2d::Project is created, to link the projects
 * document model with the appropriate list view in the UI.
 * @param model
 */
void
MainWindow::slot_setDocumentModel(QStandardItemModel* model) {

    // close all tabs related to the old model
    m_ui->schematicsTabWidget->clear();

    QListView* documentView = m_ui->documentListView;

    documentView->clearSelection();
    QAbstractItemModel* oldModel = documentView->model();

    m_ui->documentListView->setModel(model);

    if (oldModel != nullptr) {
        oldModel->disconnect();
        oldModel->deleteLater();
    }
}
Пример #5
0
void ChartProxyModel::removeTable(Table *table)
{
    QAbstractItemModel *model = table->model();
    model->disconnect(this);
}