GUI: updated QHexEdit
This commit is contained in:
		
							parent
							
								
									6e662f484d
								
							
						
					
					
						commit
						766f2fa097
					
				|  | @ -36,6 +36,35 @@ void QHexEdit::replace( int pos, int len, const QByteArray & after, const QByteA | |||
|     qHexEdit_p->replace(pos, len, after, mask); | ||||
| } | ||||
| 
 | ||||
| void QHexEdit::fill(int index, const QString & pattern) | ||||
| { | ||||
|     QString convert; | ||||
|     for(int i=0; i<pattern.length(); i++) | ||||
|     { | ||||
|         QChar ch = pattern[i].toLower(); | ||||
|         if((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (wildcardEnabled() && ch == '?')) | ||||
|             convert += ch; | ||||
|     } | ||||
|     if(convert.length()%2) //odd length
 | ||||
|         convert += "0"; | ||||
|     QByteArray data(convert.length(), 0); | ||||
|     QByteArray mask(data.length(), 0); | ||||
|     for(int i=0; i<convert.length(); i++) | ||||
|     { | ||||
|         if(convert[i] == '?') | ||||
|         { | ||||
|             data[i]='0'; | ||||
|             mask[i]='1'; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             data[i]=convert[i].toAscii(); | ||||
|             mask[i]='0'; | ||||
|         } | ||||
|     } | ||||
|     qHexEdit_p->fill(index, QByteArray().fromHex(data), QByteArray().fromHex(mask)); | ||||
| } | ||||
| 
 | ||||
| void QHexEdit::redo() | ||||
| { | ||||
|     qHexEdit_p->redo(); | ||||
|  |  | |||
|  | @ -21,7 +21,8 @@ public: | |||
|     void insert(int i, const QByteArray & ba, const QByteArray & mask); | ||||
|     void insert(int i, char ch, char mask); | ||||
|     void remove(int pos, int len=1); | ||||
|     void replace( int pos, int len, const QByteArray & after, const QByteArray & mask); | ||||
|     void replace(int pos, int len, const QByteArray & after, const QByteArray & mask); | ||||
|     void fill(int index, const QString & pattern); | ||||
| 
 | ||||
|     //properties
 | ||||
|     void setCursorPosition(int cusorPos); | ||||
|  |  | |||
|  | @ -149,6 +149,25 @@ void QHexEditPrivate::replace(int pos, int len, const QByteArray &after, const Q | |||
|     emit dataChanged(); | ||||
| } | ||||
| 
 | ||||
| void QHexEditPrivate::fill(int index, const QByteArray & ba, const QByteArray & mask) | ||||
| { | ||||
|     int dataSize = _xData.size(); | ||||
|     if(index >= dataSize) | ||||
|         return; | ||||
|     int repeat = dataSize / ba.size() + 1; | ||||
|     QByteArray fillData = ba.repeated(repeat); | ||||
|     fillData.resize(dataSize); | ||||
|     fillData = fillData.toHex(); | ||||
|     QByteArray fillMask = mask.repeated(repeat); | ||||
|     fillMask.resize(dataSize); | ||||
|     fillMask = fillMask.toHex(); | ||||
|     QByteArray origData = _xData.data().mid(index).toHex(); | ||||
|     for(int i=0; i<dataSize*2; i++) | ||||
|         if(fillMask[i]=='1') | ||||
|             fillData[i]=origData[i]; | ||||
|     this->replace(index, QByteArray().fromHex(fillData), QByteArray().fromHex(fillMask)); | ||||
| } | ||||
| 
 | ||||
| void QHexEditPrivate::setOverwriteMode(bool overwriteMode) | ||||
| { | ||||
|     _overwriteMode = overwriteMode; | ||||
|  | @ -183,6 +202,7 @@ void QHexEditPrivate::setHorizontalSpacing(int x) | |||
| { | ||||
|     _horizonalSpacing = x; | ||||
|     adjust(); | ||||
|     setCursorPos(cursorPos()); | ||||
|     this->repaint(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -40,6 +40,7 @@ public: | |||
|     void replace(int index, char ch, char mask); | ||||
|     void replace(int index, const QByteArray & ba, const QByteArray & mask); | ||||
|     void replace(int pos, int len, const QByteArray & after, const QByteArray & mask); | ||||
|     void fill(int index, const QByteArray & ba, const QByteArray & mask); | ||||
|     void undo(); | ||||
|     void redo(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,7 +2,6 @@ | |||
| 
 | ||||
| XByteArray::XByteArray() | ||||
| { | ||||
|     _oldSize = -99; | ||||
| } | ||||
| 
 | ||||
| QByteArray & XByteArray::data() | ||||
|  |  | |||
|  | @ -27,9 +27,6 @@ public slots: | |||
| 
 | ||||
| private: | ||||
|     QByteArray _data; //raw byte array
 | ||||
|     QByteArray _mask; //masked byte array
 | ||||
| 
 | ||||
|     int _oldSize;                           // size of data
 | ||||
| }; | ||||
| 
 | ||||
| #endif // XBYTEARRAY_H
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue