붙여넣기 기능 추가

git-svn-id: svn://192.168.0.12/source@42 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2015-03-12 03:21:43 +00:00
parent eb3639da70
commit 5f3b31a1aa
4 changed files with 59 additions and 33 deletions

View File

@@ -18,4 +18,5 @@ SOURCES += main.cpp\
HEADERS += widget.h \
stable.h \
../Json/sjson.h
../Json/sjson.h \
../common.h

View File

@@ -30,29 +30,9 @@ void STable::keyPressEvent(QKeyEvent* event)
{
// If Ctrl-C typed
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
{
QModelIndexList cells = selectedIndexes();
//qSort(cells);
QString text;
int currentRow = 0;
foreach (const QModelIndex& cell, cells)
{
if (text.length() == 0)
{
}
else if (cell.row() != currentRow)
text += '\n';
else
text += '\t';
currentRow = cell.row();
text += cell.data().toString();
}
QApplication::clipboard()->setText(text);
}
Copy();
if (event->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier))
{
Paste();
}
}
void STable::menuInsert()
@@ -92,6 +72,27 @@ void STable::CellClick(int nRow,int nPrev)
repaint();
}
void STable::Copy()
{
QModelIndexList cells = selectedIndexes();
//qSort(cells);
QString text;
int currentRow = 0;
foreach (const QModelIndex& cell, cells)
{
if (text.length() == 0)
{
}
else if (cell.row() != currentRow)
text += '\n';
else
text += '\t';
currentRow = cell.row();
text += cell.data().toString();
}
QApplication::clipboard()->setText(text);
}
void STable::Paste()
{
//if(qApp->clipboard()->mimeData()->hasHtml())
@@ -100,19 +101,41 @@ void STable::Paste()
}
//else
{
/*
QString selected_text = qApp->clipboard()->text();
QStringList cells = selected_text.split(QRegExp(QLatin1String("\\n|\\t")));
int cell = 0;
for(int row=0; row < rows; ++row)
QModelIndexList cells = selectedIndexes();
qSort(cells);
if (cells.size() == 0) return;
QString str = QApplication::clipboard()->text();
QStringList strRows = str.split("\n");
if (strRows.size() == 0) return;
int nStartRow = cells.at(0).row();
int nStartCol = cells.at(0).column();
int nRows = strRows.size();
{
for(int col=0; col < cols; ++col, ++cell)
{
QTableWidgetItem *newItem = new QTableWidgetItem(cells[cell]);
setItem(row, col, newItem);
}
int nPlusRow = nStartRow + nRows - rowCount();
if (nPlusRow > 0)
setRowCount(rowCount()+nPlusRow);
}
int nRow = nStartRow;
foreach(QString strRow,strRows)
{
QStringList strCols = strRow.split("\t");
int nCol = nStartCol;
foreach(QString strCol,strCols)
{
if (nCol >= columnCount()) continue;
QTableWidgetItem *pItem;
if (nRows >= nRows)
pItem = new QTableWidgetItem;
else
pItem = item(nRow,nCol);
pItem->setText(" "+strCol.trimmed()+" ");
setItem(nRow,nCol,pItem);
nCol++;
}
nRow++;
}
*/
}
}

View File

@@ -20,6 +20,7 @@ public:
void SetHeaderList(QVector <QStringList> *_vecColumn,int _nColumn);
void setArticleSelect(int _nArticle){m_nArticle = _nArticle;}
int getArticleSelect(){return m_nArticle;}
void Copy();
void Paste();
private:
int m_nArticle;

View File

@@ -12,6 +12,7 @@
#include <QMenuBar>
#include <QInputDialog>
#include "../Json/sjson.h"
#include "../common.h"
/*
QSqlDatabase dbWeb = QSqlDatabase::addDatabase("QMYSQL");