⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ktablistbox.cpp

📁 一种效率高
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    }    delete[] itemList;    delete[] itemShowList;  }}//-----------------------------------------------------------------------------void KTabListBox::setNumRows(int aRows){  lbox.setNumRows(aRows);}//-----------------------------------------------------------------------------void KTabListBox::setTabWidth(int aTabWidth){  tabPixels = aTabWidth;}//-----------------------------------------------------------------------------void KTabListBox::setNumCols(int aCols){  int i;  if (colList)  {    for (i=0; i<numColumns; i++)      delete colList[i];    delete [] colList;    delete [] colShowList;  }  if (itemList)  {    for (i=0; i<maxItems; i++)      delete itemList[i];    delete [] itemList;  }  if (itemShowList)    delete [] itemShowList;  colList  = 0L;  colShowList=0L;  itemList = 0L;  itemShowList=0L;  maxItems = 0;  if (aCols < 0) aCols = 0;  lbox.setNumCols(aCols);  numColumns = aCols;  if (aCols <= 0) return;  colList  = new KTabListBoxColumnPtr[aCols];  colShowList = new int[aCols];  for (i=0; i<aCols; i++)  {    colList[i] = newKTabListBoxColumn();    colShowList[i] = i;  }  itemList = new KTabListBoxItemPtr[INIT_MAX_ITEMS];  itemShowList = new int[INIT_MAX_ITEMS];  for (i=0; i<INIT_MAX_ITEMS; i++)  {    itemList[i] = new KTabListBoxItem(aCols);    itemShowList[i]=i;  }  maxItems = INIT_MAX_ITEMS;}//-----------------------------------------------------------------------------KTabListBoxColumn* KTabListBox::newKTabListBoxColumn(void){  return (new KTabListBoxColumn(this));}//-----------------------------------------------------------------------------void KTabListBox::readConfig(void){  KConfig* conf = KApplication::getKApplication()->getConfig();  int beg, end, i, w;  int cols = numCols(),fixedmin=MINIMUM_SPACE;  QString str, substr;  conf->setGroup(name());  str = conf->readEntry("colwidth");  if (!str.isEmpty())    for (i=0, beg=0, end=0; i<cols;)  {    end = str.find(',', beg);    if (end < 0) break;    w = str.mid(beg,end-beg).toInt();    if (colList[i]->orderType()==ComplexOrder)       fixedmin+=ARROW_SPACE+labelHeight-BUTTON_SPACE;    else       if (colList[i]->orderType()==SimpleOrder)          fixedmin+=ARROW_SPACE;    if (w < fixedmin) w = fixedmin;    colList[i]->setWidth(w);    colList[i]->setDefaultWidth(w);    i++;    beg = end+1;  }  else   for(i=0;i<cols;i++)   {     colList[i]->setWidth(60);     colList[i]->setDefaultWidth(60);   }}//-----------------------------------------------------------------------------void KTabListBox::writeConfig(void){  KConfig* conf = KApplication::getKApplication()->getConfig();  int t;  char str[200]="";  conf->setGroup(name());  for(t=0;t<numCols();t++) sprintf(str,"%s%d,",str,colList[t]->defaultWidth());  conf->writeEntry("colwidth",str);  conf->sync();}//-----------------------------------------------------------------------------void KTabListBox::setDefaultColumnWidth(int aWidth, ...){  va_list ap;  int i, cols;  cols = numColumns;  va_start(ap, aWidth);  for (i=0; aWidth && i<cols; i++)  {    colList[i]->setDefaultWidth(aWidth);    aWidth = va_arg(ap, int);  }  va_end(ap);}//-----------------------------------------------------------------------------void KTabListBox::setColumnWidth(int col, int aWidth){  if (col<0 || col>=numCols()) return;  colList[col]->setWidth(aWidth);  colList[col]->setDefaultWidth(aWidth);  lbox.updateTableSize();}//-----------------------------------------------------------------------------void KTabListBox::reorderRows(){  int t=1,t1=0,n,maxVal,iColNum[10],c1;  int result,itmp,totRows=numRows();  bool change;  // Who need more than 9 columns of priority for sorting??  KTabListBoxColumn *pc[10];  int (*columnSort)(const char *, const char *);  OrderMode fmode;  needsSort=true;  if(!lbox.autoUpdate()) return;  needsSort=false;  for(n=0;n<10;n++) { pc[n]=0L; iColNum[n]=0;}  while(t<10)  {    if(colList[t1]->number()==t)    {      iColNum[t-1]=t1;      pc[t]=colList[t1];      t1=0;t++;    }    else t1++;    if(t1==numColumns) break;  }  maxVal=t-1;  // if none column is selected no sort.  if(!maxVal)  {    for(t=0;t<totRows;t++) itemShowList[t]=t;    repaint();    return;  }  columnSort=pc[1]->columnSort; c1=iColNum[0];  fmode=pc[1]->orderMode();  change=false;  for(n=0;n<totRows-1;n++)  {      result=columnSort(                     itemList[itemShowList[n]]->text(c1).data(),                     itemList[itemShowList[n+1]]->text(c1).data() );      if(result==0)      {        if(maxVal>=2 && recursiveSort(2,n,pc,iColNum))        {              itmp=itemShowList[n];              itemShowList[n]=itemShowList[n+1];              itemShowList[n+1]=itmp;              change=true;              if(n>0) n-=2;        }      }      else if((result<0 && fmode==Ascending) ||                (result>0 && fmode==Descending) )      {          itmp=itemShowList[n];          itemShowList[n]=itemShowList[n+1];          itemShowList[n+1]=itmp;          change=true;          if(n>0) n-=2;      }  }  //We need a repaint also if change==false!!! We must redraw the arrows!  if(change) repaint();  else QWidget::repaint();}//-----------------------------------------------------------------------------bool KTabListBox::recursiveSort(int level,int n,                                KTabListBoxColumn **pc,int *iCol){  int result;  result=pc[level]->columnSort(           itemList[itemShowList[n]]->text(iCol[level-1]).data(),           itemList[itemShowList[n+1]]->text(iCol[level-1]).data() );  if(result==0)    if(pc[level+1] && recursiveSort(level+1,n,pc,iCol))       return true;    else return false;  else    if(  (result<0 && pc[level]->orderMode()==Ascending) ||         (result>0 && pc[level]->orderMode()==Descending) )      return true;    else      return false;}//-----------------------------------------------------------------------------void KTabListBox::setColumn(int col, const char* aName, int aWidth,			  ColumnType aType, OrderType aOType,			  OrderMode aOMode,bool verticalLine,			  int (*compar)(const char *, const char *)){  if (col<0 || col>=numCols()) return;  setColumnWidth(col,aWidth);  colList[col]->setName(aName);  colList[col]->setType(aType);  colList[col]->setOrder(aOType,aOMode);  colList[col]->vline=verticalLine;  if(compar)    colList[col]->columnSort=compar;  else    colList[col]->columnSort=strcmp;  update();}//-----------------------------------------------------------------------------void KTabListBox::setCurrentItem(int idx, int colId){  int i;  if (idx>=numRows()) return;  unmarkAll();    if ( idx <= topItem() && idx < lbox.lastRowVisible() )      lbox.setTopCell( itemPosList(idx));  else if ( idx >= lbox.lastRowVisible() )      {	  int i = itemPosList(idx)+1;	  int y = 0;	  while (i) y += cellHeight(--i);	  y -= lbox.viewHeight();	  lbox.setYOffset( y );      }    if (idx != current)  {    i = current;    current = idx;    updateItem(i,FALSE);  }  if (current >= 0)  {    markItem(idx);    emit highlighted(current, colId);  }}//-----------------------------------------------------------------------------// This is an internal method...void KTabListBox::setCItem(int idx){  int i;  if (idx >= numRows() || idx < 0) return;  if (idx != current)  {    unmarkItem(current);    i = current;    current = idx;    updateItem(i,FALSE);  }  unmarkAll();  markItem(idx);}//-----------------------------------------------------------------------------bool KTabListBox::isMarked(int idx) const{  return (itemList[idx]->marked() >= -1);}//-----------------------------------------------------------------------------void KTabListBox::markItem(int idx, int colId){  if (itemList[idx]->marked()==colId) return;  itemList[idx]->setMarked(colId);  nMarked++;  updateItem(idx,FALSE);}//-----------------------------------------------------------------------------void KTabListBox::unmarkItem(int idx){  int mark;  mark = itemList[idx]->marked();  itemList[idx]->setMarked(-2);  if (mark>=-1)  {    nMarked--;    updateItem(idx);  }}//-----------------------------------------------------------------------------void KTabListBox::unmarkAll(void){  int i;  if(!nMarked) return;  for (i=numRows()-1; i>=0; i--)    unmarkItem(i);  nMarked=0;}//-----------------------------------------------------------------------------const QString& KTabListBox::text(int row, int col) const{  const KTabListBoxItem* item = getItem(row);  static QString str;  int i, cols;  if (!item)  {    str = 0L;    return str;  }  if (col >= 0) return item->text(col);  cols = item->columns - 1;  for (str="",i=0; i<=cols; i++)  {    str += item->text(i);    if (i<cols) str += sepChar;  }  return str;}//-----------------------------------------------------------------------------void KTabListBox::insertItem(const char* aStr, int row){  KTabListBoxItemPtr it;  int i, newSize;  if (row < 0) row = numRows();  if (numRows() >= maxItems)  {    newSize = (maxItems << 1);    if (newSize <= row) newSize = row+2;    resizeList(newSize);  }  it = itemList[numRows()];  if(row!=numRows())  {    for (i=numRows()-1; i>=row; i--)      itemList[i+1] = itemList[i];    for(i=0;i<numRows();i++) if(itemShowList[i]>=row) itemShowList[i]++;  }  itemList[row] = it;  itemShowList[row]=row;  if (itemPosList(current) >itemPosList(row))    current=itemShowList[itemPosList(current+1)];  setNumRows(numRows()+1);  changeItem(aStr, row);  reorderRows();  if (needsUpdate(row))      lbox.repaint();}//-----------------------------------------------------------------------------void KTabListBox::appendStrList( QStrList const *strLst ){  bool update;  uint i;  if (!strLst) return;  QStrListIterator it(*strLst);  update = autoUpdate();  setAutoUpdate(FALSE);  for (i=0; i<strLst->count(); i++)  {    insertItem(it.current());    ++it;  }  setAutoUpdate(update);  lbox.repaint();}//-----------------------------------------------------------------------------void KTabListBox::changeItem(const char* aStr, int row){  QString str;  char  sepStr[2];  char* pos;  int   i;  KTabListBoxItem* item;  if (row < 0 || row >= numRows()) return;  str = aStr;  str.detach();  sepStr[0] = sepChar;  sepStr[1] = '\0';  item = itemList[row];  pos = strtok(str.data(), sepStr);  for (i=0; pos && *pos && i<numCols(); i++)  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -