Source Code (Use browser search to find items of interest.)

Class Index

qt'QHeaderData (./qt-2.1.0/src/widgets/qheader.cpp:38)

struct QHeaderData
{
    QHeaderData(int n)
    {
	count = n;
	labels.setAutoDelete( TRUE );
	iconsets.setAutoDelete( TRUE );
	sizes.resize(n);
	positions.resize(n);
	heights.resize(n);
	labels.resize(n);
	if ( int( iconsets.size() ) < n )
	    iconsets.resize( n );
	i2s.resize(n);
	s2i.resize(n);
	clicks.resize(n);
	resize.resize(n);
	int p =0;
	for ( int i = 0; i < n ; i ++ ) {
	    sizes[i] = 88;
	    // heights[i] = 10; set properly in QHeader::init()
	    i2s[i] = i;
	    s2i[i] = i;
	    positions[i] = p;
	    p += sizes[i];
	}
	clicks_default = TRUE;
	resize_default = TRUE;
	clicks.fill( clicks_default );
	resize.fill( resize_default );
	move = TRUE;
	sortColumn = -1;
	sortDirection = TRUE;
    }
    

    QArray<QCOORD>	sizes;
    QArray<QCOORD>	heights;
    QArray<QCOORD>	positions; // sorted by index
    QVector<QString>	labels;
    QVector<QIconSet>	iconsets;
    QArray<int>	        i2s;
    QArray<int>	        s2i;

    QBitArray           clicks;
    QBitArray           resize;
    uint move : 1;
    uint clicks_default : 1; // default value for new clicks bits
    uint resize_default : 1; // default value for new resize bits
    bool sortDirection;
    int sortColumn;
    int count;
    
    
    void calculatePositions(){
	// positions is sorted by index, not by section
	int p = 0;
	for ( int i = 0; i < count; i++ ) {
	    positions[i] = p;
	    p +=sizes[i2s[i]];
	}
    }
    int sectionAt( int pos ) {
	// positions is sorted by index, not by section
	if ( !count ) 
	    return -1;
	int l = 0;
	int r = count - 1;
	int i = ( (l+r+1) / 2 );
	while ( r - l ) {
	    if ( positions[i] > pos )
		r = i -1;
	    else
		l = i;
	    i = ( (l+r+1) / 2 );
	}
	if ( positions[i] <= pos && pos <= positions[i] + sizes[ i2s[i] ] )
	    return i2s[i];
	return -1;
    }
};


// BEING REVISED: eiriken
/*!
  \class QHeader qheader.h
  \brief The QHeader class provides a table header.
  \ingroup advanced

  This class provides a table header as known from Spreadsheet-like
  widgets. QHeader can be used vertically or horizontally (see setOrientation()).

  With addLabel() you can add sections, and with removeLabel() you can remove
  them. If you enabled clicking for one or all sections (see setClickEnabled()),
  the user can reorder the sections and click on them which may be used for
  sorting (see also setSortIndicator()). This feature is turned on by default.

  So, if the user reorders the sections by clicking and moving them with the mouse the index
  of a section may change. This means, the section you inserted at the first
  position might be displayed at a different index then. To get the index at which e.g
  the first section is displayed, use mapToIndex() with 0 as argument for our example.

  If you want e.g. to know which section is displayed at e.g. index 3 use
  mapToSection() with 3 as argument.

  So, you can always work with the section numbers as you inserted them
  without caring about the index at which they are displayed at the moment. Also
  the API of QHeader works with the section numbers.

  <img src=qheader-m.png> <img src=qheader-w.png>

  \sa QListView QTableView
 */



/*!
  Constructs a horizontal header.

  The \e parent and \e name arguments are sent to the QWidget constructor.
*/


qt'QHeaderData::sectionAt() (./qt-2.1.0/src/widgets/qheader.cpp:100)

    int sectionAt( int pos ) {
	// positions is sorted by index, not by section
	if ( !count ) 
	    return -1;
	int l = 0;
	int r = count - 1;
	int i = ( (l+r+1) / 2 );
	while ( r - l ) {
	    if ( positions[i] > pos )
		r = i -1;
	    else
		l = i;
	    i = ( (l+r+1) / 2 );
	}
	if ( positions[i] <= pos && pos <= positions[i] + sizes[ i2s[i] ] )
	    return i2s[i];
	return -1;
    }
};


// BEING REVISED: eiriken
/*!
  \class QHeader qheader.h
  \brief The QHeader class provides a table header.
  \ingroup advanced

  This class provides a table header as known from Spreadsheet-like
  widgets. QHeader can be used vertically or horizontally (see setOrientation()).

  With addLabel() you can add sections, and with removeLabel() you can remove
  them. If you enabled clicking for one or all sections (see setClickEnabled()),
  the user can reorder the sections and click on them which may be used for
  sorting (see also setSortIndicator()). This feature is turned on by default.

  So, if the user reorders the sections by clicking and moving them with the mouse the index
  of a section may change. This means, the section you inserted at the first
  position might be displayed at a different index then. To get the index at which e.g
  the first section is displayed, use mapToIndex() with 0 as argument for our example.

  If you want e.g. to know which section is displayed at e.g. index 3 use
  mapToSection() with 3 as argument.

  So, you can always work with the section numbers as you inserted them
  without caring about the index at which they are displayed at the moment. Also
  the API of QHeader works with the section numbers.

  <img src=qheader-m.png> <img src=qheader-w.png>

  \sa QListView QTableView
 */



/*!
  Constructs a horizontal header.

  The \e parent and \e name arguments are sent to the QWidget constructor.
*/