亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? tableview.cpp

?? 跨平臺(tái),多數(shù)據(jù)庫(kù)查看編輯和查詢工具,平臺(tái)支持windows,linux,數(shù)據(jù)庫(kù)支持oracle,odbc,mysql,slite等
?? CPP
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
#include "tableview.h"
#include "mysqltablemodel.h"
#include <QtSql>


MyDelegate::MyDelegate(QWidget *parent)
	:QSqlRelationalDelegate(parent)
{
}

MyDelegate::~MyDelegate()
{
}

QWidget *MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& item,
    const QModelIndex &index) const
{
	QWidget *editor=0;
	MySqlTableModel *model=qobject_cast<MySqlTableModel *>((QAbstractItemModel * )index.model());
	QList<QPair<QString, QString> > list;
  QPair<QString, QString> pair;
  list=model->mapValues.value(index.column());
  if(list.size()>0)
  {
    DataComboBox *comboBox = new DataComboBox(parent);
    if(comboBox)
    {
  	  foreach(pair,list)
  	  {
    		//qWarning("%s\t%s",pair.first.toLatin1().data(),pair.second.toLatin1().data());
  		  comboBox->addItem(pair.second,pair.first);
  	  }
  	  editor=comboBox;
    }
  }
  else
  {
	  editor=QSqlRelationalDelegate::createEditor(parent, item,index);	  
	  if(editor && model)
	  {
  		QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
  		TableView *tv=qobject_cast<TableView *>(this->parent());
		  if(edit && tv && tv->isPasswordColumn(model->record().field(index.column()).name()))
		     edit->setEchoMode(QLineEdit::Password);
	  }
  }	
	return editor;
}
	

void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    QSqlRelationalDelegate::setEditorData(editor,index);
    QString text=index.model()->data(index).toString().trimmed();
    
    MySqlTableModel *model=qobject_cast<MySqlTableModel *>((QAbstractItemModel * )index.model());
    DataComboBox *comboBox=qobject_cast<DataComboBox *>(editor);
    if(comboBox && model)
    {
    	comboBox->setCurrentIndex(comboBox->findData(QVariant(text)));    	
    }
    int nAlign=index.model()->headerData(index.column(),Qt::Horizontal,Qt::UserRole).toInt();
    QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
    if (edit) 
    {        
        edit->setText(text);
        if(nAlign&Qt::AlignRight)
        	edit->setAlignment(Qt::AlignRight);
    }        
}

