[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfflowlistwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * file klfflowlistwidget.cpp
3 * This file is part of the KLatexFormula Project.
4 * Copyright (C) 2011 by Philippe Faist
5 * philippe.faist at bluewin.ch
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22/* $Id$ */
23
24#include <QWidget>
25#include <QLabel>
26
27#include <klfdefs.h>
28
29#include "klfflowlayout.h"
30#include "klfflowlistwidget.h"
31#include "klfflowlistwidget_p.h"
32
33
34KLFFlowListWidget::KLFFlowListWidget(QWidget *parent) : QWidget(parent)
35{
36 pLayout = new KLFFlowLayout(this);
37 pWidgets = QList<QWidget*>();
38
40
41 setMinimumSize(1,1);
42}
46
47
49{
50 KLF_ASSERT_CONDITION(i >= 0 && i < pWidgets.size(),
51 "index "<<i<<" out of bounds [0,"<<pWidgets.size()<<"] !",
52 return QString(); ) ;
53 return pWidgets[i]->property("klfflowlistwidget_str").toString();
54}
56{
57 KLF_ASSERT_CONDITION(i >= 0 && i < pWidgets.size(),
58 "index "<<i<<" out of bounds [0,"<<pWidgets.size()<<"] !",
59 return QString(); ) ;
60 return pWidgets[i]->property("klfflowlistwidget_data");
61}
62
64{
66 int k;
67 for (k = 0; k < pWidgets.size(); ++k) {
68 s << itemAt(k);
69 }
70 return s;
71}
73{
74 QVariantList v;
75 int k;
76 for (k = 0; k < pWidgets.size(); ++k) {
77 v << itemDataAt(k);
78 }
79 return v;
80}
81
82void KLFFlowListWidget::setItems(const QStringList& strings, const QVariantList& datalist)
83{
84 // clean pWidgets
85 while (pWidgets.size()) {
86 delete pWidgets.takeAt(0);
87 }
88
89 KLF_ASSERT_CONDITION(strings.size() >= datalist.size(),
90 "datalist is larger than strings; some datas will be ignored.", ; ) ;
91 // and individually add all items
92 int k;
93 for (k = 0; k < strings.size(); ++k) {
94 QVariant v = (k < datalist.size()) ? datalist[k] : QVariant();
95 addItem(strings[k], v);
96 }
97}
98void KLFFlowListWidget::addItem(const QString& string, const QVariant& data)
99{
100 insertItem(-1, string, data);
101}
102
104{
105 i = simple_wrapped_item_index(i);
106 KLF_ASSERT_CONDITION(i >= 0 && i < pWidgets.size(),
107 "index "<<i<<" out of bounds [0,"<<pWidgets.size()-1<<"] !",
108 return; ) ;
109
110 delete pWidgets[i];
111 pWidgets.removeAt(i);
112}
113
114void KLFFlowListWidget::insertItem(int i, const QString& s, const QVariant& data)
115{
117 klfDbg("at pos="<<i<<", s="<<s<<", data="<<data) ;
118
119 i = simple_wrapped_item_index(i);
120 KLF_ASSERT_CONDITION(i >= 0 && i <= pWidgets.size(),
121 "index "<<i<<" out of bounds [0,"<<(pWidgets.size()-1)+1<<"] !",
122 return; ) ;
123
124 KLFFlowListItemWidget *w = new KLFFlowListItemWidget(this);
125 QLabel *l = new QLabel(s, this);
126 w->setItemWidget(l);
127
128 w->setProperty("klfflowlistwidget_str", QVariant(s));
129 w->setProperty("klfflowlistwidget_data", data);
130
131 connect(w, SIGNAL(closeClicked()), this, SLOT(itemClosed()));
132
133 pLayout->addWidget(w, 0, 0, Qt::AlignVCenter);
134
135 pWidgets.insert(i, w);
136}
137
138void KLFFlowListWidget::itemClosed()
139{
140 KLFFlowListItemWidget *w = qobject_cast<KLFFlowListItemWidget*>(sender());
141 KLF_ASSERT_NOT_NULL(w, "sender is not a KLFFlowListItemWidget !", return; ) ;
142
143 klfDbg("removing item "<<w<<" ...") ;
144
145 pWidgets.removeAll(w);
146 w->deleteLater();
147}
A Layout that places widgets left to right, top to bottom.
virtual void addWidget(QWidget *w, int hstretch=0, int vstretch=0, Qt::Alignment align=0)
void setFlush(Flush f)
@ FlushBegin
Leave all extra space at end of line.
QVariant itemDataAt(int i) const
void addItem(const QString &string, const QVariant &data=QVariant())
void insertItem(int i, const QString &s, const QVariant &data=QVariant())
void setItems(const QStringList &strings, const QVariantList &datalist=QVariantList())
QVariantList itemDataList() const
QStringList itemList() const
QString itemAt(int i) const
KLFFlowListWidget(QWidget *parent=NULL)
#define KLF_DEBUG_BLOCK(msg)
Utility to debug the execution of a block.
Definition klfdebug.h:152
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
Asserting Non-NULL pointers (NON-FATAL)
Definition klfdebug.h:210
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
Asserting Conditions (NON-FATAL)
Definition klfdebug.h:201
#define KLF_FUNC_NAME
Definition klfdebug.h:194
#define klfDbg(streamableItems)
print debug stream items
Definition klfdebug.h:158
Base declarations for klatexformula and some utilities.
void insert(int i, const T &value)
int removeAll(const T &value)
void removeAt(int i)
int size() const
T takeAt(int i)

Generated by doxygen 1.9.8