本文整理汇总了C++中QSortFilterProxyModel::setSortRole方法的典型用法代码示例。如果您正苦于以下问题:C++ QSortFilterProxyModel::setSortRole方法的具体用法?C++ QSortFilterProxyModel::setSortRole怎么用?C++ QSortFilterProxyModel::setSortRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSortFilterProxyModel
的用法示例。
在下文中一共展示了QSortFilterProxyModel::setSortRole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QTreeView
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false),
currentHeaderClicked(-1), searchBox(new QLineEdit(this))
{
setUniformRowHeights(true);
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
QSortFilterProxyModel *model = new QSortFilterProxyModel(this);
model->setSortRole(TreeItemDT::SORT_ROLE);
model->setFilterKeyColumn(-1); // filter all columns
setModel(model);
connect(model, SIGNAL(layoutChanged()), this, SLOT(fixMessyQtModelBehaviour()));
setSortingEnabled(false);
setContextMenuPolicy(Qt::DefaultContextMenu);
header()->setContextMenuPolicy(Qt::ActionsContextMenu);
QAction *showSearchBox = new QAction(tr("Show Search Box"), this);
showSearchBox->setShortcut( Qt::CTRL + Qt::Key_F);
showSearchBox->setShortcutContext(Qt::ApplicationShortcut);
addAction(showSearchBox);
searchBox->installEventFilter(this);
searchBox->hide();
connect(showSearchBox, SIGNAL(triggered(bool)), this, SLOT(showSearchEdit()));
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
selectedTrips.clear();
}
示例2: QDialog
SpeedLimitsDlg::SpeedLimitsDlg(bt::TorrentInterface* current, Core* core, QWidget* parent)
: QDialog(parent), core(core), current(current)
{
setupUi(this);
setWindowIcon(QIcon::fromTheme("kt-speed-limits"));
setWindowTitle(i18n("Speed Limits"));
model = new SpeedLimitsModel(core, this);
QSortFilterProxyModel* pm = new QSortFilterProxyModel(this);
pm->setSourceModel(model);
pm->setSortRole(Qt::UserRole);
m_speed_limits_view->setModel(pm);
m_speed_limits_view->setItemDelegate(new SpinBoxDelegate(this));
m_speed_limits_view->setUniformRowHeights(true);
m_speed_limits_view->setSortingEnabled(true);
m_speed_limits_view->sortByColumn(0, Qt::AscendingOrder);
m_speed_limits_view->header()->setSortIndicatorShown(true);
m_speed_limits_view->header()->setClickable(true);
m_speed_limits_view->setAlternatingRowColors(true);
QPushButton* apply_btn = m_buttonBox->button(QDialogButtonBox::Apply);
apply_btn->setEnabled(false);
connect(model, &SpeedLimitsModel::enableApply, apply_btn, &QPushButton::setEnabled);
connect(apply_btn, &QPushButton::clicked, this, &SpeedLimitsDlg::apply);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
m_upload_rate->setValue(Settings::maxUploadRate());
m_download_rate->setValue(Settings::maxDownloadRate());
connect(m_upload_rate, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)));
connect(m_download_rate, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)));
connect(m_filter, SIGNAL(textChanged(QString)), pm, SLOT(setFilterFixedString(QString)));
loadState();
// if current is specified, select it and scroll to it
if (current)
{
kt::QueueManager* qman = core->getQueueManager();
int idx = 0;
QList<bt::TorrentInterface*>::iterator itr = qman->begin();
while (itr != qman->end())
{
if (*itr == current)
break;
idx++;
itr++;
}
if (itr != qman->end())
{
QItemSelectionModel* sel = m_speed_limits_view->selectionModel();
QModelIndex midx = pm->mapFromSource(model->index(idx, 0));
QModelIndex midx2 = pm->mapFromSource(model->index(idx, 4));
sel->select(QItemSelection(midx, midx2), QItemSelectionModel::Select);
m_speed_limits_view->scrollTo(midx);
}
}
}
示例3: run_ui
void run_ui()
{
qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
QQmlApplicationEngine engine;
engine.addImportPath("qrc://imports");
DiveListModel diveListModel;
QSortFilterProxyModel *sortModel = new QSortFilterProxyModel(0);
sortModel->setSourceModel(&diveListModel);
sortModel->setDynamicSortFilter(true);
sortModel->setSortRole(DiveListModel::DiveDateRole);
sortModel->sort(0, Qt::DescendingOrder);
QQmlContext *ctxt = engine.rootContext();
ctxt->setContextProperty("diveModel", sortModel);
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
qqWindowObject = engine.rootObjects().value(0);
if (!qqWindowObject) {
fprintf(stderr, "can't create window object\n");
exit(1);
}
QQuickWindow *qml_window = qobject_cast<QQuickWindow *>(qqWindowObject);
qml_window->setIcon(QIcon(":/subsurface-mobile-icon"));
qqWindowObject->setProperty("messageText", QVariant("Subsurface mobile startup"));
#if !defined(Q_OS_ANDROID)
qml_window->setHeight(1200);
qml_window->setWidth(800);
#endif
qml_window->show();
qApp->exec();
}
示例4: QComboBox
/** Constructor */
GxsIdChooser::GxsIdChooser(QWidget *parent)
: QComboBox(parent), mFlags(IDCHOOSER_ANON_DEFAULT)
{
mBase = new RsGxsUpdateBroadcastBase(rsIdentity, this);
connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool)));
/* Initialize ui */
setSizeAdjustPolicy(QComboBox::AdjustToContents);
mFirstLoad = true;
mAllowedCount = 0 ;
mDefaultId.clear() ;
/* Enable sort with own role */
QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
proxy->setSourceModel(model());
proxy->setDynamicSortFilter(false);
model()->setParent(proxy);
setModel(proxy);
proxy->setSortRole(ROLE_SORT);
/* Connect signals */
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(myCurrentIndexChanged(int)));
connect(this, SIGNAL(activated(int)), this, SLOT(indexActivated(int)));
}
示例5: setObjectBaseName
void MethodsTab::setObjectBaseName(const QString &baseName)
{
m_objectBaseName = baseName;
auto clientModel = new ClientMethodModel(this);
clientModel->setSourceModel(ObjectBroker::model(baseName + '.' + "methods"));
QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
proxy->setDynamicSortFilter(true);
proxy->setSourceModel(clientModel);
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
proxy->setSortRole(ObjectMethodModelRole::MethodSortRole);
m_ui->methodView->setModel(proxy);
m_ui->methodView->sortByColumn(0, Qt::AscendingOrder);
m_ui->methodView->setSelectionModel(ObjectBroker::selectionModel(proxy));
m_ui->methodView->header()->setResizeMode(QHeaderView::ResizeToContents);
new SearchLineController(m_ui->methodSearchLine, proxy);
connect(m_ui->methodView, SIGNAL(doubleClicked(QModelIndex)),
SLOT(methodActivated(QModelIndex)));
connect(m_ui->methodView, SIGNAL(customContextMenuRequested(QPoint)),
SLOT(methodContextMenu(QPoint)));
m_ui->methodLog->setModel(ObjectBroker::model(baseName + '.' + "methodLog"));
m_interface = ObjectBroker::object<MethodsExtensionInterface *>(baseName + ".methodsExtension");
new PropertyBinder(m_interface, "hasObject", m_ui->methodLog, "visible");
}
示例6: QWidget
NoteBrowser::NoteBrowser(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
{
m_model = new NotesModel( this );
QSortFilterProxyModel * sortingModel = new QSortFilterProxyModel( this );
sortingModel->setSourceModel( m_model );
sortingModel->setSortRole( m_model->roleForProperty( NAO::created() ) );
sortingModel->setDynamicSortFilter( true );
sortingModel->sort( 0, Qt::DescendingOrder );
m_view = new NotesView( this );
m_view->setModel( sortingModel );
connect( m_view, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(slotNoteSelected(QModelIndex)) );
Nepomuk2::Query::ResourceTypeTerm typeTerm( Nepomuk2::Types::Class( PIMO::Note() ) );
Nepomuk2::Query::ComparisonTerm compTerm( NAO::created(), Nepomuk2::Query::Term() );
compTerm.setSortWeight( 1, Qt::DescendingOrder );
m_query = typeTerm && compTerm;
//FIXME: Figure out why this stupid layout is required!
QHBoxLayout* layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( 0 );
layout->addWidget( m_view );
}
示例7: main
int main(int argc, char *argv[])
{
qmlRegisterType<Recorder>("harbour.recorder", 1, 0, "Recorder");
qmlRegisterType<DirectoryModel>("harbour.recorder", 1, 0, "DirectoryModel");
auto app = SailfishApp::application(argc, argv);
QCoreApplication::setOrganizationName("harbour-recorder");
QCoreApplication::setOrganizationDomain("www.corne.info");
QCoreApplication::setApplicationName("Recorder");
auto view = SailfishApp::createView();
auto context = view->rootContext();
Recorder recorder;
context->setContextProperty("recorder", &recorder);
RecordingsModel sourceModel;
sourceModel.setRecorder(&recorder);
QSortFilterProxyModel recordingsModel;
recordingsModel.setSourceModel(&sourceModel);
recordingsModel.setSortRole(RecordingsModel::Modified);
recordingsModel.setDynamicSortFilter(true);
recordingsModel.sort(0, Qt::DescendingOrder);
context->setContextProperty("recordingsModel", &recordingsModel);
view->setSource(SailfishApp::pathTo("qml/harbour-recorder.qml"));
view->show();
return app->exec();
}
示例8: QWidget
MainWidget::MainWidget( MainWindow * parent ) :
QWidget( parent ), mMainWindow( parent )
{
QVBoxLayout *layout = new QVBoxLayout( this );
QSplitter *splitter = new QSplitter( Qt::Vertical, this );
layout->addWidget( splitter );
// Accounts
Akonadi::AgentInstanceModel *model = new Akonadi::AgentInstanceModel( this );
m_resourcesView = new QListView( splitter );
m_resourcesView->setModel( model );
connect( m_resourcesView, SIGNAL( clicked( const QModelIndex& ) ),
SLOT( slotCurrentResourceChanged( const QModelIndex& ) ) );
splitter->addWidget( m_resourcesView );
// Filter the collection to only show the blogs
Akonadi::AgentFilterProxyModel* proxy = new Akonadi::AgentFilterProxyModel( this );
proxy->addMimeTypeFilter( "application/x-vnd.kde.microblog" );
proxy->setSourceModel( model );
m_resourcesView->setModel( proxy );
// Bottom part
KVBox* box = new KVBox( splitter );
// Folders
m_tabBar = new AkonadiTabBar( box );
connect( m_tabBar, SIGNAL( currentChanged( const Akonadi::Collection& ) ),
SLOT( slotCurrentTabChanged( const Akonadi::Collection& ) ) );
mMessageList = new QTreeView( box );
mMessageList->setRootIsDecorated( false );
mMessageList->setDragEnabled( false );
mMessageList->setSelectionMode( QAbstractItemView::ExtendedSelection );
mMessageList->setSortingEnabled( true );
MicroblogDelegate *delegate = new MicroblogDelegate( mMessageList, this );
mMessageList->setItemDelegate( delegate );
mMessageModel = new BlogModel( this );
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel( this );
proxyModel->setSortRole( Qt::EditRole );
proxyModel->setDynamicSortFilter( true );
proxyModel->setSourceModel( mMessageModel );
mMessageList->setModel( proxyModel );
splitter->addWidget( box );
splitter->setSizes( QList<int>() << 30 << 470 );
}
示例9: SettingsPageBase
PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
SettingsPageBase(parent),
m_initialized(false),
m_listView(0),
m_enabledPreviewPlugins(),
m_remoteFileSizeBox(0)
{
QVBoxLayout* topLayout = new QVBoxLayout(this);
QLabel* showPreviewsLabel = new QLabel(i18nc("@title:group", "Show previews for:"), this);
m_listView = new QListView(this);
ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView);
connect(delegate, SIGNAL(requestServiceConfiguration(QModelIndex)),
this, SLOT(configureService(QModelIndex)));
ServiceModel* serviceModel = new ServiceModel(this);
QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(serviceModel);
proxyModel->setSortRole(Qt::DisplayRole);
m_listView->setModel(proxyModel);
m_listView->setItemDelegate(delegate);
m_listView->setVerticalScrollMode(QListView::ScrollPerPixel);
QLabel* remoteFileSizeLabel = new QLabel(i18nc("@label", "Skip previews for remote files above:"), this);
m_remoteFileSizeBox = new KIntSpinBox(this);
m_remoteFileSizeBox->setSingleStep(1);
m_remoteFileSizeBox->setSuffix(QLatin1String(" MB"));
m_remoteFileSizeBox->setRange(0, 9999999); /* MB */
QHBoxLayout* fileSizeBoxLayout = new QHBoxLayout(this);
fileSizeBoxLayout->addWidget(remoteFileSizeLabel, 0, Qt::AlignRight);
fileSizeBoxLayout->addWidget(m_remoteFileSizeBox);
topLayout->addSpacing(KDialog::spacingHint());
topLayout->addWidget(showPreviewsLabel);
topLayout->addWidget(m_listView);
topLayout->addLayout(fileSizeBoxLayout);
loadSettings();
connect(m_listView, SIGNAL(clicked(QModelIndex)), this, SIGNAL(changed()));
connect(m_remoteFileSizeBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
}
示例10: Window
IssueSelector::IssueSelector( SimpleRedmineClient* redmine, MainWindow* mainWindow )
: Window( "qrc:/IssueSelector.qml", mainWindow ),
redmine_( redmine )
{
ENTER();
// Issue selector window initialisation
setModality( Qt::ApplicationModal );
setFlags( Qt::Dialog );
setTitle( "Issue Selector" );
// Set the models
issuesProxyModel_.setSourceModel( &issuesModel_ );
issuesProxyModel_.setSortRole( IssueModel::IssueRoles::IdRole );
issuesProxyModel_.setDynamicSortFilter( true );
issuesProxyModel_.setFilterCaseSensitivity( Qt::CaseInsensitive );
issuesProxyModel_.setFilterRole( IssueModel::IssueRoles::SubjectRole );
ctx_->setContextProperty( "issuesModel", &issuesProxyModel_ );
QSortFilterProxyModel* projectProxyModel = new QSortFilterProxyModel( this );
projectProxyModel->setSourceModel( &projectModel_ );
projectProxyModel->setSortRole( SimpleModel::SimpleRoles::IdRole );
projectProxyModel->setDynamicSortFilter( true );
ctx_->setContextProperty( "projectModel", projectProxyModel );
// Connect the project selected signal to the projectSelected slot
connect( qml("project"), SIGNAL(activated(int)), this, SLOT(projectSelected(int)) );
// Connect the issue selected signal to the issueSelected slot
connect( qml("issues"), SIGNAL(activated(int)), this, SLOT(issueSelected(int)) );
// Connect the search accepted signal to the filterIssues slot
connect( qml("search"), SIGNAL(textChanged()), this, SLOT(filterIssues()) );
// Connect the closed signal to the close slot
connect( this, &Window::closed, [=](){ close(); } );
RETURN();
}
示例11: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
BookModel bookModel;
QSortFilterProxyModel proxy;
proxy.setSourceModel(&bookModel);
proxy.setFilterRole(BookModel::NameRole);
proxy.setFilterCaseSensitivity(Qt::CaseInsensitive);
proxy.setSortRole(BookModel::NameRole);
proxy.setDynamicSortFilter(true);
proxy.sort(0);
QDeclarativeView view;
view.rootContext()->setContextProperty("bookModel", &proxy);
view.setSource(QUrl::fromLocalFile("main.qml"));
view.show();
return app.exec();
}
示例12: slotPresetLoaded
void DlgPrefController::slotPresetLoaded(ControllerPresetPointer preset) {
m_ui.labelLoadedPreset->setText(presetName(preset));
m_ui.labelLoadedPresetDescription->setText(presetDescription(preset));
m_ui.labelLoadedPresetAuthor->setText(presetAuthor(preset));
QStringList supportLinks;
QString forumLink = presetForumLink(preset);
if (forumLink.length() > 0) {
supportLinks << forumLink;
}
QString wikiLink = presetWikiLink(preset);
if (wikiLink.length() > 0) {
supportLinks << wikiLink;
}
// There is always at least one support link.
// TODO(rryan): This is a horrible general support link for MIDI!
QString troubleShooting = QString(
"<a href=\"http://mixxx.org/wiki/doku.php/midi_scripting\">%1</a>")
.arg(tr("Troubleshooting"));
supportLinks << troubleShooting;
QString support = supportLinks.join(" ");
m_ui.labelLoadedPresetSupportLinks->setText(support);
// We mutate this preset so keep a reference to it while we are using it.
// TODO(rryan): Clone it? Technically a waste since nothing else uses this
// copy but if someone did they might not expect it to change.
m_pPreset = preset;
ControllerInputMappingTableModel* pInputModel =
new ControllerInputMappingTableModel(this);
// If the model reports changes, mark ourselves as dirty.
connect(pInputModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SLOT(slotDirty()));
connect(pInputModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
this, SLOT(slotDirty()));
connect(pInputModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
this, SLOT(slotDirty()));
pInputModel->setPreset(preset);
QSortFilterProxyModel* pInputProxyModel = new QSortFilterProxyModel(this);
pInputProxyModel->setSortRole(Qt::UserRole);
pInputProxyModel->setSourceModel(pInputModel);
m_ui.m_pInputMappingTableView->setModel(pInputProxyModel);
for (int i = 0; i < pInputModel->columnCount(); ++i) {
QAbstractItemDelegate* pDelegate = pInputModel->delegateForColumn(
i, m_ui.m_pInputMappingTableView);
if (pDelegate != NULL) {
qDebug() << "Setting input delegate for column" << i << pDelegate;
m_ui.m_pInputMappingTableView->setItemDelegateForColumn(i, pDelegate);
}
}
// Now that we have set the new model our old model can be deleted.
delete m_pInputProxyModel;
m_pInputProxyModel = pInputProxyModel;
delete m_pInputTableModel;
m_pInputTableModel = pInputModel;
ControllerOutputMappingTableModel* pOutputModel =
new ControllerOutputMappingTableModel(this);
pOutputModel->setPreset(preset);
QSortFilterProxyModel* pOutputProxyModel = new QSortFilterProxyModel(this);
pOutputProxyModel->setSortRole(Qt::UserRole);
pOutputProxyModel->setSourceModel(pOutputModel);
m_ui.m_pOutputMappingTableView->setModel(pOutputProxyModel);
for (int i = 0; i < pOutputModel->columnCount(); ++i) {
QAbstractItemDelegate* pDelegate = pOutputModel->delegateForColumn(
i, m_ui.m_pOutputMappingTableView);
if (pDelegate != NULL) {
qDebug() << "Setting output delegate for column" << i << pDelegate;
m_ui.m_pOutputMappingTableView->setItemDelegateForColumn(i, pDelegate);
}
}
// Now that we have set the new model our old model can be deleted.
delete m_pOutputProxyModel;
m_pOutputProxyModel = pOutputProxyModel;
delete m_pOutputTableModel;
m_pOutputTableModel = pOutputModel;
// Populate the script tab with the scripts this preset uses.
m_ui.m_pScriptsTableWidget->setRowCount(preset->scripts.length());
m_ui.m_pScriptsTableWidget->setColumnCount(3);
m_ui.m_pScriptsTableWidget->setHorizontalHeaderItem(
0, new QTableWidgetItem(tr("Filename")));
m_ui.m_pScriptsTableWidget->setHorizontalHeaderItem(
1, new QTableWidgetItem(tr("Function Prefix")));
m_ui.m_pScriptsTableWidget->setHorizontalHeaderItem(
2, new QTableWidgetItem(tr("Built-in")));
m_ui.m_pScriptsTableWidget->horizontalHeader()
->setResizeMode(QHeaderView::Stretch);
for (int i = 0; i < preset->scripts.length(); ++i) {
const ControllerPreset::ScriptFileInfo& script = preset->scripts.at(i);
//.........这里部分代码省略.........
示例13: createLayout
void IntroPage::createLayout()
{
QSortFilterProxyModel * mdl = new QSortFilterProxyModel;
mdl->setDynamicSortFilter(true);
mdl->setSourceModel(new UDevSerialPortModel);
mdl->setSortRole(Qt::DisplayRole);
mdl->setSortCaseSensitivity(Qt::CaseInsensitive);
mdl->sort(0, Qt::AscendingOrder);
m_cbxType = new WizardComboBox();
QLabel * lblType = new QLabel(tr("Dive Computer &Driver:"));
lblType->setBuddy(m_cbxType);
m_cbxModel = new WizardComboBox();
m_lblModel = new QLabel(tr("Dive Computer &Model:"));
m_lblModel->setBuddy(m_cbxModel);
m_cbxDevice = new WizardComboBox();
m_cbxDevice->setModel(mdl);
m_lblDevice = new QLabel(tr("&Serial Port:"));
m_lblDevice->setBuddy(m_cbxDevice);
m_txtParams = new QLineEdit(this);
m_txtParams->setHidden(true);
m_txtSerial = new QLineEdit(this);
m_txtSerial->setHidden(true);
m_txtManuf = new QLineEdit(this);
m_txtManuf->setHidden(true);
m_txtModel = new QLineEdit(this);
m_txtModel->setHidden(true);
QPushButton * btnParams = new QPushButton(tr("Configure Connection"));
btnParams->setToolTip(tr("Edit Driver Arguments"));
connect(btnParams, SIGNAL(clicked()), this, SLOT(btnParamsClicked()));
std::list<plugin_manifest_t>::const_iterator it;
for (it = m_registry->plugins().begin(); it != m_registry->plugins().end(); it++)
{
std::list<driver_manifest_t>::const_iterator itd;
for (itd = it->plugin_drivers.begin(); itd != it->plugin_drivers.end(); itd++)
m_cbxType->addItem(QString::fromStdString(itd->driver_desc), QVariant(QString::fromStdString(itd->driver_name)));
}
updateModels(0);
connect(m_cbxType, SIGNAL(currentIndexChanged(int)), this, SLOT(updateModels(int)));
QGridLayout * gbox = new QGridLayout();
gbox->addWidget(lblType, 0, 0);
gbox->addWidget(m_cbxType, 0, 1);
gbox->addWidget(m_lblModel, 1, 0);
gbox->addWidget(m_cbxModel, 1, 1);
gbox->addWidget(m_lblDevice, 2, 0);
gbox->addWidget(m_cbxDevice, 2, 1);
gbox->setColumnStretch(1, 1);
QHBoxLayout * hbox = new QHBoxLayout();
hbox->addStretch();
hbox->addWidget(btnParams);
QVBoxLayout * vbox = new QVBoxLayout();
vbox->addLayout(gbox);
vbox->addStretch();
vbox->addLayout(hbox);
setLayout(vbox);
}
示例14: fm
AnimalMovesWindow::AnimalMovesWindow(const std::map<QString, std::shared_ptr<db::Database>> & map, db::Database & db, const Animal & animal, QWidget * parent) :
QWidget(),
ui(new Ui::AnimalMovesWindow),
m_parent(parent),
m_db(db),
m_dbMap(map),
m_animal(animal)
{
ui->setupUi(this);
ui->label_Name->setText(m_animal.getName());
QStringList horizontalHeader;
horizontalHeader.append("Level");
horizontalHeader.append("Move");
horizontalHeader.append("Type");
horizontalHeader.append("Category");
horizontalHeader.append("Dmg");
horizontalHeader.append("Acc");
horizontalHeader.append("Prio");
m_movesModel.setHorizontalHeaderLabels(horizontalHeader);
ComboBoxDelegate * delegate = new ComboBoxDelegate(this);
std::vector<QString> vec;
for (const auto & move : m_db.getMovesByID()) {
vec.emplace_back(move.second.getName());
}
delegate->setItems(vec);
ui->tableView_Moves->setItemDelegateForColumn(1, delegate);
QSortFilterProxyModel * proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(&m_movesModel);
proxyModel->setSortRole(NumericModel::SortRole);
ui->tableView_Moves->setModel(proxyModel);
ui->tableView_Moves->resizeColumnsToContents();
ui->tableView_Moves->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
// calculate max move name size
int size = 20;
QFont font;
QFontMetrics fm(font);
for (const auto & move : m_db.getMoves()) {
size = std::max(size, fm.width(move.first));
}
ui->tableView_Moves->horizontalHeader()->resizeSection(1, size + 30);
// calculate max type name size
size = 20;
for (const auto & type : m_db.getTypes()) {
size = std::max(size, fm.width(type.first));
}
ui->tableView_Moves->horizontalHeader()->resizeSection(2, size + 30);
// fill moves
for (const auto & p : m_animal.moves()) {
assert(m_db.getMoves().count(p.second) != 0);
const auto move = m_db.getMoves().at(p.second);
QList<QStandardItem *> itemList;
itemList.append(new QStandardItem(QString::number(p.first)));
itemList.append(new QStandardItem(move.getName()));
itemList.append(new QStandardItem(move.getType()));
itemList.back()->setEditable(false);
itemList.append(new QStandardItem(move.getCategory()));
itemList.back()->setEditable(false);
itemList.append(new QStandardItem(QString::number(move.getBaseDamage())));
itemList.back()->setEditable(false);
itemList.append(new QStandardItem(QString::number(move.getAccuracy())));
itemList.back()->setEditable(false);
itemList.append(new QStandardItem(QString::number(move.getPriority())));
itemList.back()->setEditable(false);
m_movesModel.appendRow(itemList);
}
connect(&m_movesModel, &QStandardItemModel::itemChanged, [&](QStandardItem * item){
const auto col = item->column();
if (col == 0) {
// lvl changed
ui->tableView_Moves->sortByColumn(0, Qt::AscendingOrder);
} else if (col == 1) {
// move changed
const auto move = m_db.getMoves().at(item->text());
m_movesModel.setItem(item->row(), 2, new QStandardItem(move.getType()));
m_movesModel.setItem(item->row(), 3, new QStandardItem(move.getCategory()));
m_movesModel.setItem(item->row(), 4, new QStandardItem(QString::number(move.getBaseDamage())));
m_movesModel.setItem(item->row(), 5, new QStandardItem(QString::number(move.getAccuracy())));
m_movesModel.setItem(item->row(), 6, new QStandardItem(QString::number(move.getPriority())));
}
//.........这里部分代码省略.........
示例15: run_ui
void run_ui()
{
#ifdef SUBSURFACE_MOBILE
QQmlApplicationEngine engine;
register_qml_types(&engine);
LOG_STP("run_ui qml engine started");
KirigamiPlugin::getInstance().registerTypes();
#if defined(__APPLE__) && !defined(Q_OS_IOS)
// when running the QML UI on a Mac the deployment of the QML Components seems
// to fail and the search path for the components is rather odd - simply the
// same directory the executable was started from <bundle>/Contents/MacOS/
// To work around this we need to manually copy the components at install time
// to Contents/Frameworks/qml and make sure that we add the correct import path
const QStringList importPathList = engine.importPathList();
for (QString importPath: importPathList) {
if (importPath.contains("MacOS"))
engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
}
qDebug() << "QML import path" << engine.importPathList();
#endif // __APPLE__ not Q_OS_IOS
engine.addImportPath("qrc://imports");
DiveListModel diveListModel;
LOG_STP("run_ui diveListModel started");
DiveListSortModel *sortModel = new DiveListSortModel(0);
sortModel->setSourceModel(&diveListModel);
sortModel->setDynamicSortFilter(true);
sortModel->setSortRole(DiveListModel::DiveDateRole);
sortModel->sort(0, Qt::DescendingOrder);
LOG_STP("run_ui diveListModel sorted");
GpsListModel gpsListModel;
QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(0);
gpsSortModel->setSourceModel(&gpsListModel);
gpsSortModel->setDynamicSortFilter(true);
gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
gpsSortModel->sort(0, Qt::DescendingOrder);
QQmlContext *ctxt = engine.rootContext();
ctxt->setContextProperty("diveModel", sortModel);
ctxt->setContextProperty("gpsModel", gpsSortModel);
ctxt->setContextProperty("vendorList", vendorList);
set_non_bt_addresses();
LOG_STP("run_ui set_non_bt_adresses");
ctxt->setContextProperty("connectionListModel", &connectionListModel);
ctxt->setContextProperty("logModel", MessageHandlerModel::self());
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
LOG_STP("run_ui qml loaded");
qqWindowObject = engine.rootObjects().value(0);
if (!qqWindowObject) {
fprintf(stderr, "can't create window object\n");
exit(1);
}
QQuickWindow *qml_window = qobject_cast<QQuickWindow *>(qqWindowObject);
qml_window->setIcon(QIcon(":subsurface-mobile-icon"));
qDebug() << "qqwindow devicePixelRatio" << qml_window->devicePixelRatio() << qml_window->screen()->devicePixelRatio();
QScreen *screen = qml_window->screen();
QObject::connect(qml_window, &QQuickWindow::screenChanged, QMLManager::instance(), &QMLManager::screenChanged);
QMLManager *manager = QMLManager::instance();
LOG_STP("run_ui qmlmanager instance started");
// now that the log file is initialized...
show_computer_list();
LOG_STP("run_ui show_computer_list");
manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
manager->dlSortModel = sortModel;
manager->qmlWindow = qqWindowObject;
manager->screenChanged(screen);
qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
qml_window->setHeight(1200);
qml_window->setWidth(800);
#endif // not Q_OS_ANDROID and not Q_OS_IOS
qml_window->show();
LOG_STP("run_ui running exec");
#else
MainWindow::instance()->show();
#endif // SUBSURFACE_MOBILE
qApp->exec();
}