Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
orderdialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
6#include "iconloader_p.h"
7#include "ui_orderdialog.h"
8
9#include <QtDesigner/qextensionmanager.h>
10#include <QtDesigner/abstractformeditor.h>
11#include <QtDesigner/container.h>
12#include <QtCore/qabstractitemmodel.h>
13#include <QtWidgets/qpushbutton.h>
14
16
17using namespace Qt::StringLiterals;
18
19// OrderDialog: Used to reorder the pages of QStackedWidget and QToolBox.
20// Provides up and down buttons as well as DnD via QAbstractItemView::InternalMove mode
21namespace qdesigner_internal {
22
27{
28 m_ui->setupUi(this);
29 m_ui->upButton->setIcon(createIconSet("up.png"_L1));
30 m_ui->downButton->setIcon(createIconSet("down.png"_L1));
33 this, &OrderDialog::slotReset);
34 // Catch the remove operation of a DnD operation in QAbstractItemView::InternalMove mode to enable buttons
35 // Selection mode is 'contiguous' to enable DnD of groups
38
43
44 m_ui->upButton->setEnabled(false);
45 m_ui->downButton->setEnabled(false);
46}
47
49{
50 delete m_ui;
51}
52
57
59{
60 // The QWidget* are stored in a map indexed by the old index.
61 // The old index is set as user data on the item instead of the QWidget*
62 // because DnD is enabled which requires the user data to serializable
64 const qsizetype count = pages.size();
65 for (qsizetype i = 0; i < count; ++i)
66 m_orderMap.insert(int(i), pages.at(i));
67 buildList();
68}
69
71{
73 for (auto it = m_orderMap.cbegin(), cend = m_orderMap.cend(); it != cend; ++it) {
75 const int index = it.key();
76 switch (m_format) {
77 case PageOrderFormat:
78 item->setText(tr("Index %1 (%2)").arg(index).arg(it.value()->objectName()));
79 break;
80 case TabOrderFormat:
81 item->setText(tr("%1 %2").arg(index+1).arg(it.value()->objectName()));
82 break;
83 }
86 }
87
88 if (m_ui->pageList->count() > 0)
90}
91
93{
94 buildList();
95}
96
98{
100 const int count = m_ui->pageList->count();
101 for (int i=0; i < count; ++i) {
102 const int oldIndex = m_ui->pageList->item(i)->data(Qt::UserRole).toInt();
104 }
105 return rc;
106}
107
109{
110 const int row = m_ui->pageList->currentRow();
111 if (row <= 0)
112 return;
113
116}
117
119{
120 const int row = m_ui->pageList->currentRow();
121 if (row == -1 || row == m_ui->pageList->count() - 1)
122 return;
123
126}
127
129{
131}
132
134{
136}
137
138void OrderDialog::enableButtons(int r)
139{
140 m_ui->upButton->setEnabled(r > 0);
141 m_ui->downButton->setEnabled(r >= 0 && r < m_ui->pageList->count() - 1);
142}
143
154
155}
156
157QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.