#include <QPixmap>
#include <QApplication>
#include <QFont>
+#include <QItemSelection>
+#include <QItemSelectionModel>
/*!
Constructor
{
myModel = theModel;
myTable = new QtxTable( this );
+ connect( myTable->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&,
+ const QItemSelection& ) ), this, SLOT( selectionChanged() ) );
//myTable->setReadOnly( true );
setCentralWidget( myTable );
resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ),
tr( "TIP_COPY" ), tr( "PRP_COPY" ) );
+ createAction( PasteId, tr( "MEN_PASTE" ),
+ resMgr->loadPixmap( "STD", tr( "ICON_EDIT_PASTE" ) ),
+ tr( "TIP_PASTE" ), tr( "PRP_PASTE" ) );
+
createAction( PrintId, tr( "MEN_PRINT" ),
resMgr->loadPixmap( "STD", tr( "ICON_PRINT" ) ),
tr( "TIP_PRINT" ), tr( "PRP_PRINT" ) );
return aTxt;
}
-QString TableViewer_ViewWindow::image( const ContentType type, const int row, const int col ) const
+QString TableViewer_ViewWindow::image( const ContentType, const int, const int ) const
{
return "";
}
-int TableViewer_ViewWindow::fontFlags( const ContentType type, const int row, const int col ) const
+QFont TableViewer_ViewWindow::font( const ContentType type, const int row, const int col ) const
{
- int aFlags = 0;
QFont aFont = myTable->font();
switch ( type ) {
case VerticalHeader:
default:
break;
}
+ return aFont;
+}
+
+int TableViewer_ViewWindow::fontFlags( const ContentType type, const int row, const int col ) const
+{
+ int aFlags = 0;
+ QFont aFont = font( type, row, col );
if ( aFont.bold() )
aFlags |= HTMLService_HTMLText::Bold;
if ( aFont.italic() )
aFlags |= HTMLService_HTMLText::Underline;
if ( aFont.strikeOut() )
aFlags |= HTMLService_HTMLText::StrikeOut;
- //Subscript
+ // 'Subscript' type is absent for export in HTML file
return aFlags;
}
{
myToolBar->addAction( myActionsMap[DumpId] );
myToolBar->addAction( myActionsMap[CopyId] );
+ myToolBar->addAction( myActionsMap[PasteId] );
myToolBar->addAction( myActionsMap[PrintId] );
myToolBar->addAction( myActionsMap[ExportId] );
}
case ExportId:
exportData();
break;
+ case CopyId:
+ copyData();
+ break;
+ case PasteId:
+ pasteData();
+ break;
+ default:
+ break;
}
}
return a;
}
+void TableViewer_ViewWindow::selectionChanged()
+{
+ bool anEnable = myTable->getSelectedIndexes().count() > 0;
+ myActionsMap[CopyId]->setEnabled( anEnable );
+ myActionsMap[PasteId]->setEnabled( anEnable & myCopyLst.count() > 0 );
+}
+
void TableViewer_ViewWindow::onActivated()
{
const QObject* obj = sender();
QApplication::restoreOverrideCursor();
}
+void TableViewer_ViewWindow::copyData()
+{
+ QModelIndexList anItems = myTable->getSelectedIndexes();
+ if ( anItems.count() <= 0 )
+ return;
+ int aLeftCol = myTable->columnCount(), aTopRow = myTable->rowCount();
+ QModelIndexList::const_iterator anIt = anItems.begin(), aLast = anItems.end();
+ int aRow, aCol;
+ for ( ; anIt != aLast; ++anIt ) {
+ aRow = (*anIt).row();
+ aCol = (*anIt).column();
+ if ( !canPaste( aRow, aCol, "" ) )
+ continue;
+ if ( aCol < aLeftCol )
+ aLeftCol = aCol;
+ if ( aRow < aTopRow )
+ aTopRow = aRow;
+ }
+ myCopyLst.clear();
+ TableDataItem aCopyItem;
+ for ( anIt = anItems.begin(); anIt != aLast; ++anIt ) {
+ aRow = (*anIt).row();
+ aCol = (*anIt).column();
+ if ( !canCopy( aRow, aCol ) )
+ continue;
+ aCopyItem.myRow = aRow-aTopRow;
+ aCopyItem.myCol = aCol-aLeftCol;
+ aCopyItem.myText = text( Cells, aRow, aCol );
+ aCopyItem.myBgCol = backgroundColor( Cells, aRow, aCol );
+ aCopyItem.myFgCol = foregroundColor( Cells, aRow, aCol );
+ aCopyItem.myFont = font( Cells, aRow, aCol );
+ myCopyLst.append( aCopyItem );
+ }
+}
+
+void TableViewer_ViewWindow::pasteData()
+{
+ QModelIndexList anItems = myTable->getSelectedIndexes();
+ if ( anItems.count() <= 0 || myCopyLst.count() <= 0 )
+ return;
+ int aLeftCol = myTable->columnCount(), aTopRow = myTable->rowCount();
+ QModelIndexList::const_iterator anIt = anItems.begin(), aLast = anItems.end();
+ QTableWidgetItem* anItem;
+ int aCol, aRow;
+ for ( ; anIt != aLast; ++anIt ) {
+ aRow = (*anIt).row();
+ aCol = (*anIt).column();
+ if ( !canPaste( aRow, aCol, "" ) )
+ continue;
+ if ( aCol < aLeftCol )
+ aLeftCol = aCol;
+ if ( aRow < aTopRow )
+ aTopRow = aRow;
+ }
+ QList<TableDataItem>::const_iterator aCopyIt = myCopyLst.begin(),
+ aCopyLast = myCopyLst.end();
+ //int aCol, aRow;
+ TableDataItem aCopyItem;
+ for ( ; aCopyIt != aCopyLast; aCopyIt++ ) {
+ aCopyItem = *aCopyIt;
+ aCol = aCopyItem.myCol+aLeftCol;
+ aRow = aCopyItem.myRow+aTopRow;
+ if ( !canPaste( aRow, aCol, aCopyItem.myText ) )
+ continue;
+ anItem = myTable->getItem( aRow, aCol, true );
+ anItem->setText( aCopyItem.myText );
+ if ( aCopyItem.myBgCol.isValid() )
+ anItem->setBackground( aCopyItem.myBgCol );
+ if ( aCopyItem.myFgCol.isValid() )
+ anItem->setForeground( aCopyItem.myFgCol );
+ anItem->setFont( aCopyItem.myFont );
+ }
+}
+
void TableViewer_ViewWindow::exportTableData( Handle(HTMLService_HTMLTable)& table,
const ContentType type,
const int rowOffset, const int colOffset )
}
}
}
+
+bool TableViewer_ViewWindow::canCopy( const int theRow, const int theCol )
+{
+ return true;
+}
+
+bool TableViewer_ViewWindow::canPaste( const int theRow, const int theCol, const QString& )
+{
+ return theRow < myTable->rowCount() && theRow >= 0 &&
+ theCol < myTable->columnCount() & theCol >= 0;
+}
class SUIT_Desktop;
class Handle(HTMLService_HTMLTable);
class QImage;
+class QFont;
class QtxTable;
class QToolBar;
+class QTableWidgetItem;
+class QItemSelection;
class TABLEVIEWER_EXPORT TableViewer_ViewWindow: public SUIT_ViewWindow
{
protected:
typedef enum { VerticalHeader, HorizontalHeader, Cells } ContentType;
- typedef enum { DumpId, CopyId, PrintId, ExportId, Custom } ActionId;
+ typedef enum { DumpId, CopyId, PasteId, PrintId, ExportId, Custom } ActionId;
typedef QMap<int, QtxAction*> ActionsMap;
virtual void createActions();
virtual void actionActivated( const int );
virtual void exportTableData( Handle(HTMLService_HTMLTable)&,
const ContentType, const int, const int );
+ virtual bool canCopy( const int, const int );
+ virtual bool canPaste( const int, const int, const QString& );
void registerAction( const int, QtxAction* );
QtxAction* createAction( const int, const QString&, const QPixmap&, const QString&,
QString text( const ContentType, const int, const int ) const;
QString image( const ContentType, const int, const int ) const;
+ QFont font( const ContentType, const int, const int ) const;
int fontFlags( const ContentType, const int, const int ) const;
QColor foregroundColor( const ContentType, const int, const int ) const;
QColor backgroundColor( const ContentType, const int, const int ) const;
+protected slots:
+ virtual void selectionChanged();
+
private slots:
void onActivated();
private:
void exportData();
+ void copyData();
+ void pasteData();
+ typedef struct {
+ QString myText;
+ QColor myBgCol;
+ QColor myFgCol;
+ QFont myFont;
+ int myRow;
+ int myCol;
+ } TableDataItem;
protected:
TableViewer_Viewer* myModel;
private:
QtxTable* myTable;
QToolBar* myToolBar;
+ QList<TableDataItem> myCopyLst;
};
#endif // !defined(TABLEVIEWER_VIEWWINDOW_H)