Krita Source Code Documentation
Loading...
Searching...
No Matches
KisOptionCollectionWidget::Private Struct Reference

Public Member Functions

void adjustSeparators ()
 
bool containsWidget (QStringRef id) const
 
QWidget * findWidget (QStringRef path, QWidget *candidate=nullptr) const
 
void insertWidget (int index, const QString &id, QWidget *widget)
 
 Private (KisOptionCollectionWidget *q)
 
QWidget * widget (int index) const
 
QWidget * widget (QStringRef id) const
 
int widgetIndexFromId (QStringRef id) const
 

Public Attributes

Qt::Orientation orientation {Qt::Vertical}
 
KisOptionCollectionWidgetq {nullptr}
 
bool showSeparators {false}
 
int widgetsMargin {10}
 
QVector< KisOptionCollectionWidgetWrapper * > widgetWrappers
 

Detailed Description

Definition at line 193 of file KisOptionCollectionWidget.cpp.

Constructor & Destructor Documentation

◆ Private()

KisOptionCollectionWidget::Private::Private ( KisOptionCollectionWidget * q)
inline

Definition at line 201 of file KisOptionCollectionWidget.cpp.

201: q(q) {}

Member Function Documentation

◆ adjustSeparators()

void KisOptionCollectionWidget::Private::adjustSeparators ( )
inline

Definition at line 228 of file KisOptionCollectionWidget.cpp.

229 {
230 if (q->layout()->count() == 0) {
231 return;
232 }
233 for (int i = 0; i < q->layout()->count() - 1; ++i) {
234 KisOptionCollectionWidgetWrapper *widgetWrapper =
235 qobject_cast<KisOptionCollectionWidgetWrapper*>(q->layout()->itemAt(i)->widget());
236 widgetWrapper->setSeparatorVisible(showSeparators);
237 }
238 KisOptionCollectionWidgetWrapper *lastWidgetWrapper =
239 qobject_cast<KisOptionCollectionWidgetWrapper*>(q->layout()->itemAt(q->layout()->count() - 1)->widget());
240 lastWidgetWrapper->setSeparatorVisible(false);
241 }
QWidget * widget(int index) const
Get the widget that is at the given position.

References q, KisOptionCollectionWidgetWrapper::setSeparatorVisible(), showSeparators, and KisOptionCollectionWidget::widget().

◆ containsWidget()

bool KisOptionCollectionWidget::Private::containsWidget ( QStringRef id) const
inline

Definition at line 253 of file KisOptionCollectionWidget.cpp.

254 {
255 return widgetIndexFromId(id) != -1;
256 }

References widgetIndexFromId().

◆ findWidget()

QWidget * KisOptionCollectionWidget::Private::findWidget ( QStringRef path,
QWidget * candidate = nullptr ) const
inline

Definition at line 268 of file KisOptionCollectionWidget.cpp.

269 {
270 while (path.startsWith('/')) {
271 path = path.right(path.size() - 1);
272 }
273 if (path.isEmpty()) {
274 return candidate;
275 }
276 const int slashPosition = path.indexOf('/');
277 if (slashPosition == -1) {
278 return widget(path);
279 }
280 QWidget *nextCandidate = widget(path.left(slashPosition));
281 if (nextCandidate) {
282 KisOptionCollectionWidget *optionCollectionWidget =
283 qobject_cast<KisOptionCollectionWidget*>(nextCandidate);
284 if (optionCollectionWidget) {
285 return optionCollectionWidget->m_d->findWidget(path.right(path.size() - slashPosition), nextCandidate);
286 }
287 KisOptionCollectionWidgetWithHeader *optionCollectionWidgetWithHeader =
288 qobject_cast<KisOptionCollectionWidgetWithHeader*>(nextCandidate);
289 if (optionCollectionWidgetWithHeader) {
290 return optionCollectionWidgetWithHeader->m_d->widgetCollection->m_d->findWidget(path.right(path.size() - slashPosition), nextCandidate);
291 }
292 QStringRef rest = path.right(path.size() - slashPosition);
293 while (rest.startsWith('/')) {
294 rest = rest.right(rest.size() - 1);
295 }
296 if (rest.isEmpty()) {
297 return nextCandidate;
298 }
299 }
300 return nullptr;
301 }
Wrapper class around a KisOptionCollectionWidget that also provide a header with a title label and an...
Class providing a list of widgets with some addons such as separators, orientation or individual widg...

References KisOptionCollectionWidget::m_d, KisOptionCollectionWidgetWithHeader::m_d, and widget().

◆ insertWidget()

void KisOptionCollectionWidget::Private::insertWidget ( int index,
const QString & id,
QWidget * widget )
inline

Definition at line 203 of file KisOptionCollectionWidget.cpp.

204 {
205 KisOptionCollectionWidgetWrapper *widgetWrapper =
207 widgetWrapper->setProperty("id", id);
208 widgetWrapper->setSeparatorVisible(showSeparators);
209 widgetWrapper->setOrientation(orientation);
210 widgetWrapper->setWidgetMargin(widgetsMargin);
211 widgetWrappers.insert(index, widgetWrapper);
212
213 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(q->layout());
214 KIS_ASSERT(layoutMain);
215
216 int indexLayout;
217 for (indexLayout = 0; indexLayout < layoutMain->count(); ++indexLayout) {
218 const QWidget *prevWidget = layoutMain->itemAt(indexLayout)->widget();
219 const int prevIndex = q->widgetIndexFromId(prevWidget->property("id").toString());
220 if (prevIndex >= index) {
221 break;
222 }
223 }
224 layoutMain->insertWidget(indexLayout, widgetWrapper);
226 }
void setOrientation(Qt::Orientation orientation)
int widgetIndexFromId(const QString &id) const
Get the index of the widget that has the given id.
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
QVector< KisOptionCollectionWidgetWrapper * > widgetWrappers

References adjustSeparators(), KIS_ASSERT, orientation, q, KisOptionCollectionWidgetWrapper::setOrientation(), KisOptionCollectionWidgetWrapper::setSeparatorVisible(), KisOptionCollectionWidgetWrapper::setWidgetMargin(), showSeparators, widget(), KisOptionCollectionWidget::widgetIndexFromId(), widgetsMargin, and widgetWrappers.

◆ widget() [1/2]

QWidget * KisOptionCollectionWidget::Private::widget ( int index) const
inline

Definition at line 258 of file KisOptionCollectionWidget.cpp.

259 {
260 return widgetWrappers[index]->widget();
261 }

References widgetWrappers.

◆ widget() [2/2]

QWidget * KisOptionCollectionWidget::Private::widget ( QStringRef id) const
inline

Definition at line 263 of file KisOptionCollectionWidget.cpp.

264 {
265 return widget(widgetIndexFromId(id));
266 }

References widget(), and widgetIndexFromId().

◆ widgetIndexFromId()

int KisOptionCollectionWidget::Private::widgetIndexFromId ( QStringRef id) const
inline

Definition at line 243 of file KisOptionCollectionWidget.cpp.

244 {
245 for (int i = 0; i < widgetWrappers.size(); ++i) {
246 if (widgetWrappers[i]->property("id").toString() == id) {
247 return i;
248 }
249 }
250 return -1;
251 }
QString toString(const QString &value)

References widgetWrappers.

Member Data Documentation

◆ orientation

Qt::Orientation KisOptionCollectionWidget::Private::orientation {Qt::Vertical}

Definition at line 198 of file KisOptionCollectionWidget.cpp.

198{Qt::Vertical};

◆ q

KisOptionCollectionWidget* KisOptionCollectionWidget::Private::q {nullptr}

Definition at line 195 of file KisOptionCollectionWidget.cpp.

195{nullptr};

◆ showSeparators

bool KisOptionCollectionWidget::Private::showSeparators {false}

Definition at line 197 of file KisOptionCollectionWidget.cpp.

197{false};

◆ widgetsMargin

int KisOptionCollectionWidget::Private::widgetsMargin {10}

Definition at line 199 of file KisOptionCollectionWidget.cpp.

199{10};

◆ widgetWrappers

QVector<KisOptionCollectionWidgetWrapper*> KisOptionCollectionWidget::Private::widgetWrappers

Definition at line 196 of file KisOptionCollectionWidget.cpp.


The documentation for this struct was generated from the following file: