void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editable) { m_outlineCombo = new QComboBox; m_outlineCombo->setMinimumContentsLength(22); // ### m_outlineCombo->setModel(m_outlineModel); QTreeView *treeView = new QTreeView; treeView->header()->hide(); treeView->setItemsExpandable(false); treeView->setRootIsDecorated(false); m_outlineCombo->setView(treeView); treeView->expandAll(); //m_outlineCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); // Make the combo box prefer to expand QSizePolicy policy = m_outlineCombo->sizePolicy(); policy.setHorizontalPolicy(QSizePolicy::Expanding); m_outlineCombo->setSizePolicy(policy); QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar()); QList<QAction*> actions = toolBar->actions(); toolBar->insertWidget(actions.first(), m_outlineCombo); }
AddBookmarkDialog::AddBookmarkDialog(const QString &url, const QString &title, QWidget *parent, BookmarksManager *bookmarkManager) : QDialog(parent) , m_url(url) , m_bookmarksManager(bookmarkManager) { setWindowFlags(Qt::Sheet); if (!m_bookmarksManager) m_bookmarksManager = BrowserApplication::bookmarksManager(); setupUi(this); QTreeView *view = new QTreeView(this); m_proxyModel = new AddBookmarkProxyModel(this); BookmarksModel *model = m_bookmarksManager->bookmarksModel(); m_proxyModel->setSourceModel(model); view->setModel(m_proxyModel); view->expandAll(); view->header()->setStretchLastSection(true); view->header()->hide(); view->setItemsExpandable(false); view->setRootIsDecorated(false); view->setIndentation(10); location->setModel(m_proxyModel); view->show(); location->setView(view); BookmarkNode *menu = m_bookmarksManager->menu(); QModelIndex idx = m_proxyModel->mapFromSource(model->index(menu)); view->setCurrentIndex(idx); location->setCurrentIndex(idx.row()); name->setText(title); }
void BookmarkPropertiesDialog::reloadFolders() { m_model->clear(); QStandardItem *item = new QStandardItem(Utils::getIcon(QLatin1String("inode-directory")), tr("Bookmarks")); item->setData(0, Qt::UserRole); item->setToolTip(tr("Bookmarks")); m_model->invisibleRootItem()->appendRow(item); m_index = item->index(); populateFolder(BookmarksManager::getFolder(0), item); QTreeView *view = qobject_cast<QTreeView*>(m_ui->folderComboBox->view()); if (view) { view->setCurrentIndex(m_index); view->expandAll(); m_ui->folderComboBox->setRootModelIndex(m_index.parent()); m_ui->folderComboBox->setModelColumn(0); m_ui->folderComboBox->setCurrentIndex(m_index.row()); m_ui->folderComboBox->setRootModelIndex(QModelIndex()); } }
TreeView::TreeView() : QWidget() { if (! this->createConnection() ) { QString msg = "** Create Database Error"; throw msg; } setWindowTitle(tr("Tree View Model")); setMinimumSize(200, 350); QTreeView *treeView = new QTreeView(); QStandardItemModel *model = new QStandardItemModel(); // get sql data QList<struCat> itemList; itemList = getData(); // sort the qlist data qSort(itemList.begin(), itemList.end(), sortMe); // put qlist data in the tree QList<struCat>::iterator nK; QStandardItem *parentItem = model->invisibleRootItem(); QStandardItem *lastParent = NULL; for (nK = itemList.begin(); nK != itemList.end(); ++nK) { QStandardItem *item = new QStandardItem; item->setText(nK->catName); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable ); if ( nK->catParent == 0 ) { parentItem->appendRow(item); // save this lastParent = item; } else { lastParent->appendRow(item); } } model->setHeaderData(0, Qt::Horizontal, QObject::tr("Food Categories")); model->sort(0); treeView->setModel(model); treeView->expandAll(); // QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(treeView); setLayout(mainLayout); }
void SatellitesConfigDialog::expandTreeView() { QTreeView *treeView = m_configWidget->treeView; if( !treeView->model() ) { return; } // expand only branches with selected items treeView->expandAll(); for ( int i = 0; i < treeView->model()->columnCount(); ++i ) { treeView->resizeColumnToContents( i ); } }
QDialog *PluginManager::createAboutPluginDialog(QWidget *parent) { QDialog *rc = new QDialog(parent); rc->setWindowFlags(rc->windowFlags() & ~Qt::WindowContextHelpButtonHint & Qt::Sheet); rc->setWindowTitle(QCoreApplication::translate("QmlDesigner::PluginManager", "About Plugins")); QTreeView *treeView = new QTreeView; treeView->setModel(createModel(treeView)); treeView->expandAll(); QVBoxLayout *layout = new QVBoxLayout(rc); layout->addWidget(treeView); QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); layout->addWidget(bb); QObject::connect(bb, SIGNAL(rejected()), rc, SLOT(reject())); return rc; }
void NavigatorView::modelAttached(Model *model) { QmlModelView::modelAttached(model); m_treeModel->setView(this); QTreeView *treeView = treeWidget(); treeView->expandAll(); treeView->header()->setResizeMode(0, QHeaderView::Stretch); treeView->header()->resizeSection(1,26); treeView->setRootIsDecorated(false); treeView->setIndentation(20); #ifdef _LOCK_ITEMS_ treeView->header()->resizeSection(2,20); #endif }
void QmlJSTextEditorWidget::updateOutlineNow() { if (!m_semanticInfo.document) return; if (m_semanticInfo.document->editorRevision() != editorRevision()) { m_updateOutlineTimer->start(); return; } m_outlineModel->update(m_semanticInfo); QTreeView *treeView = static_cast<QTreeView*>(m_outlineCombo->view()); treeView->expandAll(); updateOutlineIndexNow(); }
int main(int argc, char** argv) { QApplication app(argc, argv); QGroupBox* subGroup = new QGroupBox("Single models"); QVBoxLayout* subLayout = new QVBoxLayout; subGroup->setLayout(subLayout); QGroupBox* mainGroup = new QGroupBox("Main model"); QVBoxLayout* mainLayout = new QVBoxLayout; mainGroup->setLayout(mainLayout); MySubView* v1 = new MySubView("Foo"); subLayout->addWidget(v1); MySubView* v2 = new MySubView("Bar"); subLayout->addWidget(v2); MySubView* v3 = new MySubView("Baz"); subLayout->addWidget(v3); Utils::ModelListModel* mainModel = new Utils::ModelListModel; mainModel->addSubModel("Foo model", v1->model()); mainModel->addSubModel("Bar model", v2->model()); mainModel->addSubModel("Baz model", v3->model()); QTreeView* mainView = new QTreeView; mainView->setModel(mainModel); mainView->expandAll(); mainLayout->addWidget(mainView); QWidget container; QHBoxLayout* containerLayout = new QHBoxLayout; container.setLayout(containerLayout); containerLayout->addWidget(subGroup); containerLayout->addWidget(mainGroup); containerLayout->setMargin(0); container.show(); return app.exec(); }
void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editor) { m_outlineCombo = new QComboBox; m_outlineCombo->setMinimumContentsLength(22); // ### m_outlineCombo->setModel(m_outlineModel); QTreeView *treeView = new QTreeView; treeView->header()->hide(); treeView->setItemsExpandable(false); treeView->setRootIsDecorated(false); m_outlineCombo->setView(treeView); treeView->expandAll(); //m_outlineCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); // Make the combo box prefer to expand QSizePolicy policy = m_outlineCombo->sizePolicy(); policy.setHorizontalPolicy(QSizePolicy::Expanding); m_outlineCombo->setSizePolicy(policy); editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo); }
LuaEditorWidget::LuaEditorWidget() : m_outlineCombo(new QComboBox) { m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); m_updateDocumentTimer.setSingleShot(true); connect(&m_updateDocumentTimer, QTimer::timeout, this, LuaEditorWidget::updateDocument); connect(this, QPlainTextEdit::textChanged, [this](){m_updateDocumentTimer.start();}); m_outlineCombo->setMinimumContentsLength(22); QTreeView* treeView = new QTreeView; treeView->header()->hide(); treeView->setItemsExpandable(false); treeView->setRootIsDecorated(false); m_outlineCombo->setView(treeView); treeView->expandAll(); QSizePolicy policy = m_outlineCombo->sizePolicy(); policy.setHorizontalPolicy(QSizePolicy::Expanding); m_outlineCombo->setSizePolicy(policy); insertExtraToolBarWidget(TextEditorWidget::Left, m_outlineCombo); }
SelectionProxyWidget::SelectionProxyWidget(QWidget *parent): QWidget(parent) { QHBoxLayout *layout = new QHBoxLayout(this); QSplitter *splitter = new QSplitter(this); layout->addWidget(splitter); m_rootModel = new DynamicTreeModel(this); DynamicTreeWidget *dynTreeWidget = new DynamicTreeWidget(m_rootModel, splitter); dynTreeWidget->setInitialTree( QLatin1String("- 1" "- 2" "- - 3" "- - 3" "- - - 4" "- - - 4" "- - - - 4" "- - 4" "- - 5" "- - - 4" "- - - - 4" "- - 5" "- 6" "- 7" "- - 8" "- - - 9" "- - - 10" "- - - - 9" "- - - - - 10" "- - - - - - 9" "- - - - - - 10" "- - - - - - - 9" "- - - - - - - - 10" "- - - - - - - - 9" "- - - - - - - 10" "- - - - - 9" "- - - - - 9" "- - - - - 9" "- - - - - 10" "- - - - - - 9" "- - - - - - 10" "- - - - - 9" "- - - - - 9" "- - - - - 9" "- - - - - 10" "- - - - - - 9" "- - - - - - 10" "- - - - 10" "- - 11" "- - 12" "- 13" "- 14" "- 15" "- - 16" "- - - 17" "- - - 18" "- 19" "- 20" "- 21")); QTreeView *selectionTree = createLabelledView(QStringLiteral("Selection"), splitter); selectionTree->setSelectionMode(QAbstractItemView::ExtendedSelection); selectionTree->setModel(m_rootModel); selectionTree->expandAll(); #define SUBTREES #define SUBTREEROOTS #define SUBTREESWITHOUTROOTS #define EXACTSELECTION #define CHILDRENOFEXACTSELECTION #ifdef SUBTREES KSelectionProxyModel *selectedBranchesModel = new KSelectionProxyModel(selectionTree->selectionModel(), this); selectedBranchesModel->setSourceModel(m_rootModel); selectedBranchesModel->setFilterBehavior(KSelectionProxyModel::SubTrees); QTreeView *selectedBranchesView = createLabelledView(QStringLiteral("SubTrees"), splitter); selectedBranchesView->setModel(selectedBranchesModel); #endif #ifdef SUBTREEROOTS KSelectionProxyModel *selectedBranchesRootsModel = new KSelectionProxyModel(selectionTree->selectionModel(), this); selectedBranchesRootsModel->setSourceModel(m_rootModel); selectedBranchesRootsModel->setFilterBehavior(KSelectionProxyModel::SubTreeRoots); QTreeView *selectedBranchesRootsView = createLabelledView(QStringLiteral("SubTreeRoots"), splitter); selectedBranchesRootsView->setModel(selectedBranchesRootsModel); #endif #ifdef SUBTREESWITHOUTROOTS KSelectionProxyModel *selectedBranchesChildrenModel = new KSelectionProxyModel(selectionTree->selectionModel(), this); selectedBranchesChildrenModel->setSourceModel(m_rootModel); selectedBranchesChildrenModel->setFilterBehavior(KSelectionProxyModel::SubTreesWithoutRoots); QTreeView *selectedBranchesChildrenView = createLabelledView(QStringLiteral("SubTreesWithoutRoots"), splitter); selectedBranchesChildrenView->setModel(selectedBranchesChildrenModel); #endif #ifdef EXACTSELECTION KSelectionProxyModel *onlySelectedModel = new KSelectionProxyModel(selectionTree->selectionModel(), this); onlySelectedModel->setSourceModel(m_rootModel); onlySelectedModel->setFilterBehavior(KSelectionProxyModel::ExactSelection); QTreeView *onlySelectedView = createLabelledView(QStringLiteral("ExactSelection"), splitter); onlySelectedView->setModel(onlySelectedModel); #endif #ifdef CHILDRENOFEXACTSELECTION KSelectionProxyModel *onlySelectedChildrenModel = new KSelectionProxyModel(selectionTree->selectionModel(), this); onlySelectedChildrenModel->setSourceModel(m_rootModel); onlySelectedChildrenModel->setFilterBehavior(KSelectionProxyModel::ChildrenOfExactSelection); QTreeView *onlySelectedChildrenView = createLabelledView(QStringLiteral("ChildrenOfExactSelection"), splitter); onlySelectedChildrenView->setModel(onlySelectedChildrenModel); #endif }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget * main_wg = new QWidget; // cria um objeto "splitter" para compartilhar widgets: QSplitter *splitter = new QSplitter(main_wg); // cria um "model" usando o "StandardModel" QStandardItemModel *model = new QStandardItemModel; const int totCols = 3; int col; // define os títulos das colunas: for (col = 0; col < totCols; ++col) { model->setHorizontalHeaderItem(col, new QStandardItem( QString("COL-%1").arg(col+1) ) ); } // alimenta linhas, colunas e sub-níveis: QStandardItem *parentItem = model->invisibleRootItem(); const int iniLevel = 0; const int totLevels= 3; QString prevRows(""); QVector<QSize> vec_ColsRows; // colunas, linhas de cada nível vec_ColsRows.reserve( totLevels ); // quantidade-colunas, quantidade-linhas vec_ColsRows << QSize(3,10) << QSize(3,3) << QSize(3,2) ; populate_model ( parentItem, vec_ColsRows, iniLevel, prevRows); // Neste exemplo, // O "model" foi alimentado com linhas, colunas e sub-níveis: // E serão criadas 4 "views" (uma "tree", uma "table", uma "list" e uma "comboBox") // relacionadas ao mesmo "model"; // Cada "view" exibe os dados de uma determinada maneira; // 1- ==== a primeira "view" é uma "tree": QTreeView *tree = new QTreeView(splitter); tree->setModel(model); // habilita classificação na tree: tree->setSortingEnabled(true); // classifica tree->sortByColumn(0); // expande toda a árvore: tree->expandAll(); // força largura de todas as colunas // para exibição completa do texto dos seus itens for (col = 0; col < totCols; ++col) tree->resizeColumnToContents(col); // configura o header para permitir mudança na ordem de classificacão: QHeaderView * hdrTree = tree->header(); hdrTree->setClickable (true); hdrTree->setSortIndicator(0,Qt::AscendingOrder); hdrTree->setSortIndicatorShown(true); hdrTree->setMovable(true); // permite mover colunas do header // 2- ==== a segunda "view" é uma "table" QTableView *table = new QTableView(splitter); table->setModel(model); table->setAlternatingRowColors(true); // habilita classificação na table: table->setSortingEnabled(true); // classifica table->sortByColumn(0); // configura o header para permitir mudança na ordem de classificacão: QHeaderView * hdrTable = table->horizontalHeader(); hdrTable->setClickable (true); hdrTable->setSortIndicator(0,Qt::AscendingOrder); hdrTable->setSortIndicatorShown(true); hdrTable->setMovable(true); // permite mover colunas do header // 3- ==== a terceira view é uma "list": QListView *list = new QListView(splitter); list->setModel(model); // 4- ==== a quarta "view" é uma "comboBox" QComboBox *combo = new QComboBox; combo->setModel(model); // configura a "splitter" definindo a largura de cada "view" int width = 800; QList< int > cols; cols << int(width* 0.45) << int(width*0.45) << int(width*0.1); splitter->setSizes(cols); // layout para agrupar a "combo" e a "splitter": QGridLayout * glayMain = new QGridLayout; main_wg->setLayout( glayMain); glayMain->addWidget( combo, 0, 1); // linha 0, coluna 0; glayMain->setRowMinimumHeight(1, glayMain->verticalSpacing() * 4); // linha 1: linha de separação glayMain->addWidget( splitter, 2, 0, 1, 3 ); // linha 2, coluna 0, rowSpan 1, colSpan 3 main_wg->setWindowTitle("06_standard - 4 'views' usando o mesmo 'model' (StandardModel) - recursivo"); main_wg->resize(800,500); main_wg->show(); return app.exec(); }