56 QMap<Q_ULLONG, QListViewItem*> mg,
58 const QStringList & Fname,
59 const QStringList & FnameGroup,
64 ListView->setDestination(toSelect);
65 aLog::print(aLog::MT_DEBUG, tr(
"CatalogForm:setData begin"));
68 QPixmap pixmap(getElementPixmap());
69 QPixmap pixmap_mark_deleted(getMarkDeletedPixmap());
70 idElementForm = idElForm;
71 idGroupForm = idGrForm;
75 fieldListGroup = FnameGroup;
77 ListView->setAllColumnsShowFocus (
true );
78 QMap<Q_ULLONG, QListViewItem *>::Iterator it = map_gr.begin();
81 while(it!=map_gr.end())
83 cat->selectByGroup(it.key());
86 item =
new QListViewItem(map_gr[it.key()]);
87 aLog::print(aLog::MT_DEBUG, tr(
"CatalogForm add first element in group"));
89 if(cat->isElementMarkDeleted())
90 item->setPixmap(0,pixmap_mark_deleted);
92 item->setPixmap(0,pixmap);
93 for(i=0; i<fieldList.count(); i++)
95 item->setText(i,cat->sysValue(fieldList[i]).toString());
97 map_el.insert(cat->sysValue(
"id").toULongLong(),item);
102 cat->selectByGroup(0);
106 aLog::print(aLog::MT_DEBUG, tr(
"CatalogForm add elements into root"));
109 item =
new QListViewItem(ListView);
110 if(cat->isElementMarkDeleted())
111 item->setPixmap(0,pixmap_mark_deleted);
113 item->setPixmap(0,pixmap);
114 for(i=0; i<fieldList.count(); i++)
116 item->setText(i,cat->sysValue(fieldList[i]).toString());
118 map_el.insert(cat->sysValue(
"id").toULongLong(),item);
124 ListView->setSelected(ListView->firstChild(),
true);
125 aLog::print(aLog::MT_DEBUG, tr(
"CatalogForm init"));
133 CatalogForm::setId(Q_ULLONG idx )
144 CatalogForm::find(
const QString& s )
150 const int LENGTH_NO_FIND = tmp;
155 const int VISIBLE_ROWS = tmp;
159 if(s.length()>=LENGTH_NO_FIND)
161 if(!ListHint->isVisible())
163 ListHint->show(LineEdit, StatusFrame);
167 cat->select(fieldName +
" like '%"+s+
"%'");
172 if(count++<VISIBLE_ROWS)
174 ListHint->insertItem(cat->sysValue(fieldName).toString(), cat->sysValue(
"id").toInt());
176 }
while(cat->Next());
178 if(!ListHint->count())
186 StatusFrame->repaint();
187 StatusFrame->drawText( 5, StatusFrame->size().height()-3, QString(tr(
"displaying %1 from %2")).arg(ListHint->count()).arg(count) );
193 if(ListHint->isVisible())
206 CatalogForm::pressArrow()
209 if(ListHint->isVisible())
211 ListHint->setFocus();
212 ListHint->setSelected(ListHint->currentItem(),
true);
217 find(LineEdit->text());
218 if(ListHint->isVisible())
220 ListHint->setFocus();
221 ListHint->setSelected(ListHint->currentItem(),
true);
229 CatalogForm::isPressArrow()
241 ListView =
new aListView(centralWidget(),
"listView");
242 ListView->setGeometry(30,30,400,300);
243 ListView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
244 LineEdit =
new aLineEdit(centralWidget(),
"lineEdit");
245 ListHint =
new aListBox(centralWidget(),
"listBox");
246 StatusFrame =
new QFrame(centralWidget(),
"statusFrame");
248 ListView->setRootIsDecorated(
true );
250 StatusFrame->setGeometry( QRect( 0, 0, 50,5 ) );
251 StatusFrame->setFrameShape( QFrame::StyledPanel );
252 StatusFrame->setFrameShadow( QFrame::Raised );
255 GridLayout =
new QGridLayout(centralWidget(), 1, 1, 11, 6,
"GridLayout");
256 GridLayout->addMultiCellWidget( ListView, 2,3, 0 , 0 );
257 GridLayout->addWidget( LineEdit, 1, 0 );
258 GridLayout->addWidget( bCancel, 3, 1 );
259 QLabel *lb =
new QLabel(tr(
"Search"),centralWidget());
260 lb->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, lb->sizePolicy().hasHeightForWidth() ) );
261 GridLayout->addWidget( lb ,0,0);
262 QSpacerItem* spacer =
new QSpacerItem( 20, 390, QSizePolicy::Minimum, QSizePolicy::Expanding );
263 GridLayout->addMultiCell( spacer, 0,2,1, 1);
265 QPixmap pix= QPixmap::fromMimeSource(
"cat.png");
268 aLog::print(aLog::MT_INFO, tr(
"Catalog Form image cat.png not loaded"));
278 connect(ListView, SIGNAL (newItemRequest(QListViewItem*)),
279 this, SLOT (new_item(QListViewItem*)));
281 connect(ListView, SIGNAL (newGroupRequest(QListViewItem*)),
282 this, SLOT (new_group(QListViewItem*)));
284 connect(ListView, SIGNAL (delItemRequest(QListViewItem*)),
285 this, SLOT (del_item(QListViewItem*)));
287 connect(ListView, SIGNAL (markDeletedRequest(QListViewItem*)),
288 this, SLOT (mark_deleted(QListViewItem*)));
290 connect(ListView, SIGNAL (undoMarkDeletedRequest(QListViewItem*)),
291 this, SLOT (undo_mark_deleted(QListViewItem*)));
293 connect(ListView, SIGNAL (editRequest(QListViewItem*,
int)),
294 this, SLOT (edit(QListViewItem*,
int)));
296 connect(ListView, SIGNAL (selectRequest(QListViewItem*)),
297 this, SLOT (select(QListViewItem*)));
299 connect(LineEdit, SIGNAL (delayTextChanged(
const QString&)),
300 this, SLOT (find(
const QString&)));
302 connect(LineEdit, SIGNAL (keyArrowPressed()),
303 this, SLOT (pressArrow()));
305 connect(LineEdit, SIGNAL (keyEnterPressed()),
308 connect(ListView, SIGNAL (expanded ( QListViewItem *)),
309 this, SLOT (onLoadElements( QListViewItem *)));
311 connect(ListHint, SIGNAL (lostFocus()),
312 LineEdit, SLOT (setFocus()));
314 connect(ListHint, SIGNAL (lostFocus()),
315 StatusFrame, SLOT (hide()));
317 connect(ListHint, SIGNAL (lostFocus()),
318 ListHint, SLOT (hide()));
320 connect(ListHint, SIGNAL (keyArrowLRPressed()),
321 LineEdit, SLOT (setFocus()));
323 connect(ListHint, SIGNAL (keyArrowLRPressed(
const QString&)),
324 this, SLOT (setText(
const QString&)));
326 connect(ListHint, SIGNAL (keyEnterPressed()),
329 connect(ListHint, SIGNAL (sendMessage(
const QString &)),
330 this->statusBar(), SLOT (message(
const QString &)));
332 connect(ListView, SIGNAL (sendMessage(
const QString &)),
333 this->statusBar(), SLOT (message(
const QString &)));
335 connect(LineEdit, SIGNAL (sendMessage(
const QString &)),
336 this->statusBar(), SLOT (message(
const QString &)));
338 LineEdit->setFocus();
345 CatalogForm::destroy()
356 CatalogForm::setText(
const QString & s )
358 LineEdit->blockSignals (
true );
359 LineEdit->setText ( s );
360 setId(ListHint->getId(ListHint->currentItem()));
361 LineEdit->blockSignals (
false );
370 Q_ULLONG ide=getId(), idg;
373 ide = findFirst(LineEdit->text());
378 if(map_el.contains(getId()))
380 goToItem(map_el[getId()]);
388 CatalogForm::goToItem( QListViewItem *item)
390 ListView->setSelected(item,
true);
391 ListView->ensureItemVisible(item);
392 ListView->setFocus();
401 CatalogForm::findFirst(
const QString &s )
404 cat->select(fieldName +
" like '%"+s+
"%'");
408 res = cat->sysValue(
"id").toULongLong();
419 CatalogForm::loadElements( Q_ULLONG idGroup )
421 QListViewItem * item;
422 QListViewItem * p_item;
426 QPixmap pixmap(getElementPixmap());
427 QPixmap pixmap_mark_deleted(getMarkDeletedPixmap());
428 cat->selectByGroup(idGroup);
435 if(map_gr.contains(idGroup)
436 && !map_el.contains(cat->sysValue(
"id").toULongLong()))
438 p_item = map_gr[idGroup];
439 item =
new QListViewItem(p_item);
440 if(cat->isElementMarkDeleted())
441 item->setPixmap(0,pixmap_mark_deleted);
443 item->setPixmap(0,pixmap);
444 for(i=0; i<fieldList.count(); i++)
447 item->setText(i,cat->sysValue(fieldList[i]).toString());
449 map_el.insert(cat->sysValue(
"id").toULongLong(),item);
461 CatalogForm::onLoadElements( QListViewItem *item )
463 QValueList<QListViewItem*> lst = map_gr.values();
464 int ind = lst.findIndex(item);
468 QValueList<Q_ULLONG> listKey = map_gr.keys();
480 CatalogForm::getIdg( Q_ULLONG ide )
482 return cat->idGroupByElement(ide);
491 CatalogForm::new_item( QListViewItem * parentItem )
498 QListViewItem* item =
new QListViewItem(ListView);
499 QPixmap pixmap(getElementPixmap());
500 item->setPixmap(0,pixmap);
501 map_el.insert(cat->sysValue(
"id").toULongLong(),item);
503 ListView->ensureItemVisible(item);
507 Q_ULLONG
id = getGroupId(parentItem);
508 QPixmap pixmap(getElementPixmap());
511 cat->groupSelect(
id);
512 if(!cat->isGroupMarkDeleted())
515 QListViewItem* item =
new QListViewItem(map_gr[
id]);
516 item->setPixmap(0,pixmap);
517 map_el.insert(cat->sysValue(
"id").toULongLong(),item);
519 ListView->ensureItemVisible(item);
522 else cfg_message(0,tr(
"Can't added new element to mark deleted group"));
526 new_item(parentItem->parent());
535 CatalogForm::getGroupId( QListViewItem * item )
537 QValueList<QListViewItem*> lst = map_gr.values();
538 int ind = lst.findIndex(item);
542 QValueList<Q_ULLONG> listKey = map_gr.keys();
553 CatalogForm::new_group( QListViewItem * parentItem )
555 Q_ULLONG
id = getGroupId(parentItem);
556 QListViewItem * item;
557 QPixmap pixmap(getGroupPixmap());
561 id = getElementId(parentItem);
564 cfg_message(0,tr(
"Can't added group to element"));
571 item =
new QListViewItem(ListView);
572 ListView->insertItem(item);
578 if(cat->isGroupMarkDeleted())
580 cfg_message(0,tr(
"Can't added group to mark deleted group"));
584 item =
new QListViewItem(map_gr[
id]);
587 item->setPixmap(0,pixmap);
588 map_gr.insert(cat->GroupSysValue(
"id").toULongLong(),item);
590 ListView->ensureItemVisible(item);
591 ListView->setCurrentItem(item);
592 ListView->setSelected(item,
true);
602 CatalogForm::getGroupPixmap()
604 QPixmap pixmap = QPixmap::fromMimeSource(
"group2.png");
608 aLog::print(aLog::MT_INFO, tr(
"Catalog Form group pixmap not load"));
619 CatalogForm::getElementPixmap()
621 QPixmap pixmap= QPixmap::fromMimeSource(
"field2.png");
624 aLog::print(aLog::MT_INFO, tr(
"Catalog Form element pixmap not load"));
634 CatalogForm::getMarkDeletedPixmap()
636 QPixmap pixmap = QPixmap::fromMimeSource(
"editdelete2.png");
640 aLog::print(aLog::MT_INFO, tr(
"Catalog Form mark deleted group pixmap not load"));
648 void CatalogForm::del_item( QListViewItem * item )
651 Q_ULLONG
id = getElementId(item);
665 id = getGroupId(item);
668 QValueList<Q_ULLONG> listDeletedId;
669 cat->delGroup(
id, listDeletedId);
670 QValueList<Q_ULLONG>::iterator it = listDeletedId.begin();
671 while(it!= listDeletedId.end())
673 if(map_el.contains(*it)) map_el.remove(*it);
674 else if(map_gr.contains(*it)) map_gr.remove(*it);
688 void CatalogForm::mark_deleted( QListViewItem * item )
690 Q_ULLONG
id = getElementId(item);
697 cat->setMarkDeletedElement(
id,
true);
698 item->setPixmap(0,getMarkDeletedPixmap());
703 id = getGroupId(item);
707 QValueList<Q_ULLONG> listDeletedId;
708 cat->getMarkDeletedList(
id,listDeletedId);
709 QValueList<Q_ULLONG>::iterator it = listDeletedId.begin();
710 while(it != listDeletedId.end())
712 if(map_el.contains(*it))
714 map_el[*it]->setPixmap(0, getMarkDeletedPixmap());
715 cat->setMarkDeletedElement(*it,
true);
716 it = listDeletedId.remove(it);
723 it = listDeletedId.begin();
724 while(it != listDeletedId.end())
726 if(map_gr.contains(*it))
728 map_gr[*it]->setPixmap(0, getMarkDeletedPixmap());
729 cat->setMarkDeletedGroup(*it,
true);
730 it = listDeletedId.remove(it);
746 void CatalogForm::undo_mark_deleted( QListViewItem * item )
748 Q_ULLONG
id = getElementId(item);
754 cat->setMarkDeletedElement(
id,
false);
755 item->setPixmap(0,getElementPixmap());
760 id = getGroupId(item);
765 QValueList<Q_ULLONG> listDeletedId;
767 cat->getMarkDeletedList(
id, listDeletedId);
768 QValueList<Q_ULLONG>::iterator it = listDeletedId.begin();
769 while(it != listDeletedId.end())
771 if(map_el.contains(*it))
773 map_el[*it]->setPixmap(0, getElementPixmap());
774 cat->setMarkDeletedElement(*it,
false);
775 it = listDeletedId.remove(it);
782 it = listDeletedId.begin();
783 while(it != listDeletedId.end())
785 if(map_gr.contains(*it))
787 map_gr[*it]->setPixmap(0, getGroupPixmap());
788 cat->setMarkDeletedGroup(*it,
false);
789 it = listDeletedId.remove(it);
801 void CatalogForm::edit( QListViewItem * item,
int)
806 void CatalogForm::edit( QListViewItem * item,
bool afterNew)
809 aLog::print(aLog::MT_DEBUG, tr(
"Catalog Form edit element start"));
813 Q_ULLONG
id = getElementId(item);
816 aLog::print(aLog::MT_DEBUG, tr(
"Catalog Form edit element with id=%1").arg(
id));
820 if(!cat->isElementMarkDeleted())
822 aForm *editForm =
new aForm(mw->ws, &mw->engine, (
long int) idElementForm);
825 if(afterNew) editForm->
setMode(0);
828 connect(editForm, SIGNAL(closeForm(Q_ULLONG)),
this, SLOT(Refresh(Q_ULLONG)));
833 aLog::print(aLog::MT_ERROR, tr(
"Catalog Form edit element form is null"));
836 else cfg_message(0, tr(
"Can't edit mark deleted element"));
838 else cfg_message(1,tr(
"Catalog haven't edit element form"));
842 id = getGroupId(item);
843 aLog::print(aLog::MT_DEBUG, tr(
"Catalog Form edit group with id = %1").arg(
id));
847 cat->groupSelect(
id);
850 if(!cat->isGroupMarkDeleted())
852 aForm *editForm =
new aForm(mw->ws, &mw->engine, (
long int) idGroupForm);
855 if(afterNew) editForm->
setMode(0);
858 editForm->SelectGroup(
id);
859 connect(editForm, SIGNAL(closeForm(Q_ULLONG)),
this, SLOT(Refresh(Q_ULLONG)));
864 aLog::print(aLog::MT_ERROR, tr(
"Catalog Form edit group form is null"));
867 else cfg_message(0, tr(
"Can't edit mark deleted group"));
869 else cfg_message(1,tr(
"Catalog haven't edit group form"));
875 aLog::print(aLog::MT_ERROR, tr(
"Catalog Form main widget is not 'MainForm'"));
884 void CatalogForm::select( QListViewItem * item )
886 Q_ULLONG res = getGroupId(item);
889 res = getElementId(item);
891 if(!cat->isElementMarkDeleted())
899 cat->groupSelect(res);
900 if(!cat->isGroupMarkDeleted())
914 Q_ULLONG CatalogForm::getElementId( QListViewItem * item )
916 QValueList<QListViewItem*> lst = map_el.values();
917 int ind = lst.findIndex(item);
921 QValueList<Q_ULLONG> listKey = map_el.keys();
928 void CatalogForm::doOk()
935 void CatalogForm::keyPressEvent( QKeyEvent * e )
937 if ( e->key()==Qt::Key_Return)
940 if ( e->key()==Qt::Key_Escape)
948 void CatalogForm::Refresh( Q_ULLONG
id )
950 QListViewItem * item;
951 if( map_el.contains(
id ))
955 for(uint i=0; i<fieldList.count(); i++)
958 item->setText(i,cat->sysValue(fieldList[i]).toString());
959 ListView->setFocus();
964 if( map_gr.contains(
id ) )
967 cat->groupSelect(
id );
968 item->setText(0,cat->GroupSysValue(fieldListGroup[0]).toString());
969 ListView->setFocus();
static QString readConfigVariable(const QString &name, bool *ok)
Definition: aservice.cpp:448
static void saveSize2Config(QRect size, const QString &mdname)
Definition: aservice.cpp:389
static void print(int status, const QString &text)
Definition: alog.cpp:58
Definition: acatalogue.h:54
Definition: catalogformwidgets.h:44
static QRect loadSizeFromConfig(const QString &mdname)
Definition: aservice.cpp:419
Definition: catalogformwidgets.h:106
Definition: mainform.h:30
Definition: catalogformwidgets.h:79