00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "omglistwidget.h"
00023
00024 #include <QListWidget>
00025 #include <QListWidgetItem>
00026 #include <QStringList>
00027 #include <QListWidgetItem>
00028
00029 OmgListWidget::OmgListWidget(QWidget* parent, Qt::WFlags fl)
00030 : QWidget(parent,fl)
00031 {
00032
00033 setupUi(this);
00034 lstItems->setEnabled(true);
00035
00036
00037 connect (lstItems,SIGNAL(itemPressed(QListWidgetItem *)),
00038 this,SLOT(itemPressedSlot(QListWidgetItem *)));
00039
00040 }
00041
00042 OmgListWidget::~OmgListWidget()
00043 {}
00044
00045
00046
00047
00048 void OmgListWidget::itemPressedSlot(QListWidgetItem * thepItem)
00049 {
00050 emit itemPressed(thepItem);
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 }
00066
00067 void OmgListWidget::selectAll()
00068 {
00069 qDebug("OmgListWidget::selectAll");
00070 for ( int myCounter = 0; myCounter < lstItems->count(); myCounter++ )
00071 {
00072 QListWidgetItem * mypItem = lstItems->item(myCounter);
00073 mypItem->setCheckState(Qt::Checked);
00074 qDebug(mypItem->text().toLocal8Bit() + " has been checked");
00075 }
00076 }
00077
00078 void OmgListWidget::invertSelection()
00079 {
00080 qDebug("OmgListWidget::invertSelection");
00081 for ( int myCounter = 0; myCounter < lstItems->count(); myCounter++ )
00082 {
00083 QListWidgetItem * mypItem = lstItems->item(myCounter);
00084 if (mypItem->checkState()==Qt::Checked)
00085 {
00086 mypItem->setCheckState(Qt::Unchecked);
00087 qDebug(mypItem->text().toLocal8Bit() + " has been unchecked");
00088 }
00089 else
00090 {
00091 mypItem->setCheckState(Qt::Checked);
00092 qDebug(mypItem->text().toLocal8Bit() + " has been checked");
00093 }
00094 }
00095 }
00096
00097 void OmgListWidget::selectNone()
00098 {
00099 qDebug("OmgListWidget::selectNone");
00100 for ( int myCounter = 0; myCounter < lstItems->count(); myCounter++ )
00101 {
00102 QListWidgetItem * mypItem = lstItems->item(myCounter);
00103 mypItem->setCheckState(Qt::Unchecked);
00104 qDebug(mypItem->text().toLocal8Bit() + " has been unchecked");
00105 }
00106 }
00107
00108 int OmgListWidget::checkedItemCount()
00109 {
00110 return checkedItems().count();
00111 }
00112
00113 QStringList OmgListWidget::checkedItems()
00114 {
00115 QStringList myList;
00116 for ( int myCounter = 0; myCounter < lstItems->count(); myCounter++ )
00117 {
00118 QListWidgetItem * mypItem = lstItems->item(myCounter);
00119 if (mypItem->checkState()==Qt::Checked)
00120 {
00121 myList << mypItem->text();
00122 }
00123 }
00124 return myList;
00125 }
00126 QStringList OmgListWidget::checkedDataItems()
00127 {
00128 QStringList myList;
00129 for ( int myCounter = 0; myCounter < lstItems->count(); myCounter++ )
00130 {
00131 QListWidgetItem * mypItem = lstItems->item(myCounter);
00132 if (mypItem->checkState()==Qt::Checked)
00133 {
00134 myList << mypItem->data(Qt::UserRole).toString();
00135 }
00136 }
00137 return myList;
00138 }
00139 void OmgListWidget::hideOptionsTool()
00140 {
00141 toolConfigure->hide();
00142 }
00143 void OmgListWidget::showOptionsTool()
00144 {
00145 toolConfigure->show();
00146 }
00147 void OmgListWidget::hideAddItemTool()
00148 {
00149 toolAddItem->hide();
00150 }
00151 void OmgListWidget::showAddItemTool()
00152 {
00153 toolAddItem->show();
00154 }
00156
00158 void OmgListWidget::addItem ( const QString & theLabel , bool theCheckedFlag=false)
00159 {
00160 QListWidgetItem *mypItem = new QListWidgetItem(theLabel,lstItems);
00161
00162 addItem (mypItem,theCheckedFlag);
00163 }
00164 void OmgListWidget::addItem ( QListWidgetItem * thepItem, bool theCheckedFlag=false )
00165 {
00166
00167 if (!theCheckedFlag)
00168 {
00169 thepItem->setCheckState(Qt::Unchecked);
00170 }
00171 else
00172 {
00173 thepItem->setCheckState(Qt::Checked);
00174 }
00175 lstItems->addItem(thepItem);
00176 }
00177 void OmgListWidget::addItems ( const QStringList & theLabels , bool theCheckedFlag=false)
00178 {
00179
00180 QStringListIterator myIterator(theLabels);
00181 while (myIterator.hasNext())
00182 {
00183
00184 addItem(myIterator.next(),theCheckedFlag);
00185 }
00186 }
00187 void OmgListWidget::clear()
00188 {
00189 lstItems->clear();
00190 }
00191 int OmgListWidget::count()
00192 {
00193 return lstItems->count();
00194 }
00195
00196 QListWidgetItem * OmgListWidget::item(int theItem)
00197 {
00198 return lstItems->item(theItem);
00199 }
00200 void OmgListWidget::insertItem ( int theRow, QListWidgetItem * thepItem , bool theCheckedFlag=false)
00201 {
00202 if (!theCheckedFlag)
00203 {
00204 thepItem->setCheckState(Qt::Unchecked);
00205 }
00206 else
00207 {
00208 thepItem->setCheckState(Qt::Checked);
00209 }
00210 lstItems->insertItem(theRow,thepItem);
00211 }
00212 void OmgListWidget::insertItem ( int theRow, const QString & theLabel , bool theCheckedFlag=false)
00213 {
00214 QListWidgetItem *mypItem = new QListWidgetItem(theLabel,lstItems);
00215
00216 insertItem (theRow,mypItem,theCheckedFlag);
00217 }
00218 void OmgListWidget::insertItems ( int theRow, const QStringList & theLabels , bool theCheckedFlag=false)
00219 {
00220
00221 QStringListIterator myIterator(theLabels);
00222 while (myIterator.hasNext())
00223 {
00224
00225 insertItem(theRow++,myIterator.next(),theCheckedFlag);
00226 }
00227
00228 }
00229
00230
00231
00232
00233
00234
00235 void OmgListWidget::on_toolSelectAll_clicked()
00236 {
00237
00238 selectAll();
00239 }
00240 void OmgListWidget::on_toolSelectNone_clicked()
00241 {
00242
00243 selectNone();
00244 }
00245
00246 void OmgListWidget::on_toolInvertSelection_clicked()
00247 {
00248
00249 invertSelection();
00250 }
00251
00252 void OmgListWidget::on_toolAddItem_clicked()
00253 {
00254 qDebug("on_toolAddItem_clicked()");
00255 emit addItemClicked();
00256 }
00257
00258 void OmgListWidget::on_toolConfigure_clicked()
00259 {
00260 emit configureClicked();
00261 }