void MyDelegate::setModelData ( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const
{	
    MySqlTableModel *tableModel=qobject_cast<MySqlTableModel *>((QAbstractItemModel * )model);
    DataComboBox *comboBox=qobject_cast<DataComboBox *>(editor);
    if(comboBox && tableModel)
    {
    	QString text=comboBox->itemData(comboBox->currentIndex()).toString();
    	tableModel->setData(index,QVariant(text));
    }
    else
    	QSqlRelationalDelegate::setModelData(editor,model,index);
	
}

QSize MyDelegate::sizeHint(const QStyleOptionViewItem &option,
                                    const QModelIndex &index) const
{
  MySqlTableModel *model=qobject_cast<MySqlTableModel *>((QAbstractItemModel * )index.model());
  //DataComboBox *comboBox=qobject_cast<DataComboBox *>(editor);
  if(model)
  {
 		QList<QPair<QString, QString> > list;
    QPair<QString, QString> pair;
    list=model->mapValues.value(index.column());
    QString text = index.data(Qt::DisplayRole).toString();
    foreach(pair,list)
    {
    	if(text==pair.first)
    	{
    		text=pair.second;
    		break;
    	}
    }
    QFont font(option.font);
    font.setPointSize(QFontInfo(font).pointSize() * 3/2);
    QFontMetrics fontMetrics(font);
    return QSize(fontMetrics.width(text), fontMetrics.lineSpacing());
  }
  else
  	return(QSqlRelationalDelegate::sizeHint(option,index));
}


void MyDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const 
{	
	  MySqlTableModel *model=qobject_cast<MySqlTableModel *>((QAbstractItemModel * )index.model());
	  TableView *tv=qobject_cast<TableView *>(this->parent());

		painter->save();
		const QRect rect=option.rect;
		const QPalette palette=option.palette;

//qWarning(index.model()->headerData(index.column(),Qt::Horizontal).toString().toLatin1().data());
	if(tv && tv->isPasswordColumn(index.model()->headerData(index.column(),Qt::Horizontal).toString()))
	{
		QString password=index.data().toString();
    QString star;    
    star.fill('*',8);
    
    if(option.state & QStyle::State_Selected )
    {
    	QPen pen=QPen(palette.highlightedText().color());
    	painter->setPen(pen);
    	painter->fillRect(rect,palette.highlight());
    	
    }
    QRect r=rect;
    r.setLeft(r.left()+2);
    painter->drawText(r,star,Qt::AlignVCenter|Qt::AlignCenter);     

    
    
	}		
	else if(model)
	{
    
    QString text;//=index.data(Qt::ToolTipRole).toString();
    //if(text.isNull() || text.isEmpty() || text.length()==0)
    text=index.data().toString();
    QIcon icon=qVariantValue<QIcon>(index.model()->headerData(index.column(),Qt::Horizontal,Qt::DecorationRole));
    int fieldType=index.model()->headerData(index.column(),Qt::Horizontal,Qt::ToolTipRole).toInt();
 	  
    if(option.state & QStyle::State_Selected )
    {
   		QPen pen=QPen(palette.highlightedText().color());
   		painter->setPen(pen);
    	painter->fillRect(rect,palette.highlight());
    }
    else
    {
    	if(fieldType==1)   //key列
    	{
    		QFont font=option.font;
    		font.setBold(true);
    		QPen pen=QPen(QColor(0,0,250));
    		painter->setPen(pen);
    		//painter->setFont(font);
    	}
    	
    }
    int nAlign=index.model()->headerData(index.column(),Qt::Horizontal,Qt::UserRole).toInt();
   	QVariant::Type t = static_cast<QVariant::Type>(index.data(Qt::EditRole).userType());	

    QRect r=rect;
    
    
    //顯示關(guān)系表的關(guān)系列
    QString str="(NULL)";
	  QList<QPair<QString, QString> > list;
    QPair<QString, QString> pair;
    list=model->mapValues.value(index.column());
    if(list.size()>0)
  	{
    	foreach(pair,list)
    	{
    		if(pair.first==text)
    		{
    			str=pair.second;
    			break;
    		}
    	}
    	r.setLeft(r.left()+2);
	    painter->drawText(r,str,Qt::AlignLeft | Qt::AlignVCenter);     	
    }
    else    
    {
   	    if(nAlign&Qt::AlignRight  ||t==QVariant::Double||t==QVariant::Int||t==QVariant::UInt||t==QVariant::LongLong||t==QVariant::ULongLong)
        {
          r.setRight(r.right()-2);
          if(text.toDouble()<0)
          {
    		    QPen pen=QPen(QColor(250,0,0));
    		    painter->setPen(pen);
          }
        }
       else
    	   r.setLeft(r.left()+2);

    	painter->drawText(r,text,(Qt::Alignment)nAlign | Qt::AlignVCenter);     	
    }
	}
	else
		QSqlRelationalDelegate::paint(painter,option,index);

  if(option.state & QStyle::State_HasFocus )
    drawFocus(painter,option,rect);
	painter->restore();
	
		
	
}

TableView::TableView(QWidget *parent )
	:QTableView(parent)
{
	
	filterDlg=0;
	findDlg=0;
	
	setAlternatingRowColors(true);
	setContextMenuPolicy(Qt::ActionsContextMenu);
	setMinimumWidth(400);

	QSettings settings(qApp->applicationName(), "dbmanager");
	QString text = settings.value("xh", "password,passwd,mm,口令,密碼").toString();
	passwordColumnList=text.split(",");

	
	actCommit = new QAction(tr("保存"),this);	
	actCommit->setIcon(QIcon(":/image/save.png"));
	connect(actCommit,SIGNAL(triggered()),this,SLOT(commit()));

	actDeleteRow = new QAction(tr("刪除行"),this);
	actDeleteRow->setIcon(QIcon(":/image/delete.png"));
	connect(actDeleteRow,SIGNAL(triggered()),this,SLOT(deleteRow()));
	
	actInsertRow = new QAction("插入行",this);
	actInsertRow->setIcon(QIcon(":/image/insert.png"));
	connect(actInsertRow,SIGNAL(triggered()),this,SLOT(insertRow()));

	
	actAppendRow = new QAction("追加行",this);
	actAppendRow->setIcon(QIcon(":/image/append.png"));
	connect(actAppendRow,SIGNAL(triggered()),this,SLOT(appendRow()));	
	
	actRollback = new QAction ("撤消",this);
	actRollback->setIcon(QIcon(":/image/rollback.png"));
	connect(actRollback,SIGNAL(triggered()),this,SLOT(rollback()));
	
	actFilter=new QAction(QIcon(":/image/filter.png"),"設(shè)置過(guò)濾條件...",this);	
	connect(actFilter,SIGNAL(triggered()),this,SLOT(setFilter()));

	actFind=new QAction(QIcon(":/image/find.png"),"查找...",this);	
	actFind->setEnabled(false);
	actFind->setShortcut(QKeySequence::Find);
	connect(actFind,SIGNAL(triggered()),this,SLOT(showFind()));
	
	actClose=new QAction(QIcon(":/image/close.png"),"關(guān)閉當(dāng)前表",this);	
	actClose->setEnabled(false);
	connect(actClose,SIGNAL(triggered()),this,SLOT(closeTable()));
	
	actRetrieveAll=new QAction(QIcon(":/image/retrieveall.png"),"檢索所有記錄",this);	
	connect(actRetrieveAll,SIGNAL(triggered()),this,SLOT(retrieveAll()));
		
	
	
	actCopy=new QAction(QIcon(":/image/copy.png"),"復(fù)制選中內(nèi)容",this);	
	actCopy->setShortcut(QKeySequence::Copy);
	connect(actCopy,SIGNAL(triggered()),this,SLOT(copy()));	

	actSave=new QAction(QIcon(":/image/savefile.png"),"保存選中內(nèi)容為文件...",this);	
	actSave->setShortcut(tr("Ctrl+S"));
	connect(actSave,SIGNAL(triggered()),this,SLOT(save()));

	actPrint=new QAction(QIcon(":/image/printer.png"),"打印...",this);	
	actPrint->setShortcut(tr("Ctrl+P"));
	connect(actPrint,SIGNAL(triggered()),this,SLOT(print()));
	
  
  QAction *action=new QAction(this);
  action->setSeparator(true);
  addAction(actRetrieveAll);
  addAction(actClose);	  
  addAction(action);
  addAction(actSave);
  addAction(actCopy);
  action=new QAction(this);
  action->setSeparator(true);
  addAction(action);
  addAction(actInsertRow);	
	addAction(actAppendRow);
	addAction(actDeleteRow);
  action=new QAction(this);
  action->setSeparator(true);
  addAction(action);
	addAction(actCommit);
	addAction(actRollback);
	action=new QAction(this);
  action->setSeparator(true);
	addAction(action);
	addAction(actFilter);
	addAction(actFind);
	addAction(actPrint);
	enableAction(false);
	
	horizontalHeader()->setSortIndicatorShown(true);
	connect(this->horizontalHeader(),SIGNAL(sortIndicatorChanged (int, Qt::SortOrder)),this,SLOT(onSortIndicatorChanged ( int, Qt::SortOrder)));
	
	MyDelegate *delegate=new MyDelegate(this);
	setItemDelegate(delegate); 	


}
TableView::~TableView()
{
	QAbstractItemModel * m=model();
	MySqlTableModel *model=qobject_cast<MySqlTableModel *>(m);
	if(!model)
			return;
	
	if(model)	
	{
		try
		{
		model->save();	
		delete model;
	  }
	  catch(...){}
	
	  //closeTable();
	}


}

void TableView::deleteRow()
{
		if(!model())
		return;
		
    QAbstractItemModel * m=model();
		MySqlTableModel *model=qobject_cast<MySqlTableModel *>(m);
		if(!model)
			return;

	int ret = QMessageBox::question(this, tr("數(shù)據(jù)庫(kù)管理"),
		tr("是否確定要?jiǎng)h除此行?.\n"),
		QMessageBox::Yes | QMessageBox::No);
	QModelIndexList currentSelection = selectionModel()->selectedIndexes();
	
	if (ret == QMessageBox::Yes)
	{
		QModelIndexList currentSelection = selectionModel()->selectedIndexes();
		QMap <int,QModelIndex> map;    
		foreach (QModelIndex index,currentSelection) 
			map[index.row()]=index;        

		QList <int > listRows=map.keys();
		qSort(listRows.begin(), listRows.end(), qGreater<int>());
		foreach(int row,listRows)
		model->removeRow(row);
		model->save();
		resizeColumnsToContents ();
	  resizeRowsToContents ();		
	}
}

void TableView::insertRow()
{
	if(!model())
		return;
		QAbstractItemModel * m=model();
	MySqlTableModel *model=qobject_cast<MySqlTableModel *>(m);
	if(!model)
			return;


	QModelIndex insertIndex = currentIndex();
	int row = insertIndex.row() == -1 ? 0 : insertIndex.row();
	model->insertRow(row);
	insertIndex = model->index(row, 0);
	setCurrentIndex(insertIndex);
	edit(insertIndex);

}
void TableView::appendRow()
{
		if(!model())
		return;
    QAbstractItemModel * m=model();
		MySqlTableModel *model=qobject_cast<MySqlTableModel *>(m);
	if(!model)
			return;

	model->insertRow(model->rowCount());
	QModelIndex insertIndex  = model->index(model->rowCount()-1, 0);
	setCurrentIndex(insertIndex);
	edit(insertIndex);

}
void TableView::rollback()
{
		if(!model())
		return;
		QAbstractItemModel * m=model();
		MySqlTableModel *model=qobject_cast<MySqlTableModel *>(m);
	if(!model)
			return;
		
	model->cancel();
	if(model->database().driver() && model->database().driver()->hasFeature(QSqlDriver::Transactions))
	{
		model->database().rollback();
		model->database().transaction();
	}

	resizeColumnsToContents ();
	resizeRowsToContents ();

}

void TableView::commit()
{
		if(!model())
		return;
		QAbstractItemModel * m=model();
		MySqlTableModel *model=qobject_cast<MySqlTableModel *>(m);
	if(!model)
			return;
		
	if(!model->save())
		QMessageBox::warning(this,"錯(cuò)誤",model->lastError().text());  	
	else
	{
		if(model->database().driver() && model->database().driver()->hasFeature(QSqlDriver::Transactions))
		{
		model->database().commit();
		model->database().transaction();
		}
		
	}
	resizeColumnsToContents ();
	resizeRowsToContents ();

}



?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人黄色电影在线| 色狠狠桃花综合| 亚洲一区二区在线观看视频| 日韩一区二区在线免费观看| 成人黄页毛片网站| 麻豆精品一区二区综合av| 亚洲色图一区二区三区| 日韩欧美的一区| 欧美视频三区在线播放| 成人永久aaa| 久久99九九99精品| 亚洲成av人在线观看| 国产精品国产三级国产a | 欧美一区二区三区成人| 99久久婷婷国产综合精品| 国产在线视频精品一区| 首页亚洲欧美制服丝腿| 亚洲精品大片www| 亚洲欧洲av色图| 2021久久国产精品不只是精品| 欧美日韩在线精品一区二区三区激情| 东方aⅴ免费观看久久av| 久久99久久99小草精品免视看| 亚洲国产精品久久人人爱| 亚洲欧美日韩一区| 国产精品女上位| 亚洲国产精品黑人久久久| 亚洲精品在线免费观看视频| 日韩欧美中文字幕精品| 欧美电影在线免费观看| 欧美撒尿777hd撒尿| 在线精品视频一区二区三四| 色88888久久久久久影院野外| 99国产一区二区三精品乱码| 成人av中文字幕| 成人涩涩免费视频| 成人夜色视频网站在线观看| 国产精品一区2区| 国产成人在线视频网站| 欧美亚洲国产一区在线观看网站| 色久综合一二码| 在线观看国产91| 欧美日韩精品欧美日韩精品| 欧洲视频一区二区| 欧美日韩中字一区| 91精品国产91热久久久做人人 | 9i看片成人免费高清| 国产成人精品免费| 成人动漫视频在线| 日本伦理一区二区| 69久久99精品久久久久婷婷| 欧美精品视频www在线观看| 91精品国产91久久综合桃花 | 亚洲精品视频一区二区| 亚洲综合视频在线| 日韩经典中文字幕一区| 久久精品免费看| 国产成人精品三级| 91热门视频在线观看| 欧美三级视频在线播放| 日韩一区二区三区视频在线 | 亚洲免费在线播放| 免费一区二区视频| 国产成人在线观看免费网站| 9久草视频在线视频精品| 欧美三级资源在线| 亚洲精品一线二线三线| 国产精品久线在线观看| 亚洲高清免费一级二级三级| 久久99国产精品尤物| 成人h动漫精品一区二| 欧美午夜不卡在线观看免费| 欧美一级高清片| 国产精品久久久久天堂| 性欧美疯狂xxxxbbbb| 国产一区二区精品久久91| 91老师国产黑色丝袜在线| 欧美日本一区二区| 欧美国产精品一区二区| 亚洲va中文字幕| 国产成a人亚洲精品| 欧美色手机在线观看| 久久人人超碰精品| 亚洲成人一区二区在线观看| 国产盗摄女厕一区二区三区| 欧美在线免费播放| 国产亚洲精品中文字幕| 天天av天天翘天天综合网色鬼国产| 国产在线看一区| 欧美日韩五月天| 国产精品日韩成人| 美女视频第一区二区三区免费观看网站| 成人综合在线网站| 日韩午夜在线影院| 亚洲一区二区成人在线观看| 26uuu精品一区二区| 91蜜桃免费观看视频| 2023国产精品视频| 亚洲五码中文字幕| 成人免费毛片嘿嘿连载视频| 欧美一区二区三区在线观看| 亚洲男人天堂av| 高清不卡一二三区| 日韩一区二区三区高清免费看看| 亚洲日本va午夜在线电影| 激情都市一区二区| 3d成人动漫网站| 亚洲九九爱视频| 成人av在线播放网站| 久久综合九色综合97婷婷女人 | 亚洲一区二区三区四区五区黄| 国产成人自拍网| 精品国产乱码久久久久久久久 | 欧美精品一二三| 亚洲欧美电影院| 成人永久免费视频| 久久久久99精品一区| 久久精品国产第一区二区三区| 欧美视频一二三区| 一区二区三区av电影| 97久久精品人人爽人人爽蜜臀| 久久精品人人做人人综合 | 色呦呦日韩精品| 国产精品系列在线| 国产成人午夜99999| 精品美女在线播放| 捆绑调教一区二区三区| 91精品国产欧美一区二区成人| 丝袜脚交一区二区| 欧美日韩黄视频| 午夜精品在线视频一区| 精品1区2区3区| 午夜一区二区三区在线观看| 欧美日韩一级片网站| 婷婷综合久久一区二区三区| 欧美性猛交xxxx黑人交| 亚洲国产视频在线| 欧美嫩在线观看| 老司机精品视频导航| 精品国产乱码久久久久久影片| 国内不卡的二区三区中文字幕 | 成人开心网精品视频| 国产精品女同一区二区三区| 不卡视频在线看| 日韩毛片精品高清免费| 在线观看免费一区| 污片在线观看一区二区| 国产精品午夜在线观看| 91麻豆免费视频| 亚洲国产成人高清精品| 欧美一级二级在线观看| 国产一区二区精品久久91| 国产精品网站在线播放| 色综合欧美在线视频区| 亚洲成人在线网站| 精品国产一区二区三区久久影院| 国产综合色在线视频区| 国产精品久久久久久久久免费樱桃 | 国产网站一区二区三区| 不卡欧美aaaaa| 亚洲一级电影视频| 欧美一区二区三区四区五区| 国内不卡的二区三区中文字幕| 国产精品国产三级国产普通话蜜臀 | 欧美一区二区三区四区在线观看 | 欧美成人在线直播| 国产呦萝稀缺另类资源| 亚洲欧洲av在线| 欧美久久久久久久久中文字幕| 日本中文字幕一区二区视频| 国产人成亚洲第一网站在线播放 | 奇米在线7777在线精品| 久久久不卡网国产精品二区| 一本在线高清不卡dvd| 日本伊人色综合网| 中文字幕欧美国产| 欧美日韩的一区二区| 国产成人精品综合在线观看| 亚洲综合在线观看视频| 欧美电视剧在线看免费| 91丝袜美腿高跟国产极品老师 | 亚洲成人动漫av| 中文一区二区完整视频在线观看| 欧美日韩不卡一区二区| 国产一区二区三区免费看 | 亚洲色图色小说| 日韩欧美一级二级三级久久久| 成人午夜电影小说| 日韩国产精品大片| 亚洲三级在线免费| 日韩精品中文字幕在线不卡尤物 | 中文字幕乱码久久午夜不卡 | 国产精品一区免费视频| 亚洲综合偷拍欧美一区色| 久久精品无码一区二区三区| 欧美日本乱大交xxxxx| 91欧美一区二区| 国产精品一区二区91| 久久精品国产久精国产| 亚洲不卡av一区二区三区|