⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertyselectorview.cpp

📁 压缩包里有教材<<C++模式设计-基于QT4开源跨平台开发框架>>所有源码
💻 CPP
字号:
#include "propertyselectorview.h"#include "propertyselectormodel.h"#include <QAbstractListModel>#include <QWidget>#include <QListView>#include <QToolBar>#include <QAction>#include <QActionGroup>#include <QObject>#include <QSize>#include <QDebug>//start id=constructorPropertySelectorView::PropertySelectorView(QAbstractListModel* model, QWidget* parent) :QMainWindow(parent) {    m_ListView = new QListView(this);    setCentralWidget(m_ListView);    PropertySelectorModel* chdmodel(qobject_cast<PropertySelectorModel*>(model));    m_ListView->setModel(chdmodel);    m_ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);    m_ListView->setSelectionBehavior(QAbstractItemView::SelectRows);    QToolBar* toolbar = new QToolBar("Actions", this);    m_ActionGroup = new QActionGroup(this);    m_ApplyAction = addChoice("Apply", "Apply Changes");    m_CancelAction = addChoice("Cancel", "Cancel Changes");     toolbar->addActions(m_ActionGroup->actions());    QMainWindow::addToolBar(Qt::TopToolBarArea, toolbar);    connect(m_CancelAction, SIGNAL(triggered(bool)),                      this, SLOT(closeWindow(bool)));    connect(m_ApplyAction, SIGNAL(triggered(bool)),                      this, SLOT(sendSelects(bool)));}//end/** After the user has selected headers, this method obtains a list of indexesof the selected items and uses a signal to send that list to the model.*///start id=selectsvoid PropertySelectorView::sendSelects(bool) {    QItemSelectionModel* selectModel = m_ListView->selectionModel();    QModelIndexList selects = selectModel->selectedIndexes();    emit selectionsMade(selects);}//endvoid PropertySelectorView::closeWindow(bool) {    setVisible(false);}/** This method consists of factored out code for creating actions*/QAction* PropertySelectorView::addChoice(QString name, QString text) {    QAction* retval = new QAction(text, this);    retval->setObjectName(name);    retval->setEnabled(true);    m_ActionGroup->addAction(retval);    return retval;}/** This slot is called prior to the restoration of visibility of the view. Itis invoked by a signal in the model which transmits the list of indexes ofselected items so that the most recently applied selects can be seen.*/void PropertySelectorView::restoreSelects(QList<QPersistentModelIndex> selects) {    QItemSelectionModel* selectModel = m_ListView->selectionModel();    foreach(QPersistentModelIndex indx, selects)         selectModel->select(indx, QItemSelectionModel::Select);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -