kexi
kexifieldlistview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexifieldlistview.h"
00021
00022 #include <qheader.h>
00023 #include <qlayout.h>
00024 #include <qlabel.h>
00025 #include <qpushbutton.h>
00026 #include <qcursor.h>
00027 #include <qpoint.h>
00028 #include <qapplication.h>
00029 #include <qbitmap.h>
00030 #include <qstyle.h>
00031
00032 #include <kdebug.h>
00033 #include <kiconloader.h>
00034 #include <kdeversion.h>
00035 #include <kconfig.h>
00036 #include <kglobalsettings.h>
00037 #include <klocale.h>
00038
00039 #include <kexidb/tableschema.h>
00040 #include <kexidb/queryschema.h>
00041 #include <kexidb/utils.h>
00042 #include <kexidragobjects.h>
00043
00044 KexiFieldListView::KexiFieldListView(QWidget *parent, const char *name, int options)
00045 : KListView(parent, name)
00046 , m_schema(0)
00047 , m_options(options)
00048 {
00049 m_keyIcon = SmallIcon("key");
00050 m_noIcon = QPixmap(m_keyIcon.size());
00051 QBitmap bmp(m_noIcon.size());
00052 bmp.fill(Qt::color0);
00053 m_noIcon.setMask(bmp);
00054
00055 setAcceptDrops(true);
00056 viewport()->setAcceptDrops(true);
00057 setDropVisualizer(false);
00058 setDropHighlighter(true);
00059 setAllColumnsShowFocus(true);
00060 addColumn(i18n("Field Name"));
00061 if (m_options & ShowDataTypes)
00062 addColumn(i18n("Data Type"));
00063 if (m_options & AllowMultiSelection)
00064 setSelectionMode(QListView::Extended);
00065 setResizeMode(QListView::LastColumn);
00066
00067 setSorting(-1, true);
00068 setDragEnabled(true);
00069 }
00070
00071 KexiFieldListView::~KexiFieldListView()
00072 {
00073 delete m_schema;
00074 }
00075
00076 void KexiFieldListView::setSchema(KexiDB::TableOrQuerySchema* schema)
00077 {
00078 if (schema && m_schema == schema)
00079 return;
00080 clear();
00081 delete m_schema;
00082 m_schema = schema;
00083 if (!m_schema)
00084 return;
00085
00086 int order=0;
00087 bool hasPKeys = true;
00088 KListViewItem *item = 0;
00089 KexiDB::QueryColumnInfo::Vector columns = m_schema->columns(true );
00090 const int count = columns.count();
00091 for(int i=-1; i < count; i++)
00092 {
00093 KexiDB::QueryColumnInfo *colinfo = 0;
00094 if (i==-1) {
00095 if (! (m_options & ShowAsterisk))
00096 continue;
00097 item = new KListViewItem(this, item, "*");
00098 }
00099 else {
00100 colinfo = columns[i];
00101 item = new KListViewItem(this, item, colinfo->aliasOrName());
00102 if (m_options & ShowDataTypes)
00103 item->setText(1, colinfo->field->typeName());
00104 }
00105 if(colinfo && (colinfo->field->isPrimaryKey() || colinfo->field->isUniqueKey()))
00106 item->setPixmap(0, m_keyIcon);
00107 else if (hasPKeys) {
00108 item->setPixmap(0, m_noIcon);
00109 }
00110 order++;
00111 }
00112
00113 setCurrentItem(firstChild());
00114 }
00115
00116 #if 0
00117 QSize KexiFieldListView::sizeHint()
00118 {
00119 QFontMetrics fm(font());
00120
00121 kdDebug() << m_table->name() << " cw=" << columnWidth(1) + fm.width("i") << ", " << fm.width(m_table->name()+" ") << endl;
00122
00123 QSize s(
00124 QMAX( columnWidth(1) + fm.width("i"), fm.width(m_table->name()+" ")),
00125 childCount()*firstChild()->totalHeight() + 4 );
00126
00127 return s;
00128 }
00129
00130 void KexiFieldListView::setReadOnly(bool b)
00131 {
00132 setAcceptDrops(!b);
00133 viewport()->setAcceptDrops(!b);
00134 }
00135 #endif
00136
00137 QDragObject* KexiFieldListView::dragObject()
00138 {
00139 QStringList selectedFields;
00140 for (QListViewItemIterator it(this); it.current(); ++it) {
00141 if (it.current()->isSelected()) {
00143 selectedFields.append(it.current()->text(0));
00144 }
00145 }
00146 return new KexiFieldDrag(m_schema->table() ? "kexi/table" : "kexi/query",
00147 m_schema->name(), selectedFields, this, "KexiFieldDrag");
00148
00149
00150
00151
00152
00153 }
00154
00155 #include "kexifieldlistview.moc"
|